List of usage examples for org.apache.commons.lang StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(String str, String prefix)
Case insensitive check if a String starts with a specified prefix.
From source file:org.bigmouth.nvwa.network.http.Response.java
public String getCookie(String key) { for (Header header : headers) { if (StringUtils.equals("Set-Cookie", header.getName())) { String value = header.getValue(); if (StringUtils.isNotBlank(value) && StringUtils.startsWithIgnoreCase(value, key)) { // Because of the need to remove the effective range: path=/ String[] values = StringUtils.split(value, ";"); String[] jsessionid = values[0].split("="); return (jsessionid.length >= 2) ? jsessionid[1] : null; }/* w w w . j a va 2 s .c om*/ } } return null; }
From source file:org.carewebframework.security.spring.controller.LoginPaneController.java
/** * Sets the message text to the specified value. If the text starts with an html tag, it will be * rendered as such./*from ww w. java2 s .c o m*/ * * @param value The message text. * @param plainText Component to display plain text. * @param htmlText Component to display html. * @param parent If not null, parent will be hidden if text is empty. */ private void setMessageText(String value, Label plainText, Html htmlText, Component parent) { value = StringUtils.trimToEmpty(value); boolean isHtml = StringUtils.startsWithIgnoreCase(value, "<html>"); boolean notEmpty = !value.isEmpty(); plainText.setVisible(notEmpty && !isHtml); htmlText.setVisible(notEmpty && isHtml); if (parent != null) { parent.setVisible(notEmpty); } if (isHtml) { htmlText.setContent(value); } else { plainText.setValue(value); } }
From source file:org.carewebframework.vista.ui.notification.NotificationService.java
/** * Creates a list of recipients from a list of raw data. * //from www .ja v a 2 s . c o m * @param recipientData List of raw data as returned by lookup. * @param isGroup If true, the list represents mail groups. If false, it represents users. * @param filter The text used in the lookup. It will be used to limit the returned results. * @param result List of recipients. */ private void toRecipients(List<String> recipientData, boolean isGroup, String filter, Collection<Recipient> result) { result.clear(); for (String data : recipientData) { Recipient recipient = new Recipient(data, isGroup); if (StringUtils.startsWithIgnoreCase(recipient.getName(), filter)) { result.add(recipient); } else { break; } } }
From source file:org.codice.ddf.cxf.client.impl.SecureCxfClientFactoryImpl.java
/** * Constructs a factory that will return security-aware cxf clients. Once constructed, use the * getClient* methods to retrieve a fresh client with the same configuration. Providing {@link * WebClient} to interfaceClass will create a generic web client. * * <p>This factory can and should be cached. The clients it constructs should not be. * * @param endpointUrl the remote url to connect to * @param interfaceClass an interface representing the resource at the remote url * @param providers optional list of providers to further configure the client * @param interceptor optional message interceptor for the client * @param disableCnCheck disable ssl check for common name / host name match * @param allowRedirects allow this client to follow redirects *///from w w w. j a v a 2 s . c om public SecureCxfClientFactoryImpl(String endpointUrl, Class<T> interfaceClass, List<?> providers, Interceptor<? extends Message> interceptor, boolean disableCnCheck, boolean allowRedirects, PropertyResolver propertyResolver) { if (StringUtils.isEmpty(endpointUrl) || interfaceClass == null) { throw new IllegalArgumentException("Called without a valid URL, will not be able to connect."); } if (propertyResolver != null) { endpointUrl = propertyResolver.getResolvedString(); } else { LOGGER.warn("Called without a valid propertyResolver, system properties in URI may not resolve."); } this.interfaceClass = interfaceClass; this.disableCnCheck = disableCnCheck; this.allowRedirects = allowRedirects; JAXRSClientFactoryBean jaxrsClientFactoryBean = new JAXRSClientFactoryBean(); jaxrsClientFactoryBean.setServiceClass(interfaceClass); jaxrsClientFactoryBean.setAddress(endpointUrl); jaxrsClientFactoryBean.setClassLoader(interfaceClass.getClassLoader()); jaxrsClientFactoryBean.getInInterceptors().add(new LoggingInInterceptor()); jaxrsClientFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor()); if (!basicAuth && StringUtils.startsWithIgnoreCase(endpointUrl, HTTPS)) { jaxrsClientFactoryBean.getInInterceptors().add(new PaosInInterceptor(Phase.RECEIVE)); jaxrsClientFactoryBean.getOutInterceptors().add(new PaosOutInterceptor(Phase.POST_LOGICAL)); } if (CollectionUtils.isNotEmpty(providers)) { jaxrsClientFactoryBean.setProviders(providers); } if (interceptor != null) { jaxrsClientFactoryBean.getInInterceptors().add(interceptor); } this.clientFactory = jaxrsClientFactoryBean; }
From source file:org.codice.ddf.cxf.client.impl.SecureCxfClientFactoryImpl.java
/** * Clients produced by this method will be secured with two-way ssl and the provided security * subject./*from w ww .ja v a 2s . com*/ * * <p>The returned client should NOT be reused between requests! This method should be called for * each new request in order to ensure that the security token is up-to-date each time. */ public final T getClientForSubject(Subject subject) { final java.lang.SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkPermission(CREATE_CLIENT_PERMISSION); } return AccessController.doPrivileged((PrivilegedAction<T>) () -> { String asciiString = clientFactory.getAddress(); T newClient = getNewClient(); if (!basicAuth && StringUtils.startsWithIgnoreCase(asciiString, HTTPS)) { if (subject instanceof ddf.security.Subject) { RestSecurity.setSubjectOnClient((ddf.security.Subject) subject, WebClient.client(newClient)); } } auditRemoteConnection(asciiString); return newClient; }); }
From source file:org.codice.ddf.cxf.paos.PaosInInterceptor.java
private String createToken(String authorization) throws IOException { String token = null;//from w w w.j a v a 2 s.c om if (authorization != null) { if (StringUtils.startsWithIgnoreCase(authorization, BASIC)) { byte[] decode = Base64.getDecoder().decode(authorization.split("\\s")[1]); if (decode != null) { String userPass = new String(decode, StandardCharsets.UTF_8); String[] authComponents = userPass.split(":"); if (authComponents.length == 2) { token = getUsernameToken(authComponents[0], authComponents[1]); } else if ((authComponents.length == 1) && (userPass.endsWith(":"))) { token = getUsernameToken(authComponents[0], ""); } } } else if (StringUtils.startsWithIgnoreCase(authorization, SAML)) { token = RestSecurity.inflateBase64(authorization.split("\\s")[1]); } } return token; }
From source file:org.codice.ddf.cxf.SecureCxfClientFactory.java
/** * Clients produced by this method will be secured with two-way ssl * and the provided security subject.//from www . j av a2 s . c o m * <p> * The returned client should NOT be reused between requests! * This method should be called for each new request in order to ensure * that the security token is up-to-date each time. */ public T getClientForSubject(Subject subject) { String asciiString = clientFactory.getAddress(); T newClient = getNewClient(); if (!basicAuth && StringUtils.startsWithIgnoreCase(asciiString, "https")) { if (subject instanceof ddf.security.Subject) { RestSecurity.setSubjectOnClient((ddf.security.Subject) subject, WebClient.client(newClient)); } } return newClient; }
From source file:org.codice.ddf.security.common.jaxrs.RestSecurity.java
public static void setUserOnClient(String username, String password, Client client) throws UnsupportedEncodingException { if (client != null && username != null && password != null) { if (!StringUtils.startsWithIgnoreCase(client.getCurrentURI().getScheme(), "https")) { if (Boolean.valueOf(System.getProperty("org.codice.allowBasicAuthOverHttp", "false"))) { LOGGER.warn("CAUTION: Passing username & password on an un-encrypted protocol [{}]." + " This is a security issue. ", client.getCurrentURI()); SecurityLogger.auditWarn("Passing username & password on an un-encrypted protocol [" + client.getCurrentURI() + "]."); } else { LOGGER.warn("Passing username & password is not allowed on an un-encrypted protocol [{}].", client.getCurrentURI()); return; }// ww w . ja v a2s . com } String basicCredentials = username + ":" + password; String encodedHeader = BASIC_HEADER_PREFIX + Base64.getEncoder().encodeToString(basicCredentials.getBytes(StandardCharsets.UTF_8)); client.header(AUTH_HEADER, encodedHeader); } }
From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.WfsFilterDelegate.java
private void configureSorting(DomainType constraint) { if (constraint.getNoValues() != null && constraint.getDefaultValue() != null) { if (StringUtils.equalsIgnoreCase(constraint.getDefaultValue().getValue(), Boolean.TRUE.toString())) { this.isSortingSupported = true; } else if (StringUtils.equalsIgnoreCase(constraint.getDefaultValue().getValue(), Boolean.FALSE.toString())) { this.isSortingSupported = false; }/*from w w w.ja v a2 s. c om*/ } if (constraint.getAllowedValues() != null) { this.isSortingSupported = true; AllowedValues allowedValues = constraint.getAllowedValues(); List<Object> values = allowedValues.getValueOrRange(); for (Object value : values) { if (value instanceof ValueType) { String sortOrder = ((ValueType) value).getValue(); // Could be ASC, ASCENDING, etc. if (StringUtils.startsWithIgnoreCase(sortOrder, "A")) { allowedSortOrders.add(SortOrder.ASCENDING); } else if (StringUtils.startsWithIgnoreCase(sortOrder, "D")) { allowedSortOrders.add(SortOrder.DESCENDING); } } } } }
From source file:org.codice.solr.factory.impl.HttpClientBuilder.java
private boolean useTls() { return StringUtils.startsWithIgnoreCase( AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(SOLR_HTTP_URL)), "https"); }