]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoUserDetailsContextMapper.java
Improve Security
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / ldap / ArgeoUserDetailsContextMapper.java
index 55232648066d2368e67d39d9e799d72140367edb..459d5e5fc834989b43081c3271c5db673ae5f5c0 100644 (file)
@@ -1,8 +1,26 @@
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.argeo.security.ldap;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.argeo.security.ArgeoUser;
 import org.argeo.security.UserNature;
@@ -13,9 +31,13 @@ import org.springframework.security.GrantedAuthority;
 import org.springframework.security.userdetails.UserDetails;
 import org.springframework.security.userdetails.ldap.UserDetailsContextMapper;
 
+/**
+ * Performs the mapping between LDAP and the user natures, using
+ * {@link UserNatureMapper}.
+ */
 public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper {
-//     private final static Log log = LogFactory
-//                     .getLog(ArgeoUserDetailsContextMapper.class);
+       // private final static Log log = LogFactory
+       // .getLog(ArgeoUserDetailsContextMapper.class);
 
        private List<UserNatureMapper> userNatureMappers = new ArrayList<UserNatureMapper>();
 
@@ -25,15 +47,15 @@ public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper {
                                .first();
                String password = new String(arr);
 
-               List<UserNature> userNatures = new ArrayList<UserNature>();
+               Map<String, UserNature> userNatures = new HashMap<String, UserNature>();
                for (UserNatureMapper userInfoMapper : userNatureMappers) {
                        UserNature userNature = userInfoMapper.mapUserInfoFromContext(ctx);
                        if (userNature != null)
-                               userNatures.add(userNature);
+                               userNatures.put(userInfoMapper.getName(), userNature);
                }
 
-               return new ArgeoUserDetails(username, Collections
-                               .unmodifiableList(userNatures), password, authorities);
+               return new ArgeoUserDetails(username,
+                               Collections.unmodifiableMap(userNatures), password, authorities);
        }
 
        public void mapUserToContext(UserDetails user, DirContextAdapter ctx) {
@@ -42,7 +64,7 @@ public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper {
                ctx.setAttributeValue("userPassword", user.getPassword());
                if (user instanceof ArgeoUser) {
                        ArgeoUser argeoUser = (ArgeoUser) user;
-                       for (UserNature userNature : argeoUser.getUserNatures()) {
+                       for (UserNature userNature : argeoUser.getUserNatures().values()) {
                                for (UserNatureMapper userInfoMapper : userNatureMappers) {
                                        if (userInfoMapper.supports(userNature)) {
                                                userInfoMapper.mapUserInfoToContext(userNature, ctx);