List of usage examples for org.springframework.util Assert isInstanceOf
public static void isInstanceOf(Class<?> type, @Nullable Object obj, Supplier<String> messageSupplier)
From source file:org.acegisecurity.providers.ProviderManager.java
/** * Sets the {@link AuthenticationProvider} objects to be used for authentication. * * @param newList/*from ww w . java 2s .c o m*/ * * @throws IllegalArgumentException DOCUMENT ME! */ public void setProviders(List newList) { checkIfValidList(newList); Iterator iter = newList.iterator(); while (iter.hasNext()) { Object currentObject = iter.next(); Assert.isInstanceOf(AuthenticationProvider.class, currentObject, "Can only provide AuthenticationProvider instances"); } this.providers = newList; }
From source file:org.apache.ranger.service.PasswordComparisonAuthenticator.java
public DirContextOperations authenticate(final Authentication authentication) { Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, "Can only process UsernamePasswordAuthenticationToken objects"); // locate the user and check the password DirContextOperations user = null;// ww w. j av a 2s. co m String username = authentication.getName(); String password = (String) authentication.getCredentials(); Iterator dns = getUserDns(username).iterator(); SpringSecurityLdapTemplate ldapTemplate = new SpringSecurityLdapTemplate(getContextSource()); while (dns.hasNext() && user == null) { final String userDn = (String) dns.next(); try { user = ldapTemplate.retrieveEntry(userDn, getUserAttributes()); } catch (NameNotFoundException ignore) { } } if (user == null && getUserSearch() != null) { user = getUserSearch().searchForUser(username); } if (user == null) { throw new UsernameNotFoundException("User not found: " + username, username); } if (logger.isDebugEnabled()) { logger.debug("Performing LDAP compare of password attribute '" + passwordAttributeName + "' for user '" + user.getDn() + "'"); } String encodedPassword = passwordEncoder.encodePassword(password, null); byte[] passwordBytes = encodedPassword.getBytes(); if (!ldapTemplate.compare(user.getDn().toString(), passwordAttributeName, passwordBytes)) { throw new BadCredentialsException( messages.getMessage("PasswordComparisonAuthenticator.badCredentials", "Bad credentials")); } return user; }
From source file:org.apache.roller.weblogger.ui.core.security.CrowdAuthenticationProvider.java
public Authentication authenticate(Authentication authentication) throws AuthenticationException { Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, messages.getMessage("AbstractUserDetailsAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported")); UsernamePasswordAuthenticationToken authenticationToken = null; if (crowdClient != null) { UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication; String password = (String) authentication.getCredentials(); String username = userToken.getName(); Assert.notNull(password, "Null password was supplied in authentication token"); if (!StringUtils.hasLength(username)) { throw new BadCredentialsException( messages.getMessage("CrowdAuthenticationProvider.emptyUsername", "Empty Username")); }//from w w w. j a v a 2 s . co m if (password.length() == 0) { LOG.debug("Rejecting empty password for user " + username); throw new BadCredentialsException( messages.getMessage("CrowdAuthenticationProvider.emptyPassword", "Empty Password")); } try { User user = crowdClient.authenticateUser(authentication.getName(), authentication.getCredentials().toString()); GrantedAuthority[] grantedAuthorities = getGrantedAuthorities(user); // this is the required constructor, since we don't know any of the boolean values // and we can assume if the employee is active and we have gotten this far, these values // can be set to the isActive() field on the crowd User object. // NOTE: null values for timeZone and locale are okay, they are dealt with at another level. CrowdRollerUserDetails crowdRollerUserDetails = new CrowdRollerUserDetails(user, authentication.getCredentials().toString(), crowdTimezone, crowdLocale, grantedAuthorities); authenticationToken = new UsernamePasswordAuthenticationToken(crowdRollerUserDetails, authentication.getCredentials(), grantedAuthorities); } catch (UserNotFoundException e) { throw new UsernameNotFoundException(e.getMessage(), e); } catch (InactiveAccountException e) { throw new DisabledException(e.getMessage(), e); } catch (ExpiredCredentialException e) { throw new CredentialsExpiredException(e.getMessage(), e); } catch (InvalidAuthenticationException e) { throw new BadCredentialsException(e.getMessage(), e); } catch (ApplicationPermissionException e) { throw new AuthenticationServiceException(e.getMessage(), e); } catch (OperationFailedException e) { throw new AuthenticationServiceException(e.getMessage(), e); } } return authenticationToken; }
From source file:org.apereo.portal.utils.AbstractBeanLocator.java
public AbstractBeanLocator(T instance, Class<T> type) { Assert.notNull(instance, "instance must not be null"); Assert.notNull(type, "type must not be null"); Assert.isInstanceOf(type, instance, instance + " must implement " + type); this.instance = instance; }
From source file:org.cloudifysource.security.CloudifyDaoAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, messages.getMessage("AbstractUserDetailsAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported")); logger.finest("CloudifyDaoAuthenticationProvider: authenticate"); final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication; final CloudifyUserDetails user; // Determine username final String username = userToken.getName(); final String password = (String) authentication.getCredentials(); if (StringUtils.isBlank(username)) { throw new IllegalArgumentException("Empty username not allowed"); }//from w w w . j a v a2 s . co m Assert.notNull(password, "Null password was supplied in authentication token"); logger.fine("Processing authentication request for user: " + username); // Get the Cloudify user details from the user details service try { user = retrieveUser(username); String retrievedUserPassword = user.getPassword(); if (!password.equals(retrievedUserPassword)) { logger.warning("Authentication failed: password does not match stored value"); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); } } catch (final UsernameNotFoundException e) { logger.warning("User '" + username + "' not found"); throw e; } // authenticate runAuthenticationChecks(user); // create a successful and full authentication token return createSuccessfulAuthentication(userToken, user); }
From source file:org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.java
/** * Creates the ApplicationContext instance. Subclasses can override to customise the used ApplicationContext * * @param parentCtx The parent ApplicationContext instance. Can be null. * * @return An instance of GenericApplicationContext *///w w w .j a v a2 s .c om protected GenericApplicationContext createApplicationContext(ApplicationContext parentCtx) { if (parentCtx != null && beanFactory != null) { Assert.isInstanceOf(DefaultListableBeanFactory.class, beanFactory, "ListableBeanFactory set must be a subclass of DefaultListableBeanFactory"); return new GrailsApplicationContext((DefaultListableBeanFactory) beanFactory, parentCtx); } if (beanFactory != null) { Assert.isInstanceOf(DefaultListableBeanFactory.class, beanFactory, "ListableBeanFactory set must be a subclass of DefaultListableBeanFactory"); return new GrailsApplicationContext((DefaultListableBeanFactory) beanFactory); } if (parentCtx != null) { return new GrailsApplicationContext(parentCtx); } return new GrailsApplicationContext(); }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.search.SearchableCompassQueryBuilderSortOptionHelper.java
public CompassQuery addSort(CompassQuery compassQuery, Map options) { Object sort = options.get("sort"); if (sort == null) { return compassQuery; }//from w w w.ja va 2 s .c o m Assert.isTrue(sort instanceof String || sort instanceof List, "sort option should be given as string or list"); List<String> sorts = null; List<String> orders = null; if (sort instanceof String) { sorts = Arrays.asList(StringUtils.split((String) sort, ',')); } else { sorts = (List) sort; } if (!options.containsKey(ORDER) && !options.containsKey(DIRECTION)) { orders = new ArrayList<String>(); } else { Assert.isTrue( (options.containsKey(ORDER) && !options.containsKey(DIRECTION)) || (!options.containsKey(ORDER) && options.containsKey(DIRECTION)), "Either specify a sort '" + ORDER + "' or '" + DIRECTION + "' or neither but not both"); Object order = options.get(DIRECTION); if (order == null) { order = options.get(ORDER); } Assert.isTrue(order instanceof String || order instanceof List, "order/direction option should be given as string or list"); if (order instanceof String) { orders = Arrays.asList(StringUtils.split((String) order, ',')); } else { orders = (List) order; } } if (orders.size() < sorts.size()) { while (orders.size() != sorts.size()) { orders.add("auto"); } } for (int i = 0; i < sorts.size(); i++) { String s = sorts.get(i); String o = orders.get(i); Object sortProperty = getSortProperty(s); CompassQuery.SortDirection direction = getSortDirection(sortProperty, o); if (sortProperty instanceof CompassQuery.SortImplicitType) { compassQuery = compassQuery.addSort((CompassQuery.SortImplicitType) sortProperty, direction); } else { Assert.isInstanceOf(String.class, sortProperty, "Expected string"); CompassQuery.SortPropertyType sortType = getSortType((String) options.get("sortType")); compassQuery = compassQuery.addSort((String) sortProperty, sortType, direction); } } return compassQuery; }
From source file:org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingEvaluator.java
public void setClassLoader(ClassLoader classLoader) { Assert.isInstanceOf(GroovyClassLoader.class, classLoader, "Property [classLoader] must be an instance of GroovyClassLoader"); this.classLoader = (GroovyClassLoader) classLoader; }
From source file:org.codehaus.groovy.grails.web.taglib.GroovySyntaxTag.java
public void setWriter(Writer w) { Assert.isInstanceOf(PrintWriter.class, w, "A GroovySynax tag requires a java.io.PrintWriter instance"); out = (PrintWriter) w;/*w w w . j a v a2s . c om*/ }
From source file:org.codehaus.groovy.grails.web.taglib.GroovySyntaxTag.java
public void setAttribute(String name, Object value) { Assert.isInstanceOf(String.class, value, "A GroovySyntax tag requires only string valued attributes"); attributes.put(name.substring(1, name.length() - 1), (String) value); }