1 package compbio.spring.security;
3 import java.util.Collection;
4 import java.util.HashSet;
7 import javax.annotation.Resource;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.springframework.security.core.GrantedAuthority;
12 import org.springframework.security.core.authority.SimpleGrantedAuthority;
13 import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
16 * The class maps LDAP groups defined in the LDAP service to the ProteoCache
17 * roles for a specific user. The class implements the standard Spring Security
18 * GrantedAuthoritiesMapper interface and should replace the standard
19 * Authorities Mapper in security configuration XML file.
21 * @version 1.0 January 2014
23 * @author Alexaner Sherstnev
27 public class LDAPAuthorityMapper implements GrantedAuthoritiesMapper {
29 private static final Log logger = LogFactory.getLog(LDAPAuthorityMapper.class);
31 public LDAPAuthorityMapper() {
35 * the real mapping method. Currently, all users who are able to
36 * authenticate are assigned with the same ROLE_LDAP_USER.
38 * @param authorities a set of original granted authorities assigned by ldapAuthProvider
39 * @return a new set of granted authorities greated in the method
41 public Collection<? extends GrantedAuthority> mapAuthorities(final Collection<? extends GrantedAuthority> authorities) {
42 SimpleGrantedAuthority sa = new SimpleGrantedAuthority("ROLE_LDAP_USER");
43 Set<GrantedAuthority> roles = new HashSet<GrantedAuthority>();
45 logger.info("LDAPAuthorityMapper: set new role ROLE_LDAP_USER");