]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoUserDetailsContextMapper.java
Add license headers
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / ldap / ArgeoUserDetailsContextMapper.java
index 25b5c6eba57df15e36fc4138b9842deea0f7b95b..03af0f49bd7d5c5268a423746eb7123d98725ac5 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * 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;
@@ -14,7 +30,10 @@ import org.springframework.security.userdetails.UserDetails;
 import org.springframework.security.userdetails.ldap.UserDetailsContextMapper;
 
 public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper {
-       private List<UserNatureMapper> userInfoMappers = new ArrayList<UserNatureMapper>();
+//     private final static Log log = LogFactory
+//                     .getLog(ArgeoUserDetailsContextMapper.class);
+
+       private List<UserNatureMapper> userNatureMappers = new ArrayList<UserNatureMapper>();
 
        public UserDetails mapUserFromContext(DirContextOperations ctx,
                        String username, GrantedAuthority[] authorities) {
@@ -22,13 +41,15 @@ public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper {
                                .first();
                String password = new String(arr);
 
-               List<UserNature> userInfos = new ArrayList<UserNature>();
-               for (UserNatureMapper userInfoMapper : userInfoMappers) {
-                       userInfos.add(userInfoMapper.mapUserInfoFromContext(ctx));
+               List<UserNature> userNatures = new ArrayList<UserNature>();
+               for (UserNatureMapper userInfoMapper : userNatureMappers) {
+                       UserNature userNature = userInfoMapper.mapUserInfoFromContext(ctx);
+                       if (userNature != null)
+                               userNatures.add(userNature);
                }
 
                return new ArgeoUserDetails(username, Collections
-                               .unmodifiableList(userInfos), password, authorities);
+                               .unmodifiableList(userNatures), password, authorities);
        }
 
        public void mapUserToContext(UserDetails user, DirContextAdapter ctx) {
@@ -37,19 +58,19 @@ public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper {
                ctx.setAttributeValue("userPassword", user.getPassword());
                if (user instanceof ArgeoUser) {
                        ArgeoUser argeoUser = (ArgeoUser) user;
-                       for (UserNature userInfo : argeoUser.getUserNatures()) {
-                               for (UserNatureMapper userInfoMapper : userInfoMappers) {
-                                       if (userInfoMapper.supports(userInfo)) {
-                                               userInfoMapper.mapUserInfoToContext(userInfo, ctx);
-                                               break;// use the first mapper found an no others
+                       for (UserNature userNature : argeoUser.getUserNatures()) {
+                               for (UserNatureMapper userInfoMapper : userNatureMappers) {
+                                       if (userInfoMapper.supports(userNature)) {
+                                               userInfoMapper.mapUserInfoToContext(userNature, ctx);
+                                               break;// use the first mapper found and no others
                                        }
                                }
                        }
                }
        }
 
-       public void setUserInfoMappers(List<UserNatureMapper> userInfoMappers) {
-               this.userInfoMappers = userInfoMappers;
+       public void setUserNatureMappers(List<UserNatureMapper> userNatureMappers) {
+               this.userNatureMappers = userNatureMappers;
        }
 
 }