From 55684b7175eb02ae00808785ce40f53f303e8ec8 Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Thu, 23 Jun 2016 10:52:47 +0300 Subject: [PATCH] configuration for spring security - LDAP authentication --- build-system/pom.xml | 9 ++++- gui/admin-gui/pom.xml | 6 ++++ .../main/webapp/WEB-INF/ctx-web-security.xml | 35 ++++++++++++++++--- model/model-impl/pom.xml | 4 +++ .../impl/security/UserProfileServiceImpl.java | 23 ++++++++++-- repo/security-api/pom.xml | 1 + 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/build-system/pom.xml b/build-system/pom.xml index 76c5613fb26..1df3499dc5e 100644 --- a/build-system/pom.xml +++ b/build-system/pom.xml @@ -64,7 +64,7 @@ 1.0.1 1.7.12 4.2.5.RELEASE - 4.0.4.RELEASE + 4.1.0.RELEASE 6.8.8 1.2 2.1.1 @@ -744,6 +744,11 @@ spring-security-core ${spring.security.version} + + org.springframework.security + spring-security-ldap + ${spring.security.version} + aopalliance aopalliance @@ -1422,6 +1427,7 @@ xml-apis:xml-apis stax:stax-api + org.springframework.ldap:spring-ldap-core org.codehaus.woodstox:stax2-api @@ -1434,6 +1440,7 @@ xml-apis:xml-apis stax:stax-api + org.springframework.ldap:spring-ldap-core diff --git a/gui/admin-gui/pom.xml b/gui/admin-gui/pom.xml index e28d2d519bb..9850d6c4aed 100644 --- a/gui/admin-gui/pom.xml +++ b/gui/admin-gui/pom.xml @@ -464,6 +464,7 @@ org.springframework.security spring-security-core + org.springframework.security @@ -474,6 +475,11 @@ spring-security-config runtime + + org.springframework.security + spring-security-ldap + runtime + diff --git a/gui/admin-gui/src/main/webapp/WEB-INF/ctx-web-security.xml b/gui/admin-gui/src/main/webapp/WEB-INF/ctx-web-security.xml index 03d2b174cb2..fb8da5b4e66 100644 --- a/gui/admin-gui/src/main/webapp/WEB-INF/ctx-web-security.xml +++ b/gui/admin-gui/src/main/webapp/WEB-INF/ctx-web-security.xml @@ -19,7 +19,7 @@ xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd -http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd"> +http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.1.xsd"> @@ -107,9 +107,36 @@ http://www.springframework.org/schema/security http://www.springframework.org/sc - - - + + + + + + + + + + + + + uid={0},ou=people + + + + + + + + + + + + + diff --git a/model/model-impl/pom.xml b/model/model-impl/pom.xml index 9bc968161a1..371c21c1a12 100644 --- a/model/model-impl/pom.xml +++ b/model/model-impl/pom.xml @@ -193,6 +193,10 @@ org.springframework.security spring-security-core + + + org.springframework.security + spring-security-ldap org.apache.commons diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java index c0de283d556..61657ec2d5b 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java @@ -58,10 +58,14 @@ import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.xml.ns._public.common.common_3.*; +import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DirContextOperations; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -76,7 +80,7 @@ * @author semancik */ @Service(value = "userDetailsService") -public class UserProfileServiceImpl implements UserProfileService, UserDetailsService { +public class UserProfileServiceImpl implements UserProfileService, UserDetailsService, UserDetailsContextMapper { private static final Trace LOGGER = TraceManager.getTrace(UserProfileServiceImpl.class); @@ -316,13 +320,28 @@ public PrismObject resolveOwner(P @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { -// TODO Auto-generated method stub try { return getPrincipal(username); } catch (ObjectNotFoundException e) { throw new UsernameNotFoundException(e.getMessage(), e); } } + + @Override + public UserDetails mapUserFromContext(DirContextOperations ctx, String username, + Collection authorities) { + try { + return getPrincipal(username); + } catch (ObjectNotFoundException e) { + throw new UsernameNotFoundException(e.getMessage(), e); + } + } + + @Override + public void mapUserToContext(UserDetails user, DirContextAdapter ctx) { + // TODO Auto-generated method stub + + } } diff --git a/repo/security-api/pom.xml b/repo/security-api/pom.xml index 746fa4daaa5..b4d37811ac6 100644 --- a/repo/security-api/pom.xml +++ b/repo/security-api/pom.xml @@ -56,6 +56,7 @@ org.springframework.security spring-security-core + com.evolveum.midpoint.tools