@Override protected Authentication checkToken(String token) { UserAttribute attribute = new UserAttribute(); attribute.setName(attributeName); attribute.setValue(token); // looks for user(s) having the specified attribute with the given // token value Collection<User> users = userService.getByAttribute(attribute); // the token is considered valid if only 1 user matches if(users.size() == 1) { User user = users.iterator().next(); return createAuthenticationForUser(user); } else if(users.size() > 1) { LOGGER.error("Too many users matching the given token. Only one is allowed for a token to be valid!"); } else { LOGGER.error("No users matching the given token."); } return null; }
@Override /** * If details is a UserDetailsWithAttributes object, its attributes are mapped to User * attributes. * Each mapping is an SpEL expression using the UserDetailsWithAttributes as a source. * */ public void mapUser(Object details, User user) { List<UserAttribute> attributes = new ArrayList<UserAttribute>(); details = preProcessDetails(details); for(String attributeName : attributeMappings.keySet()) { Expression exp = parser.parseExpression(attributeMappings.get(attributeName)); UserAttribute userAttribute = new UserAttribute(); userAttribute.setName(attributeName); Object value = exp.getValue(evaluationContext, details); userAttribute.setValue(value == null ? null : value.toString()); attributes.add(userAttribute); } user.setAttribute(attributes); }
a.setName(aDto.getName()); attributes.add(a);