Add mode comments to the classes
[proteocache.git] / server / compbio / spring / security / LDAPAuthorityMapper.java
1 package compbio.spring.security;
2
3 import java.util.Collection;
4 import java.util.HashSet;
5 import java.util.Set;
6
7 import javax.annotation.Resource;
8
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;
14
15 /**
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.
20  * 
21  * @version 1.0 January 2014
22  * 
23  * @author Alexaner Sherstnev
24  * 
25  */
26 @Resource
27 public class LDAPAuthorityMapper implements GrantedAuthoritiesMapper {
28
29         private static final Log logger = LogFactory.getLog(LDAPAuthorityMapper.class);
30
31         public LDAPAuthorityMapper() {
32         }
33
34         /**
35          * the real mapping method. Currently, all users who are able to
36          * authenticate are assigned with the same ROLE_LDAP_USER.
37          * 
38          * @param authorities a set of original granted authorities assigned by ldapAuthProvider
39          * @return a new set of granted authorities greated in the method
40          */
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>();
44                 roles.add(sa);
45                 logger.info("LDAPAuthorityMapper: set new role ROLE_LDAP_USER");
46                 return roles;
47         }
48 }