X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=security%2Fruntime%2Forg.argeo.security.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fldap%2FArgeoUserDetailsContextMapper.java;h=12c8a333251f8f84fe0d41af677abbbc325f740a;hb=79d37fb873ba8ebaafe64c924f53bc9c76ea6d8c;hp=25b5c6eba57df15e36fc4138b9842deea0f7b95b;hpb=7c9ba14fbe8cd771af9d205c7988507c1dd7abb6;p=lgpl%2Fargeo-commons.git diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoUserDetailsContextMapper.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoUserDetailsContextMapper.java index 25b5c6eba..12c8a3332 100644 --- a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoUserDetailsContextMapper.java +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoUserDetailsContextMapper.java @@ -1,8 +1,26 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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; @@ -14,7 +32,10 @@ import org.springframework.security.userdetails.UserDetails; import org.springframework.security.userdetails.ldap.UserDetailsContextMapper; public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper { - private List userInfoMappers = new ArrayList(); + // private final static Log log = LogFactory + // .getLog(ArgeoUserDetailsContextMapper.class); + + private List userNatureMappers = new ArrayList(); public UserDetails mapUserFromContext(DirContextOperations ctx, String username, GrantedAuthority[] authorities) { @@ -22,13 +43,15 @@ public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper { .first(); String password = new String(arr); - List userInfos = new ArrayList(); - for (UserNatureMapper userInfoMapper : userInfoMappers) { - userInfos.add(userInfoMapper.mapUserInfoFromContext(ctx)); + Map userNatures = new HashMap(); + for (UserNatureMapper userInfoMapper : userNatureMappers) { + UserNature userNature = userInfoMapper.mapUserInfoFromContext(ctx); + if (userNature != null) + userNatures.put(userInfoMapper.getName(), userNature); } - return new ArgeoUserDetails(username, Collections - .unmodifiableList(userInfos), password, authorities); + return new ArgeoUserDetails(username, + Collections.unmodifiableMap(userNatures), password, authorities); } public void mapUserToContext(UserDetails user, DirContextAdapter ctx) { @@ -37,19 +60,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().values()) { + 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 userInfoMappers) { - this.userInfoMappers = userInfoMappers; + public void setUserNatureMappers(List userNatureMappers) { + this.userNatureMappers = userNatureMappers; } }