X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=security%2Fruntime%2Forg.argeo.security.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fldap%2FArgeoSecurityDaoLdap.java;h=763539ce25afb8d0b39d98bb94fb40a59756ec03;hb=e80be147bdb65aa2a0c34e848ca78851b781508d;hp=83e090661533ea71e00f01d36606663ce488cf17;hpb=12f0ab4fa622e3507570f5dcbe586c05131a0050;p=lgpl%2Fargeo-commons.git diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoSecurityDaoLdap.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoSecurityDaoLdap.java index 83e090661..763539ce2 100644 --- a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoSecurityDaoLdap.java +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/ArgeoSecurityDaoLdap.java @@ -19,6 +19,8 @@ import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; +import org.springframework.security.Authentication; +import org.springframework.security.context.SecurityContextHolder; import org.springframework.security.ldap.DefaultLdapUsernameToDnMapper; import org.springframework.security.ldap.LdapAuthoritiesPopulator; import org.springframework.security.ldap.LdapUsernameToDnMapper; @@ -92,6 +94,15 @@ public class ArgeoSecurityDaoLdap implements ArgeoSecurityDao, InitializingBean return createBasicArgeoUser(getDetails(uname)); } + public ArgeoUser getCurrentUser() { + Authentication authentication = SecurityContextHolder.getContext() + .getAuthentication(); + ArgeoUser argeoUser = ArgeoUserDetails.asArgeoUser(authentication); + if (argeoUser.getRoles().contains(defaultRole)) + argeoUser.getRoles().remove(defaultRole); + return argeoUser; + } + @SuppressWarnings("unchecked") public List listUsers() { List usernames = (List) ldapTemplate.listBindings( @@ -247,4 +258,8 @@ public class ArgeoSecurityDaoLdap implements ArgeoSecurityDao, InitializingBean public void setUserNatureMappers(List userNatureMappers) { this.userNatureMappers = userNatureMappers; } + + public String getDefaultRole() { + return defaultRole; + } }