+package compbio.spring.security;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
+import org.springframework.security.ldap.authentication.LdapAuthenticationProvider;
+
+/**
+ * Maps groups defined in LDAP to roles for a specific user.
+ */
+@Resource
+public class LDAPAuthorityMapper implements GrantedAuthoritiesMapper {
+
+ private static final Log logger = LogFactory.getLog(LDAPAuthorityMapper.class);
+
+ public LDAPAuthorityMapper() {
+ }
+/*
+ public Collection<? extends GrantedAuthority> mapAuthorities(final Collection<? extends GrantedAuthority> authorities) {
+
+ Set<PCacheLDAPAuthority> roles = EnumSet.noneOf(PCacheLDAPAuthority.class);
+ roles.add(PCacheLDAPAuthority.ROLE_LDAP_USER);
+ logger.info("LDAPAuthorityMapper: set new role ROLE_LDAP_USER");
+ *
+ * for (GrantedAuthority authority : authorities) { if
+ * (ROLE_CUSTOMER_SERVICE_OFFICER.equals(authority.getAuthority())) {
+ * roles.add(PCacheLDAPAuthority.ROLE_USER); } else if
+ * (ROLE_ADMIN.equals(authority.getAuthority())) {
+ * roles.add(PCacheLDAPAuthority.ROLE_ADMIN); } }
+ *
+ return roles;
+ }*/
+
+
+ public Collection<? extends GrantedAuthority> mapAuthorities(final Collection<? extends GrantedAuthority> authorities) {
+ SimpleGrantedAuthority sa = new SimpleGrantedAuthority("ROLE_LDAP_USER");
+ Set<GrantedAuthority> roles = new HashSet<GrantedAuthority>();
+ roles.add(sa);
+ logger.info("LDAPAuthorityMapper: set new role ROLE_LDAP_USER");
+
+ return roles;
+ }
+}