List of usage examples for org.springframework.util Assert hasLength
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier)
From source file:org.springframework.security.config.http.AuthenticationConfigBuilder.java
void createJeeFilter(BeanReference authManager) { final String ATT_MAPPABLE_ROLES = "mappable-roles"; Element jeeElt = DomUtils.getChildElementByTagName(httpElt, Elements.JEE); RootBeanDefinition filter = null;/* w ww .j a v a 2 s . c o m*/ if (jeeElt != null) { BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder .rootBeanDefinition(J2eePreAuthenticatedProcessingFilter.class); filterBuilder.getRawBeanDefinition().setSource(pc.extractSource(jeeElt)); filterBuilder.addPropertyValue("authenticationManager", authManager); BeanDefinitionBuilder adsBldr = BeanDefinitionBuilder .rootBeanDefinition(J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource.class); adsBldr.addPropertyValue("userRoles2GrantedAuthoritiesMapper", new RootBeanDefinition(SimpleAttributes2GrantedAuthoritiesMapper.class)); String roles = jeeElt.getAttribute(ATT_MAPPABLE_ROLES); Assert.hasLength(roles, "roles is expected to have length"); BeanDefinitionBuilder rolesBuilder = BeanDefinitionBuilder.rootBeanDefinition(StringUtils.class); rolesBuilder.addConstructorArgValue(roles); rolesBuilder.setFactoryMethod("commaDelimitedListToSet"); RootBeanDefinition mappableRolesRetriever = new RootBeanDefinition( SimpleMappableAttributesRetriever.class); mappableRolesRetriever.getPropertyValues().addPropertyValue("mappableAttributes", rolesBuilder.getBeanDefinition()); adsBldr.addPropertyValue("mappableRolesRetriever", mappableRolesRetriever); filterBuilder.addPropertyValue("authenticationDetailsSource", adsBldr.getBeanDefinition()); filter = (RootBeanDefinition) filterBuilder.getBeanDefinition(); createPrauthEntryPoint(jeeElt); createJeeProvider(); } jeeFilter = filter; }
From source file:org.springframework.security.ldap.DefaultSpringSecurityContextSource.java
/** * Create and initialize an instance which will connect to the supplied LDAP URL. If * you want to use more than one server for fail-over, rather use the * {@link #DefaultSpringSecurityContextSource(List, String)} constructor. * * @param providerUrl an LDAP URL of the form * <code>ldap://localhost:389/base_dn</code> *//*from w ww . j a va 2s. com*/ public DefaultSpringSecurityContextSource(String providerUrl) { Assert.hasLength(providerUrl, "An LDAP connection URL must be supplied."); StringTokenizer st = new StringTokenizer(providerUrl); ArrayList<String> urls = new ArrayList<>(); // Work out rootDn from the first URL and check that the other URLs (if any) match while (st.hasMoreTokens()) { String url = st.nextToken(); String urlRootDn = LdapUtils.parseRootDnFromUrl(url); urls.add(url.substring(0, url.lastIndexOf(urlRootDn))); this.logger.info(" URL '" + url + "', root DN is '" + urlRootDn + "'"); if (this.rootDn == null) { this.rootDn = urlRootDn; } else if (!this.rootDn.equals(urlRootDn)) { throw new IllegalArgumentException("Root DNs must be the same when using multiple URLs"); } } setUrls(urls.toArray(new String[urls.size()])); setBase(this.rootDn); setPooled(true); setAuthenticationStrategy(new SimpleDirContextAuthenticationStrategy() { @Override @SuppressWarnings("rawtypes") public void setupEnvironment(Hashtable env, String dn, String password) { super.setupEnvironment(env, dn, password); // Remove the pooling flag unless we are authenticating as the 'manager' // user. if (!DefaultSpringSecurityContextSource.this.userDn.equals(dn) && env.containsKey(SUN_LDAP_POOLING_FLAG)) { DefaultSpringSecurityContextSource.this.logger.debug("Removing pooling flag for user " + dn); env.remove(SUN_LDAP_POOLING_FLAG); } } }); }
From source file:org.springframework.security.ldap.LdapUtils.java
/** * Works out the root DN for an LDAP URL. * <p>//from w w w . j a v a 2 s .c om * For example, the URL <tt>ldap://monkeymachine:11389/dc=springframework,dc=org</tt> * has the root DN "dc=springframework,dc=org". * </p> * * @param url the LDAP URL * * @return the root DN */ public static String parseRootDnFromUrl(String url) { Assert.hasLength(url, "url must have length"); String urlRootDn; if (url.startsWith("ldap:") || url.startsWith("ldaps:")) { URI uri = parseLdapUrl(url); urlRootDn = uri.getRawPath(); } else { // Assume it's an embedded server urlRootDn = url; } if (urlRootDn.startsWith("/")) { urlRootDn = urlRootDn.substring(1); } return urlRootDn; }
From source file:org.springframework.security.ldap.LdapUtils.java
/** * Parses the supplied LDAP URL.//from w w w . j a v a 2 s . com * @param url the URL (e.g. * <tt>ldap://monkeymachine:11389/dc=springframework,dc=org</tt>). * @return the URI object created from the URL * @throws IllegalArgumentException if the URL is null, empty or the URI syntax is * invalid. */ private static URI parseLdapUrl(String url) { Assert.hasLength(url, "url must have length"); try { return new URI(url); } catch (URISyntaxException e) { IllegalArgumentException iae = new IllegalArgumentException("Unable to parse url: " + url); iae.initCause(e); throw iae; } }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer.java
@Override public void serialize(OAuth2AccessToken token, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject();/*from ww w . j av a 2 s . c o m*/ jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) { jgen.writeStringField(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue()); } Date expiration = token.getExpiration(); if (expiration != null) { long now = System.currentTimeMillis(); jgen.writeNumberField(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000); } Set<String> scope = token.getScope(); if (scope != null && !scope.isEmpty()) { StringBuffer scopes = new StringBuffer(); for (String s : scope) { Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope + ""); scopes.append(s); scopes.append(" "); } jgen.writeStringField(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1)); } Map<String, Object> additionalInformation = token.getAdditionalInformation(); for (String key : additionalInformation.keySet()) { jgen.writeObjectField(key, additionalInformation.get(key)); } jgen.writeEndObject(); }
From source file:org.springframework.security.ui.ntlm.NtlmAuthenticationFilterEntryPoint.java
/** * Sets the authentication failure URL./*from w w w.j av a2s . co m*/ * * @param authenticationFailureUrl the authentication failure URL. */ public void setAuthenticationFailureUrl(String authenticationFailureUrl) { Assert.hasLength(authenticationFailureUrl, "authenticationFailureUrl must be specified"); this.authenticationFailureUrl = authenticationFailureUrl; }
From source file:org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.java
protected AbstractRememberMeServices(String key, UserDetailsService userDetailsService) { Assert.hasLength(key, "key cannot be empty or null"); Assert.notNull(userDetailsService, "UserDetailsService cannot be null"); this.key = key; this.userDetailsService = userDetailsService; }
From source file:org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.java
@Override public void afterPropertiesSet() throws Exception { Assert.hasLength(key, "key cannot be empty or null"); Assert.notNull(userDetailsService, "A UserDetailsService is required"); }
From source file:org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.java
public void setCookieName(String cookieName) { Assert.hasLength(cookieName, "Cookie name cannot be empty or null"); this.cookieName = cookieName; }
From source file:org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.java
public void setCookieDomain(String cookieDomain) { Assert.hasLength(cookieDomain, "Cookie domain cannot be empty or null"); this.cookieDomain = cookieDomain; }