From d7a1dc6a8c46beb21da305722295124a8e17d6b7 Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Mon, 9 Jan 2017 13:00:37 +0100 Subject: [PATCH 1/9] new module for Single Sign-on implementation --- modules/pom.xml | 3 +- modules/winauth-sso/pom.xml | 134 +++++++ .../module/winauthsso/SpringBootApp.java | 19 + .../common/api/AuthenticationManagerAD.java | 15 + .../common/api/AuthenticationSource.java | 96 +++++ .../common/api/PrincipalProfile.java | 44 +++ .../winauthsso/common/api/UserData.java | 123 +++++++ .../winauthsso/common/api/Usermanagement.java | 16 + .../winauthsso/common/api/WinauthSSO.java | 19 + .../api/accesscontrol/ActiveDirectory.java | 200 ++++++++++ .../common/api/security/UserDataAD.java | 125 +++++++ .../common/api/to/UserDetailsClientToAD.java | 110 ++++++ .../security/AuthenticationManagerImpl.java | 298 +++++++++++++++ .../security/AuthenticationSourceADImpl.java | 342 ++++++++++++++++++ .../common/impl/security/GroupMapperAD.java | 94 +++++ .../NegotiateCustomSecurityFilter.java | 13 + .../security/NegotiateSecurityFilterSSO.java | 84 +++++ .../PrincipalAccessControlProviderImplAD.java | 33 ++ .../impl/security/PrincipalProfileImpl.java | 129 +++++++ .../security/UserDetailsContextMapperAD.java | 108 ++++++ .../common/impl/security/WinauthSSOImpl.java | 258 +++++++++++++ .../common/impl/security/WinauthSSO_OLD.java | 219 +++++++++++ .../src/main/resources/application.properties | 9 + .../base/AuthenticationManagerImplTest.java | 39 ++ .../base/AuthenticationSourceADImplTest.java | 57 +++ .../winauth/base/GroupMapperADTest.java | 76 ++++ .../base/UserDetailsContextMapperADTest.java | 56 +++ .../module/winauth/base/WinauthSSOTest.java | 66 ++++ .../src/test/resources/application.properties | 56 +++ 29 files changed, 2840 insertions(+), 1 deletion(-) create mode 100644 modules/winauth-sso/pom.xml create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/PrincipalProfile.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/Usermanagement.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/WinauthSSO.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserDataAD.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateCustomSecurityFilter.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalProfileImpl.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java create mode 100644 modules/winauth-sso/src/main/resources/application.properties create mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java create mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java create mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java create mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java create mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java create mode 100644 modules/winauth-sso/src/test/resources/application.properties diff --git a/modules/pom.xml b/modules/pom.xml index d827cd4..4db23fd 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -16,8 +16,9 @@ foo reporting - i18n + i18n winauth + winauth-sso async diff --git a/modules/winauth-sso/pom.xml b/modules/winauth-sso/pom.xml new file mode 100644 index 0000000..ba021be --- /dev/null +++ b/modules/winauth-sso/pom.xml @@ -0,0 +1,134 @@ + + 4.0.0 + + com.capgemini.devonfw.dev + devonfw-modules + dev-SNAPSHOT + + com.capgemini.devonfw.modules + devonfw-winauth-sso + ${devonfw.version} + ${project.artifactId} + Single sign-on with Windows credentials authentication. + + + + + com.github.dblock.waffle + waffle-spring-security3 + + + + + javax.servlet + javax.servlet-api + provided + + + + + org.jasypt + jasypt + compile + + + + + + org.springframework.security + spring-security-ldap + + + org.apache.directory.server + apacheds-server-jndi + + + + org.springframework.security.kerberos + spring-security-kerberos-core + + + org.springframework.security.kerberos + spring-security-kerberos-web + + + org.springframework.security.kerberos + spring-security-kerberos-client + + + + + + org.hibernate + hibernate-validator-annotation-processor + 4.1.0.Final + + + + + org.springframework.boot + spring-boot + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-configuration-processor + true + + + javax.inject + javax.inject + + + org.springframework + spring-context + + + + org.springframework + spring-test + test + + + io.oasp.java.modules + oasp4j-test + test + + + io.oasp.java.modules + oasp4j-configuration + test + + + + io.oasp.java.modules + oasp4j-security + + + + io.oasp.java.modules + oasp4j-basic + + + + + io.oasp.java.modules + oasp4j-rest + + + + io.oasp.java.modules + oasp4j-beanmapping + + + + + + + + + diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java new file mode 100644 index 0000000..6894e16 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java @@ -0,0 +1,19 @@ +package com.capgemini.devonfw.module.winauthsso; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SuppressWarnings("javadoc") +@SpringBootApplication +// @EntityScan(basePackages = { "devonfw.winauthSample" }) +public class SpringBootApp { + /** + * Entry point for spring-boot based app + * + * @param args - arguments + */ + public static void main(String[] args) { + + SpringApplication.run(SpringBootApp.class, args); + } +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java new file mode 100644 index 0000000..858f915 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java @@ -0,0 +1,15 @@ +package com.capgemini.devonfw.module.winauthsso.common.api; + +import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; + +/** + * This class contains the configuration to the Active Directory authentication + * + * @author jhcore + */ +public interface AuthenticationManagerAD { + /** + * @return the LDAP authentication provider + */ + public LdapAuthenticationProvider LdapAuthenticationProvider(); +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java new file mode 100644 index 0000000..0864c3a --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java @@ -0,0 +1,96 @@ +package com.capgemini.devonfw.module.winauthsso.common.api; + +import javax.naming.directory.Attributes; + +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer; + +/** + * This class contains the configuration of the Active Directory + * + * @author jhcore + */ +public interface AuthenticationSource { + + /** + * @return AD username + */ + public String getUsername(); + + /** + * @param username new value of AD username. + */ + public void setUsername(String username); + + /** + * @return AD password + */ + public String getPassword(); + + /** + * @param password new value of AD password. + */ + public void setPassword(String password); + + /** + * @return AD domain + */ + public String getDomain(); + + /** + * @param domain new value of AD getdomain. + */ + public void setDomain(String domain); + + /** + * @param username AD username + * @return The user AD attributes + */ + public Attributes searchUserByUsername(String username); + + /** + * @return userSearchFiler + */ + public String getUserSearchFilter(); + + /** + * @param userSearchFiler new value of userSearchFilter. + */ + public void setUserSearchFilter(String userSearchFiler); + + /** + * @return userSearchBase + */ + public String getUserSearchBase(); + + /** + * @param userSearchBase new value of userSearchBase. + */ + public void setUserSearchBase(String userSearchBase); + + /** + * @return groupsPrefix + */ + public String getRolePrefix(); + + /** + * @param groupsPrefix new value of groupsPrefix. + */ + public void setRolePrefix(String groupsPrefix); + + /** + * @return url + */ + public String getUrl(); + + /** + * @param url new value of url. + */ + public void setUrl(String url); + + /** + * @return the authentication LDAP provider + */ + public LdapAuthenticationProviderConfigurer getLdapAuthenticationProviderConfigurer(); + +} \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/PrincipalProfile.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/PrincipalProfile.java new file mode 100644 index 0000000..42a195b --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/PrincipalProfile.java @@ -0,0 +1,44 @@ +package com.capgemini.devonfw.module.winauthsso.common.api; + +import java.security.Principal; +import java.util.List; + +/** + * This is the interface for the profile of a user in Active Directory. + * + * @author jhcore + * @since dev + */ +public interface PrincipalProfile extends Principal { + /** + * @return the unique id of the user for authentication and identification. + */ + String getId(); + + /** + * @return the unique login of the user for authentication and identification. + */ + @Override + String getName(); + + /** + * @return the first name of the users real name. + */ + String getFirstName(); + + /** + * @return the last name of the users real name. + */ + String getLastName(); + + /** + * @return the list of groups of this {@link PrincipalProfile}. + */ + List getGroups(); + + /** + * @param id + */ + void setId(String id); + +} \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java new file mode 100644 index 0000000..25deac4 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java @@ -0,0 +1,123 @@ +package com.capgemini.devonfw.module.winauthsso.common.api; + +import java.security.Principal; +import java.util.Collection; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; + +import com.capgemini.devonfw.module.winauthsso.common.api.to.UserDetailsClientToAD; + +/** + * Container class for the profile of a user. + * + * @author hohwille + */ +public class UserData extends User implements Principal { + + private static final long serialVersionUID = 1L; + + private PrincipalProfile userProfile; + + /** + * @return userProfile + */ + public PrincipalProfile getUserProfile() { + + return this.userProfile; + } + + /** + * @param userProfile new value of userProfile. + */ + public void setUserProfile(PrincipalProfile userProfile) { + + this.userProfile = userProfile; + } + + /** + * The constructor. + * + * @param username sets the username + * @param password sets the password + * @param enabled check if user is enabled + * @param accountNonExpired check if user account is not expired + * @param credentialsNonExpired check if user credentials are not expired + * @param accountNonLocked check if user account is not locked + * @param authorities the authorities/permissions the user has + */ + public UserData(String username, String password, boolean enabled, boolean accountNonExpired, + boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { + + super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); + } + + /** + * The constructor. + * + * @param username sets the username + * @param password sets the password + * @param authorities the authorities/permissions the user has + */ + public UserData(String username, String password, Collection authorities) { + + super(username, password, authorities); + } + + @Override + public String getName() { + + return getUsername(); + } + + /** + * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link UserData} + * instance. + */ + public UserDetailsClientToAD toClientTo() { + + UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); + clientTo.setId(this.userProfile.getId()); + clientTo.setName(this.userProfile.getName()); + clientTo.setFirstName(this.userProfile.getFirstName()); + clientTo.setLastName(this.userProfile.getLastName()); + clientTo.setGroups((this.userProfile.getGroups())); + return clientTo; + } + + @Override + public String toString() { + + return getName(); + } + + /** + * @return the {@link UserData} of the user currently logged in. + */ + public static UserData get() { + + return get(SecurityContextHolder.getContext().getAuthentication()); + } + + /** + * @param authentication is the {@link Authentication} where to retrieve the user from. + * @return the {@link UserData} of the logged in user from the given {@link Authentication}. + */ + public static UserData get(Authentication authentication) { + + if (authentication == null) { + throw new IllegalStateException("Authentication not available!"); + } + Object principal = authentication.getPrincipal(); + if (principal == null) { + throw new IllegalStateException("Principal not available!"); + } + try { + return (UserData) principal; + } catch (ClassCastException e) { + throw new IllegalStateException("Principal (" + principal + ") is not an instance of UserData!", e); + } + } +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/Usermanagement.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/Usermanagement.java new file mode 100644 index 0000000..0863284 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/Usermanagement.java @@ -0,0 +1,16 @@ +package com.capgemini.devonfw.module.winauthsso.common.api; + +/** + * Interface to get a user from its login. + * + * @author jhcore + */ +public interface Usermanagement { + + /** + * @param login The login of the requested user. + * @return The {@link PrincipalProfile} with the given login or {@code null} if no such object exists. + */ + PrincipalProfile findPrincipalProfileByLogin(String login); + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/WinauthSSO.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/WinauthSSO.java new file mode 100644 index 0000000..21542e9 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/WinauthSSO.java @@ -0,0 +1,19 @@ +package com.capgemini.devonfw.module.winauthsso.common.api; + +import waffle.spring.NegotiateSecurityFilter; +import waffle.spring.NegotiateSecurityFilterEntryPoint; + +/** + * This is the interface for a simple facade to manage the Winauth Single sign-on + * + * @author pparrado + * + */ +public interface WinauthSSO { + + public NegotiateSecurityFilter getSSOFilter(); + + public NegotiateSecurityFilterEntryPoint getSSOFilterEntryPoint(); + + public void setCustomFilter(NegotiateSecurityFilter waffleNegotiateSecurityFilter); +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java new file mode 100644 index 0000000..b4ebb40 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java @@ -0,0 +1,200 @@ +package com.capgemini.devonfw.module.winauthsso.common.api.accesscontrol; + +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +/** + * This class contains the configuration to connect with Active Directory + * + * @author jhcore + */ +public class ActiveDirectory { + private static final Logger LOG = LoggerFactory.getLogger(ActiveDirectory.class); + + /** Properties of the DirContext {"@link javax.naming.directory.DirContext} **/ + public Properties properties; + + /** Context of the {@link ActiveDirectory} **/ + public DirContext dirContext; + + /** Encapsulates factors that determine scope of search **/ + public SearchControls searchCtls; + + /** Attributes of the query to ActiveDirectory **/ + public String[] returnAttributes = { "sAMAccountName", "givenName", "sn", "cn", "mail", "memberOf" }; + + /** Domain of the server of ActiveDirectory **/ + public String domainBase; + + /** **/ + public String baseFilter = "(&((&(objectCategory=Person)(objectClass=User)))"; + + /** + * constructor with parameter for initializing a LDAP context + * + * @param username a {@link java.lang.String} object - username com.capgemini.devonfw.module.winauth.common.api.to + * establish a LDAP connection + * @param password a {@link java.lang.String} object - password com.capgemini.devonfw.module.winauth.common.api.to + * establish a LDAP connection + * @param domainController a {@link java.lang.String} object - domain controller name for LDAP connection + */ + public ActiveDirectory(String username, String password, String domainController) { + this.properties = new Properties(); + + this.properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); + this.properties.put(Context.PROVIDER_URL, "LDAP://" + domainController); + this.properties.put(Context.SECURITY_PRINCIPAL, username + "@" + domainController); + this.properties.put(Context.SECURITY_CREDENTIALS, password); + + // initializing active directory LDAP connection + try { + this.dirContext = new InitialDirContext(this.properties); + } catch (NamingException e) { + LOG.error(e.getMessage()); + } + + // default domain base for search + this.domainBase = getDomainBase(domainController); + + // initializing search controls + this.searchCtls = new SearchControls(); + this.searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); + this.searchCtls.setReturningAttributes(this.returnAttributes); + } + + /** + * The constructor. + */ + public ActiveDirectory() { + super(); + } + + /** + * @param username -> AD username + * @param password -> AD password + * @param domainController -> AD domainController + */ + public void connect(String username, String password, String domainController) { + + this.properties = new Properties(); + + this.properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); + this.properties.put(Context.PROVIDER_URL, "LDAP://" + domainController); + this.properties.put(Context.SECURITY_PRINCIPAL, username + "@" + domainController); + this.properties.put(Context.SECURITY_CREDENTIALS, password); + this.properties.put(Context.REFERRAL, "follow"); + // initializing active directory LDAP connection + try { + this.dirContext = new InitialDirContext(this.properties); + } catch (NamingException e) { + LOG.error(e.getMessage()); + } + + // default domain base for search + this.domainBase = getDomainBase(domainController); + + // initializing search controls + this.searchCtls = new SearchControls(); + this.searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); + this.searchCtls.setReturningAttributes(this.returnAttributes); + } + + /** + * @param returnAttributes + */ + @SuppressWarnings("javadoc") + public void setAttributes(String[] returnAttributes) { + + this.searchCtls.setReturningAttributes(this.returnAttributes); + } + + /** + * search the Active directory by username/email id for given search base + * + * @param searchValue a {@link java.lang.String} object - search value used for AD search for eg. username or email + * @param searchBy a {@link java.lang.String} object - scope of search by username or by email id + * @param searchBase a {@link java.lang.String} object - search base value for scope tree + * @return search result a {@link javax.naming.NamingEnumeration} object - active directory search result + */ + @SuppressWarnings("unchecked") + public NamingEnumeration searchUser(String searchValue, String searchBy, String searchBase) { + + String filter = getFilter(searchValue, searchBy); + String base = (null == searchBase) ? this.domainBase : getDomainBase(searchBase); // for eg.: "DC=myjeeva,DC=com"; + @SuppressWarnings("rawtypes") + NamingEnumeration result; + try { + result = this.dirContext.search(base, filter, this.searchCtls); + return result; + } catch (NamingException e) { + e.printStackTrace(); + UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); + LOG.warn("Failed com.capgemini.devonfw.module.winauth.common.api.to get user {}." + searchValue + exception); + throw exception; + } catch (Exception e) { + e.printStackTrace(); + UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); + LOG.warn("Failed com.capgemini.devonfw.module.winauth.common.api.to get user {}." + searchValue + exception); + throw exception; + } + } + + /** + * closes the LDAP connection with Domain controller + */ + public void closeLdapConnection() { + + try { + if (this.dirContext != null) + this.dirContext.close(); + } catch (NamingException e) { + LOG.error(e.getMessage()); + } + } + + /** + * active directory filter string value + * + * @param searchValue a {@link java.lang.String} object - search value of username/email id for active directory + * @param searchBy a {@link java.lang.String} object - scope of search by username or email id + * @return a {@link java.lang.String} object - filter string + */ + private String getFilter(String searchValue, String searchBy) { + + String filter = this.baseFilter; + filter += "(" + searchBy + "=" + searchValue + "))"; + /* + * if (searchBy.equals("email")) { filter += "(mail=" + searchValue + "))"; } else if (searchBy.equals("username")) + * { filter += "(samaccountname=" + searchValue + "))"; } + */ + return filter; + } + + /** + * creating a domain base value from domain controller name + */ + private static String getDomainBase(String base) { + + char[] namePair = base.toUpperCase().toCharArray(); + String dn = "DC="; + for (int i = 0; i < namePair.length; i++) { + if (namePair[i] == '.') { + dn += ",DC=" + namePair[++i]; + } else { + dn += namePair[i]; + } + } + return dn; + } +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserDataAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserDataAD.java new file mode 100644 index 0000000..78ee28f --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserDataAD.java @@ -0,0 +1,125 @@ +package com.capgemini.devonfw.module.winauthsso.common.api.security; + +import java.security.Principal; +import java.util.Collection; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; + +import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; +import com.capgemini.devonfw.module.winauthsso.common.api.to.UserDetailsClientToAD; + +/** + * Container class for the profile of a user. + * + * @author hohwille, jhcore + */ +public class UserDataAD extends User implements Principal { + + private static final long serialVersionUID = 1L; + + private PrincipalProfile userProfile; + + /** + * The constructor. + * + * @param username sets the username + * @param password sets the password + * @param enabled check if user is enabled + * @param accountNonExpired check if user account is not expired + * @param credentialsNonExpired check if user credentials are not expired + * @param accountNonLocked check if user account is not locked + * @param authorities the authorities/permissions the user has + */ + public UserDataAD(String username, String password, boolean enabled, boolean accountNonExpired, + boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { + + super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); + } + + /** + * The constructor. + * + * @param username sets the username + * @param password sets the password + * @param authorities the authorities/permissions the user has + */ + public UserDataAD(String username, String password, Collection authorities) { + + super(username, password, authorities); + } + + @Override + public String getName() { + + return getUsername(); + } + + /** + * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link UserDataAD} + * instance. + */ + public UserDetailsClientToAD toClientTo() { + + UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); + clientTo.setId(this.userProfile.getId()); + clientTo.setName(this.userProfile.getName()); + clientTo.setFirstName(this.userProfile.getFirstName()); + clientTo.setLastName(this.userProfile.getLastName()); + clientTo.setGroups(this.userProfile.getGroups()); + return clientTo; + } + + @Override + public String toString() { + + return getName(); + } + + /** + * @return userProfile + */ + public PrincipalProfile getUserProfile() { + + return this.userProfile; + } + + /** + * @param userProfile the userProfile com.capgemini.devonfw.module.winauth.common.api.to set + */ + public void setUserProfile(PrincipalProfile userProfile) { + + this.userProfile = userProfile; + } + + /** + * @return the {@link UserDataAD} of the user currently logged in. + */ + public static UserDataAD get() { + + return get(SecurityContextHolder.getContext().getAuthentication()); + } + + /** + * @param authentication is the {@link Authentication} where com.capgemini.devonfw.module.winauth.common.api.to + * retrieve the user from. + * @return the {@link UserDataAD} of the logged in user from the given {@link Authentication}. + */ + public static UserDataAD get(Authentication authentication) { + + if (authentication == null) { + throw new IllegalStateException("Authentication not available!"); + } + Object principal = authentication.getPrincipal(); + if (principal == null) { + throw new IllegalStateException("Principal not available!"); + } + try { + return (UserDataAD) principal; + } catch (ClassCastException e) { + throw new IllegalStateException("Principal (" + principal + ") is not an instance of UserDataAD!", e); + } + } +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java new file mode 100644 index 0000000..65ec395 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java @@ -0,0 +1,110 @@ +package com.capgemini.devonfw.module.winauthsso.common.api.to; + +import java.util.List; + +import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; + +import io.oasp.module.basic.common.api.to.AbstractTo; + +/** + * This is the {@link AbstractTo TO} for the client view on the user AD details. + * + * @author hohwille, jhcore + */ +public class UserDetailsClientToAD extends AbstractTo implements PrincipalProfile { + + /** UID for serialization. */ + private static final long serialVersionUID = 1L; + + private String id; + + private String name; + + private String firstName; + + private String lastName; + + private List groups; + + /** + * The constructor. + */ + public UserDetailsClientToAD() { + + super(); + } + + @Override + public String getId() { + + return this.id; + } + + @Override + public String getName() { + + return this.name; + } + + @Override + public String getFirstName() { + + return this.firstName; + } + + @Override + public String getLastName() { + + return this.lastName; + } + + @Override + public List getGroups() { + + return this.groups; + } + + /** + * Sets the ID. + * + * @param id the ID com.capgemini.devonfw.module.winauth.common.api.to set + */ + public void setId(String id) { + + this.id = id; + } + + /** + * @param name the name com.capgemini.devonfw.module.winauth.common.api.to set + */ + public void setName(String name) { + + this.name = name; + } + + /** + * @param firstName the firstName com.capgemini.devonfw.module.winauth.common.api.to set + */ + public void setFirstName(String firstName) { + + this.firstName = firstName; + } + + /** + * @param lastName the lastName com.capgemini.devonfw.module.winauth.common.api.to set + */ + public void setLastName(String lastName) { + + this.lastName = lastName; + } + + /** + * @param groups of the AD user + */ + public void setGroups(List groups) { + + this.groups = groups; + + } + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java new file mode 100644 index 0000000..c4bd322 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java @@ -0,0 +1,298 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.Properties; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; +import org.jasypt.properties.EncryptableProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.ldap.DefaultSpringSecurityContextSource; +import org.springframework.security.ldap.authentication.BindAuthenticator; +import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; +import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; +import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; + +import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationManagerAD; + +/** + * Implementation of {@link AuthenticationManagerAD} + * + * @author jhcore + */ +@Named +@Configuration +@ConfigurationProperties(prefix = "devon.winauth.ldap") +public class AuthenticationManagerImpl implements AuthenticationManagerAD { + + /** + * Password of the server authentication + */ + private String password; + + /** + * Server domain + */ + private String url = "ldap://domain.com"; + + private String userSearchFilter = "(uid={0})"; + + private String userSearchBase = ""; + + private String userDn = ""; + + private String keyPass; + + private StandardPBEStringEncryptor encryptor; + + private boolean encrypt = false; + + /** + * @return encryptor + */ + public StandardPBEStringEncryptor getEncryptor() { + + return this.encryptor; + } + + /** + * @param encryptor new value of encryptor. + */ + public void setEncryptor(StandardPBEStringEncryptor encryptor) { + + this.encryptor = encryptor; + } + + /** + * @return encrypt + */ + public boolean isEncrypt() { + + return this.encrypt; + } + + /** + * @param encrypt new value of encrypt. + */ + public void setEncrypt(boolean encrypt) { + + this.encrypt = encrypt; + } + + /** + * @return userDn + */ + public String getUserDn() { + + return this.userDn; + } + + /** + * @param userDn new value of userDn. + */ + public void setUserDn(String userDn) { + + this.userDn = userDn; + } + + @Inject + private UserDetailsContextMapper userDetailsContextMapper; + + private String[] patterns = {}; + + /** + * @return patterns + */ + public String[] getPatterns() { + + return this.patterns; + } + + /** + * @param patterns new value of patterns. + */ + public void setPatterns(String[] patterns) { + + this.patterns = patterns; + } + + @Override + @Bean + public LdapAuthenticationProvider LdapAuthenticationProvider() { + + LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(BindAuthenticator()); + ldapAuthenticationProvider.setUserDetailsContextMapper(this.userDetailsContextMapper); + return ldapAuthenticationProvider; + } + + /** + * @return userDetailsContextMapper + */ + @Bean + public UserDetailsContextMapper getUserDetailsContextMapper() { + + if (this.userDetailsContextMapper != null) + return this.userDetailsContextMapper; + else + return new UserDetailsContextMapperAD(); + } + + /** + * @param userDetailsContextMapper new value of userDetailsContextMapper. + */ + + public void setUserDetailsContextMapper(UserDetailsContextMapper userDetailsContextMapper) { + + this.userDetailsContextMapper = userDetailsContextMapper; + } + + // @Bean + // public UserDetailsContextMapper UserDetailsContextMapper() { + // + // return new UserDetailsContextMapperAD(); + // } + + /** + * The class BindAuthenticator in the package {@link org.springframework.security.ldap.authentication} implements the + * bind authentication strategy. It simply attempts to bind as the user. + * + * @return the bind authentication strategy + */ + @Bean + public BindAuthenticator BindAuthenticator() { + + BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource()); + bindAuthenticator.setUserSearch(userSearch()); + bindAuthenticator.setUserDnPatterns(this.patterns); + return bindAuthenticator; + + } + + /** + * ContextSource implementation which uses Spring LDAP's LdapContextSource as a base class. Used internally by the + * Spring Security LDAP namespace configuration. + * + * @return the LdapContextSource + */ + @Bean + public DefaultSpringSecurityContextSource contextSource() { + + String pass = this.password; + + if (this.encrypt) { + this.encryptor = new StandardPBEStringEncryptor(); + this.encryptor.setPassword(this.keyPass); + + Properties props = new EncryptableProperties(this.encryptor); + props.setProperty("password", this.password); + pass = props.getProperty("password"); + } + + DefaultSpringSecurityContextSource defaultSpringSecurityContextSource = + new DefaultSpringSecurityContextSource(this.url); + defaultSpringSecurityContextSource.setUserDn(this.userDn); + defaultSpringSecurityContextSource.setPassword(pass); + return defaultSpringSecurityContextSource; + } + + /** + * @return keyPass + */ + public String getKeyPass() { + + return this.keyPass; + } + + /** + * @param keyPass new value of keyPass. + */ + public void setKeyPass(String keyPass) { + + this.keyPass = keyPass; + } + + /** + * LdapUserSearch implementation which uses an Ldap filter to locate the user. + * + * @return the LdapUserSearch + */ + @Bean + public FilterBasedLdapUserSearch userSearch() { + + FilterBasedLdapUserSearch filterBasedLdapUserSearch = + new FilterBasedLdapUserSearch(this.userSearchBase, this.userSearchFilter, contextSource()); + return filterBasedLdapUserSearch; + } + + /** + * @return password + */ + public String getPassword() { + + return this.password; + } + + /** + * @param password new value of password. + */ + public void setPassword(String password) { + + this.password = password; + } + + /** + * @return domain + */ + + /** + * @return userSearchFilter + */ + public String getUserSearchFilter() { + + return this.userSearchFilter; + } + + /** + * @return url + */ + public String getUrl() { + + return this.url; + } + + /** + * @param url new value of url. + */ + public void setUrl(String url) { + + this.url = url; + } + + /** + * @param userSearchFilter new value of userSearchFilter. + */ + public void setUserSearchFilter(String userSearchFilter) { + + this.userSearchFilter = userSearchFilter; + } + + /** + * @return userSearchBase + */ + public String getUserSearchBase() { + + return this.userSearchBase; + } + + /** + * @param userSearchBase new value of userSearchBase. + */ + public void setUserSearchBase(String userSearchBase) { + + this.userSearchBase = userSearchBase; + } + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java new file mode 100644 index 0000000..0102f6e --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java @@ -0,0 +1,342 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.Properties; + +import javax.inject.Named; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.SearchResult; + +import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; +import org.jasypt.properties.EncryptableProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; +import com.capgemini.devonfw.module.winauthsso.common.api.accesscontrol.ActiveDirectory; + +/** + * Implementation of {@link AuthenticationSource} + * + * @author jhcore + */ +@ConfigurationProperties(prefix = "devon.winauth.ad") +@Named +public class AuthenticationSourceADImpl implements AuthenticationSource { + + private static final Logger LOG = LoggerFactory.getLogger(AuthenticationSourceADImpl.class); + + /** + * Instance of the ActiveDirectory class. We need it to do the query. + */ + private ActiveDirectory activeDirectory; + + /** + * User name of the server authentication + */ + private String username = ""; + + /** + * Password of the server authentication + */ + private String password; + + /** + * Server domain + */ + private String domain = ""; + + private String userSearchFilter = "(uid={0})"; + + private String userSearchBase = ""; + + private String searchBy = ""; + + private String rolePrefix = ""; + + private String url = ""; + + private StandardPBEStringEncryptor encryptor; + + private String keyPass; + + private boolean encrypt = false; + + /** + * @return searchBy + */ + public String getSearchBy() { + + return this.searchBy; + } + + /** + * @param searchBy new value of searchBy. + */ + public void setSearchBy(String searchBy) { + + this.searchBy = searchBy; + } + + /** + * The constructor. + */ + public AuthenticationSourceADImpl() { + super(); + this.activeDirectory = new ActiveDirectory(); + if (this.searchBy == null || this.searchBy.equals("")) { + this.searchBy = "samaccountname"; + } + + } + + @Override + public LdapAuthenticationProviderConfigurer getLdapAuthenticationProviderConfigurer() { + + LdapAuthenticationProviderConfigurer ldap = + new LdapAuthenticationProviderConfigurer<>(); + + String pass = this.password; + + if (this.encrypt) { + this.encryptor = new StandardPBEStringEncryptor(); + this.encryptor.setPassword(this.keyPass); + + Properties props = new EncryptableProperties(this.encryptor); + props.setProperty("password", this.password); + pass = props.getProperty("password"); + } + + ldap.userSearchBase(this.userSearchBase).userSearchFilter(this.userSearchFilter).rolePrefix(this.rolePrefix) + .contextSource().managerDn(this.username).managerPassword(pass).url(this.url); + + return ldap; + }; + + /** + * @return keyPass + */ + public String getKeyPass() { + + return this.keyPass; + } + + /** + * @param keyPass new value of keyPass. + */ + public void setKeyPass(String keyPass) { + + this.keyPass = keyPass; + } + + /** + * @return encrypt + */ + public boolean isEncrypt() { + + return this.encrypt; + } + + /** + * @param encrypt new value of encrypt. + */ + public void setEncrypt(boolean encrypt) { + + this.encrypt = encrypt; + } + + /** + * The constructor. + * + * @param username + * @param password + * @param domain + */ + @SuppressWarnings("javadoc") + public AuthenticationSourceADImpl(String username, String password, String domain) { + super(); + } + + /** + * @param searchValue -> the value of the user name we are searching + * @return attributes of the user + */ + @Override + public Attributes searchUserByUsername(String searchValue) { + + NamingEnumeration result; + try { + String pass = this.password; + if (this.encrypt) { + this.encryptor = new StandardPBEStringEncryptor(); + this.encryptor.setPassword(this.keyPass); + + Properties props = new EncryptableProperties(this.encryptor); + props.setProperty("password", this.password); + pass = props.getProperty("password"); + } + this.activeDirectory.connect(this.username, pass, this.domain); + + result = this.activeDirectory.searchUser(searchValue, this.searchBy, this.domain); + } finally { + this.activeDirectory.closeLdapConnection(); + } + // (&((&(objectCategory=Person)(objectClass=User)))(samaccountname=Servidor Web)) + try { + Attributes attrs = result.next().getAttributes(); + return attrs; + } catch (NamingException e) { + e.printStackTrace(); + UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); + LOG.error("Failed to get user {}.", this.username, exception); + throw exception; + } + } + + /** + * @return activeDirectory + */ + public ActiveDirectory getActiveDirectory() { + + return this.activeDirectory; + } + + /** + * @param activeDirectory new value of {@link ActiveDirectory}. + */ + public void setActiveDirectory(ActiveDirectory activeDirectory) { + + this.activeDirectory = activeDirectory; + } + + /** + * @return username + */ + @Override + public String getUsername() { + + return this.username; + } + + /** + * @param username new value of username. + */ + @Override + public void setUsername(String username) { + + this.username = username; + } + + /** + * @return password + */ + @Override + public String getPassword() { + + return this.password; + } + + /** + * @param password new value of password. + */ + @Override + public void setPassword(String password) { + + this.password = password; + } + + /** + * @return domain + */ + @Override + public String getDomain() { + + return this.domain; + } + + /** + * @param domain new value of domain. + */ + @Override + public void setDomain(String domain) { + + this.domain = domain; + } + + /** + * @return userSearchFilter + */ + @Override + public String getUserSearchFilter() { + + return this.userSearchFilter; + } + + /** + * @param userSearchFiler new value of userSearchFilter. + */ + @Override + public void setUserSearchFilter(String userSearchFiler) { + + this.userSearchFilter = userSearchFiler; + } + + /** + * @return userSearchBase + */ + @Override + public String getUserSearchBase() { + + return this.userSearchBase; + } + + /** + * @param userSearchBase new value of userSearchBase. + */ + @Override + public void setUserSearchBase(String userSearchBase) { + + this.userSearchBase = userSearchBase; + } + + /** + * @return rolePrefix + */ + @Override + public String getRolePrefix() { + + return this.rolePrefix; + } + + /** + * @param rolePrefix new value of rolePrefix. + */ + @Override + public void setRolePrefix(String rolePrefix) { + + this.rolePrefix = rolePrefix; + } + + /** + * @return url + */ + @Override + public String getUrl() { + + return this.url; + } + + /** + * @param url new value of url. + */ + @Override + public void setUrl(String url) { + + this.url = url; + } +} \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java new file mode 100644 index 0000000..00851d1 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java @@ -0,0 +1,94 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Named; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * This class contains the methods to map the AD groups to Application groups. + * + * @author jhcore + */ +@ConfigurationProperties(prefix = "devon.winauth") +@Named("GroupMapperAD") +public class GroupMapperAD { + + /** + * The constructor. + */ + public GroupMapperAD() { + super(); + this.groups = new HashMap<>(); + } + + /** + * + */ + public HashMap> groups; + + /** + * @return groups + */ + public HashMap> getGroups() { + + return this.groups; + } + + /** + * @param groups new value of the user groups. + */ + public void setGroups(HashMap> groups) { + + this.groups = groups; + } + + /** + * @param memberOf chair with the AD groups + * @return an ArrayList with the the mapping groups + */ + public ArrayList groupsMapping(String memberOf) { + + ArrayList result = new ArrayList<>(); + + // Search the CN groups of memberOf + Pattern p = Pattern.compile("CN=[A-Za-z0-9-\\--\\.]*"); + Matcher m = p.matcher(memberOf); + + ArrayList groupsAD = new ArrayList<>(); + + // Delete the substring "CN=" + while (m.find()) { + groupsAD.add(m.group().substring(3)); + } + + // Mapping the groupsAD to groups + for (int i = 0; i < groupsAD.size(); i++) { + if (this.groups.values().toString().contains(groupsAD.get(i))) { + result.add(getKeysByValue(groupsAD.get(i))); + } + } + + return result; + } + + private String getKeysByValue(String value) { + + String result = null; + + for (Entry> e : this.groups.entrySet()) { + for (int i = 0; i < e.getValue().size(); i++) + if (e.getValue().get(i).equals(value)) { + result = e.getKey(); + break; + } + } + return result; + } + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateCustomSecurityFilter.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateCustomSecurityFilter.java new file mode 100644 index 0000000..78b8e97 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateCustomSecurityFilter.java @@ -0,0 +1,13 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import waffle.spring.NegotiateSecurityFilter; + +/** + * Wrapper for {@link NegotiateSecurityFilter} + * + * @author pparrado + * + */ +public class NegotiateCustomSecurityFilter extends NegotiateSecurityFilter { + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java new file mode 100644 index 0000000..e87a135 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java @@ -0,0 +1,84 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.core.Authentication; + +import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; + +import waffle.servlet.spi.SecurityFilterProviderCollection; +import waffle.spring.NegotiateSecurityFilter; + +/** + * This is a dummy implementation of NegotiateSecurityFilterSSO. The functionality is the same of the class + * NegotiateSecurityFilter. Is created to inject the bean of the class WinauthSSO in the case of we don't want to + * implement our own Filter and build the UserDetails. + * + * In a case we want to implement a new UserDetail, we can implement NegotiateSecurityFilterSSO and build a User in the + * method boolean setAuthentication(HttpServletRequest, HttpServletResponse, Authentication). + * + * @author jhcore + */ +public class NegotiateSecurityFilterSSO extends NegotiateSecurityFilter { + + /** + * The constructor. + */ + public NegotiateSecurityFilterSSO() { + super(); + } + + @Override + public void setProvider(SecurityFilterProviderCollection securityFilterProviderCollection) { + + super.setProvider(securityFilterProviderCollection); + } + + private AuthenticationSource authenticationSource; + + private GroupMapperAD groupMapperAD; + + /** + * @return authenticationSource + */ + public AuthenticationSource getAuthenticationSource() { + + return this.authenticationSource; + } + + /** + * @param authenticationSource new value of authenticationSource. + */ + @Inject + public void setAuthenticationSource(AuthenticationSource authenticationSource) { + + this.authenticationSource = authenticationSource; + } + + /** + * @return groupMapperAD + */ + public GroupMapperAD getGroupMapperAD() { + + return this.groupMapperAD; + } + + /** + * @param groupMapperAD new value of groupMapperAD. + */ + @Inject + public void setGroupMapperAD(GroupMapperAD groupMapperAD) { + + this.groupMapperAD = groupMapperAD; + } + + @Override + protected boolean setAuthentication(final HttpServletRequest request, final HttpServletResponse response, + final Authentication authentication) { + + return super.setAuthentication(request, response, authentication); + } + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java new file mode 100644 index 0000000..d274a60 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java @@ -0,0 +1,33 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.Collection; + +import javax.inject.Named; + +import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; + +import io.oasp.module.security.common.api.accesscontrol.PrincipalAccessControlProvider; + +/** + * Implementation of PrincipalAccessControlProvider + * + * @author jhcore + */ +@Named +public class PrincipalAccessControlProviderImplAD implements PrincipalAccessControlProvider { + + /** + * The constructor. + */ + public PrincipalAccessControlProviderImplAD() { + + super(); + } + + @Override + public Collection getAccessControlIds(PrincipalProfile principal) { + + return principal.getGroups(); + } + +} \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalProfileImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalProfileImpl.java new file mode 100644 index 0000000..f2dfbd3 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalProfileImpl.java @@ -0,0 +1,129 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.List; +import java.util.Locale; + +import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; + +/** + * Implementation of {@link PrincipalProfile}. + * + * @author jhcore + */ +public class PrincipalProfileImpl implements PrincipalProfile { + + private String name; + + private String firstName; + + private String lastName; + + private List groups; + + private Locale language; + + private String id; + + /** + * The constructor. + */ + public PrincipalProfileImpl() { + } + + /** + * @return name + */ + @Override + public String getName() { + + return this.name; + } + + /** + * @param name new value of user name. + */ + public void setName(String name) { + + this.name = name; + } + + /** + * @return firstName + */ + @Override + public String getFirstName() { + + return this.firstName; + } + + /** + * @param firstName new value of user first name. + */ + public void setFirstName(String firstName) { + + this.firstName = firstName; + } + + /** + * @return lastName + */ + @Override + public String getLastName() { + + return this.lastName; + } + + /** + * @param lastName new value of user last name. + */ + public void setLastName(String lastName) { + + this.lastName = lastName; + } + + /** + * @return groups + */ + @Override + public List getGroups() { + + return this.groups; + } + + /** + * @param groups new value of user groups + */ + public void setGroups(List groups) { + + this.groups = groups; + } + + @Override + public String getId() { + + return this.id; + } + + /** + * @return language + */ + public Locale getLanguage() { + + return this.language; + } + + /** + * @param language the language to set + */ + public void setLanguage(Locale language) { + + this.language = language; + } + + @Override + public void setId(String id) { + + this.id = id; + } + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java new file mode 100644 index 0000000..9019be6 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java @@ -0,0 +1,108 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.inject.Inject; +import javax.naming.directory.Attributes; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DirContextOperations; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; + +import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; +import com.capgemini.devonfw.module.winauthsso.common.api.UserData; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.AuthenticationManagerImpl; + +/** + * Implementation of {@link UserDetailsContextMapper} + * + * @author jhcore + */ +// @Named("UserDetailsContextMapperAD") +public class UserDetailsContextMapperAD implements UserDetailsContextMapper { + + private static final Logger LOG = LoggerFactory.getLogger(AuthenticationManagerImpl.class); + + @Inject + private AuthenticationSource authenticationSource; + + @Inject + private GroupMapperAD groupMapperAD; + + /** + * @return authenticationSource + */ + public AuthenticationSource getAuthenticationSource() { + + return this.authenticationSource; + } + + /** + * @param authenticationSource new value of authenticationSource. + */ + public void setAuthenticationSource(AuthenticationSource authenticationSource) { + + this.authenticationSource = authenticationSource; + } + + /** + * @return groupMapperAD + */ + public GroupMapperAD getGroupMapperAD() { + + return this.groupMapperAD; + } + + /** + * @param groupMapperAD new value of groupMapperAD. + */ + public void setGroupMapperAD(GroupMapperAD groupMapperAD) { + + this.groupMapperAD = groupMapperAD; + } + + @Override + public UserDetails mapUserFromContext(DirContextOperations ctx, String username, + Collection authorities) { + + UserData user = new UserData(username, "", authorities); + + try { + Attributes attributes = this.authenticationSource.searchUserByUsername(username); + + String cn = attributes.get("cn").toString().substring(4);// Username + String givenname = attributes.get("givenname").toString().substring(11); // FirstName + String sn = attributes.get("sn").toString().substring(4);// LastName + String memberOf = attributes.get("memberof").toString().substring(10); // Groups + + PrincipalProfileImpl userProfile = new PrincipalProfileImpl(); + userProfile.setName(cn); + userProfile.setFirstName(givenname); + userProfile.setLastName(sn); + userProfile.setId(cn); + ArrayList groups = this.groupMapperAD.groupsMapping(memberOf); + + userProfile.setGroups(groups); + + user.setUserProfile(userProfile); + } catch (Exception e) { + e.printStackTrace(); + UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); + LOG.warn("Failed com.capgemini.devonfw.module.winauth.common.impl.security get user {} in Active Directory." + + username + exception); + throw exception; + } + return user; + } + + @Override + public void mapUserToContext(UserDetails user, DirContextAdapter ctx) { + + } +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java new file mode 100644 index 0000000..3bde755 --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java @@ -0,0 +1,258 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Named; + +import com.capgemini.devonfw.module.winauthsso.common.api.WinauthSSO; + +import waffle.servlet.spi.NegotiateSecurityFilterProvider; +import waffle.servlet.spi.SecurityFilterProvider; +import waffle.servlet.spi.SecurityFilterProviderCollection; +import waffle.spring.NegotiateSecurityFilter; +import waffle.spring.NegotiateSecurityFilterEntryPoint; +import waffle.spring.WindowsAuthenticationProvider; +import waffle.windows.auth.impl.WindowsAuthProviderImpl; + +/** + * @author pparrado + * + */ +@Named +public class WinauthSSOImpl implements WinauthSSO { + + // @Override + // public NegotiateSecurityFilterEntryPoint getNegotiateSecurityFilterEntryPoint() { + // + // // TODO Auto-generated method stub + // return null; + // } + // + + private WindowsAuthenticationProvider waffleWindowsAuthProvider; + + private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider; + + private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection; + + private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint; + + private NegotiateSecurityFilter waffleNegotiateSecurityFilter; + + /** + * The constructor. + */ + public WinauthSSOImpl() { + this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilter(); + init(); + } + + /** + * The constructor with arguments. + * + * @param waffleNegotiateSecurityFilter contains the authentication customized + */ + public WinauthSSOImpl(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { + this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; + init(); + } + + @Override + public void setCustomFilter(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { + + this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; + init(); + } + + /** + * Initialize the variables of the class + */ + public void init() { + + this.waffleWindowsAuthProvider = waffleWindowsAuthProvider(); + + this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider(); + + this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection(); + + this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint(); + + this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter(); + } + + /** + * @return the WindowsAuthProvider + */ + private WindowsAuthenticationProvider waffleWindowsAuthProvider() { + + WindowsAuthenticationProvider windowsAuthenticationProvider = new WindowsAuthenticationProvider(); + windowsAuthenticationProvider.setAuthProvider(new WindowsAuthProviderImpl()); + return windowsAuthenticationProvider; + } + + /** + * @return negotiateSecurityFilterProvider + */ + private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider() { + + return new NegotiateSecurityFilterProvider(this.waffleWindowsAuthProvider.getAuthProvider()); + } + + /** + * @return SecurityFilterProviderCollection + */ + private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection() { + + final List securityFilterProviders = new ArrayList<>(); + + securityFilterProviders.add(this.negotiateSecurityFilterProvider); + + return new SecurityFilterProviderCollection(securityFilterProviders.toArray(new SecurityFilterProvider[] {})); + } + + /** + * @return NegotiateSecurityFilterEntryPoint + */ + private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint() { + + this.negotiateSecurityFilterEntryPoint = new NegotiateSecurityFilterEntryPoint(); + + this.negotiateSecurityFilterEntryPoint.setProvider(this.waffleSecurityFilterProviderCollection); + + return this.negotiateSecurityFilterEntryPoint; + } + + /** + * @return NegotiateSecurityFilter + */ + public NegotiateSecurityFilter getNegotiateSecurityFilter() { + + if (this.waffleNegotiateSecurityFilter == null) { + this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilterSSO(); + } + + this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); + return this.waffleNegotiateSecurityFilter; + } + + /** + * @return NegotiateSecurityFilter + */ + private NegotiateSecurityFilter waffleNegotiateSecurityFilter() { + + this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); + + return this.waffleNegotiateSecurityFilter; + } + + /* + * GETTERS and SETTERS + */ + + /** + * @return waffleWindowsAuthProvider + */ + public WindowsAuthenticationProvider getWaffleWindowsAuthProvider() { + + return this.waffleWindowsAuthProvider; + } + + /** + * @param waffleWindowsAuthProvider new value of waffleWindowsAuthProvider. + */ + public void setWaffleWindowsAuthProvider(WindowsAuthenticationProvider waffleWindowsAuthProvider) { + + this.waffleWindowsAuthProvider = waffleWindowsAuthProvider; + } + + /** + * @return negotiateSecurityFilterProvider + */ + public NegotiateSecurityFilterProvider getNegotiateSecurityFilterProvider() { + + return this.negotiateSecurityFilterProvider; + } + + /** + * @param negotiateSecurityFilterProvider new value of negotiateSecurityFilterProvider. + */ + public void setNegotiateSecurityFilterProvider(NegotiateSecurityFilterProvider negotiateSecurityFilterProvider) { + + this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider; + } + + /** + * @return waffleSecurityFilterProviderCollection + */ + public SecurityFilterProviderCollection getWaffleSecurityFilterProviderCollection() { + + return this.waffleSecurityFilterProviderCollection; + } + + /** + * @param waffleSecurityFilterProviderCollection new value of waffleSecurityFilterProviderCollection. + */ + public void setWaffleSecurityFilterProviderCollection( + SecurityFilterProviderCollection waffleSecurityFilterProviderCollection) { + + this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection; + } + + /** + * @return negotiateSecurityFilterEntryPoint + */ + public NegotiateSecurityFilterEntryPoint getNegotiateSecurityFilterEntryPoint() { + + return this.negotiateSecurityFilterEntryPoint; + } + + /** + * @param negotiateSecurityFilterEntryPoint new value of negotiateSecurityFilterEntryPoint. + */ + public void setNegotiateSecurityFilterEntryPoint( + NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint) { + + this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint; + } + + /** + * @return waffleNegotiateSecurityFilter + */ + + public NegotiateSecurityFilter getWaffleNegotiateSecurityFilter() { + + return this.waffleNegotiateSecurityFilter; + } + + /** + * Gets the NegotiateSecurityFilter. This method is a wrapper for getWaffleNegotiateSecurityFilter() + * + * @return {@link NegotiateSecurityFilter} + */ + @Override + public NegotiateSecurityFilter getSSOFilter() { + + return getWaffleNegotiateSecurityFilter(); + } + + /** + * Gets the NegotiateSecurityFilterEntryPoint. This method is a wrapper for getNegotiateSecurityFilterEntryPoint() + * + * @return {@link NegotiateSecurityFilterEntryPoint} + */ + @Override + public NegotiateSecurityFilterEntryPoint getSSOFilterEntryPoint() { + + return getNegotiateSecurityFilterEntryPoint(); + } + + /** + * @param waffleNegotiateSecurityFilter new value of waffleNegotiateSecurityFilter. + */ + public void setWaffleNegotiateSecurityFilter(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { + + this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; + } + +} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java new file mode 100644 index 0000000..ab7057d --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java @@ -0,0 +1,219 @@ +package com.capgemini.devonfw.module.winauthsso.common.impl.security; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Named; + +import waffle.servlet.spi.NegotiateSecurityFilterProvider; +import waffle.servlet.spi.SecurityFilterProvider; +import waffle.servlet.spi.SecurityFilterProviderCollection; +import waffle.spring.NegotiateSecurityFilter; +import waffle.spring.NegotiateSecurityFilterEntryPoint; +import waffle.spring.WindowsAuthenticationProvider; +import waffle.windows.auth.impl.WindowsAuthProviderImpl; + +/** + * This class initialize all Waffle Single Sign On configuration. + * + * @author jhcore + */ +@Named +public class WinauthSSO_OLD { + + private WindowsAuthenticationProvider waffleWindowsAuthProvider; + + private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider; + + private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection; + + private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint; + + private NegotiateSecurityFilter waffleNegotiateSecurityFilter; + + /** + * The constructor. + */ + public WinauthSSO_OLD() { + this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilter(); + init(); + } + + /** + * The constructor with arguments. + * + * @param waffleNegotiateSecurityFilter contains the authentication customized + */ + public WinauthSSO_OLD(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { + this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; + init(); + } + + /** + * Initialize the variables of the class + */ + public void init() { + + this.waffleWindowsAuthProvider = waffleWindowsAuthProvider(); + + this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider(); + + this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection(); + + this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint(); + + this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter(); + } + + /** + * @return the WindowsAuthProvider + */ + private WindowsAuthenticationProvider waffleWindowsAuthProvider() { + + WindowsAuthenticationProvider windowsAuthenticationProvider = new WindowsAuthenticationProvider(); + windowsAuthenticationProvider.setAuthProvider(new WindowsAuthProviderImpl()); + return windowsAuthenticationProvider; + } + + /** + * @return negotiateSecurityFilterProvider + */ + private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider() { + + return new NegotiateSecurityFilterProvider(this.waffleWindowsAuthProvider.getAuthProvider()); + } + + /** + * @return SecurityFilterProviderCollection + */ + private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection() { + + final List securityFilterProviders = new ArrayList<>(); + + securityFilterProviders.add(this.negotiateSecurityFilterProvider); + + return new SecurityFilterProviderCollection(securityFilterProviders.toArray(new SecurityFilterProvider[] {})); + } + + /** + * @return NegotiateSecurityFilterEntryPoint + */ + private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint() { + + this.negotiateSecurityFilterEntryPoint = new NegotiateSecurityFilterEntryPoint(); + + this.negotiateSecurityFilterEntryPoint.setProvider(this.waffleSecurityFilterProviderCollection); + + return this.negotiateSecurityFilterEntryPoint; + } + + /** + * @return NegotiateSecurityFilter + */ + public NegotiateSecurityFilter getNegotiateSecurityFilter() { + + if (this.waffleNegotiateSecurityFilter == null) { + this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilterSSO(); + } + + this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); + return this.waffleNegotiateSecurityFilter; + } + + /** + * @return NegotiateSecurityFilter + */ + private NegotiateSecurityFilter waffleNegotiateSecurityFilter() { + + this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); + + return this.waffleNegotiateSecurityFilter; + } + + /* + * GETTERS and SETTERS + */ + + /** + * @return waffleWindowsAuthProvider + */ + public WindowsAuthenticationProvider getWaffleWindowsAuthProvider() { + + return this.waffleWindowsAuthProvider; + } + + /** + * @param waffleWindowsAuthProvider new value of waffleWindowsAuthProvider. + */ + public void setWaffleWindowsAuthProvider(WindowsAuthenticationProvider waffleWindowsAuthProvider) { + + this.waffleWindowsAuthProvider = waffleWindowsAuthProvider; + } + + /** + * @return negotiateSecurityFilterProvider + */ + public NegotiateSecurityFilterProvider getNegotiateSecurityFilterProvider() { + + return this.negotiateSecurityFilterProvider; + } + + /** + * @param negotiateSecurityFilterProvider new value of negotiateSecurityFilterProvider. + */ + public void setNegotiateSecurityFilterProvider(NegotiateSecurityFilterProvider negotiateSecurityFilterProvider) { + + this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider; + } + + /** + * @return waffleSecurityFilterProviderCollection + */ + public SecurityFilterProviderCollection getWaffleSecurityFilterProviderCollection() { + + return this.waffleSecurityFilterProviderCollection; + } + + /** + * @param waffleSecurityFilterProviderCollection new value of waffleSecurityFilterProviderCollection. + */ + public void setWaffleSecurityFilterProviderCollection( + SecurityFilterProviderCollection waffleSecurityFilterProviderCollection) { + + this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection; + } + + /** + * @return negotiateSecurityFilterEntryPoint + */ + public NegotiateSecurityFilterEntryPoint getNegotiateSecurityFilterEntryPoint() { + + return this.negotiateSecurityFilterEntryPoint; + } + + /** + * @param negotiateSecurityFilterEntryPoint new value of negotiateSecurityFilterEntryPoint. + */ + public void setNegotiateSecurityFilterEntryPoint( + NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint) { + + this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint; + } + + /** + * @return waffleNegotiateSecurityFilter + */ + public NegotiateSecurityFilter getWaffleNegotiateSecurityFilter() { + + return this.waffleNegotiateSecurityFilter; + } + + /** + * @param waffleNegotiateSecurityFilter new value of waffleNegotiateSecurityFilter. + */ + public void setWaffleNegotiateSecurityFilter(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { + + this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; + } + +} diff --git a/modules/winauth-sso/src/main/resources/application.properties b/modules/winauth-sso/src/main/resources/application.properties new file mode 100644 index 0000000..414b903 --- /dev/null +++ b/modules/winauth-sso/src/main/resources/application.properties @@ -0,0 +1,9 @@ +# --------------------------------------------------------------------------- +# Base values +# --------------------------------------------------------------------------- + + +# Activate spring profiles +#spring.profiles.active = integrationTest + +#Server configuration \ No newline at end of file diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java new file mode 100644 index 0000000..caf9f4f --- /dev/null +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java @@ -0,0 +1,39 @@ +package com.capgemini.devonfw.module.winauth.base; + +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.capgemini.devonfw.module.winauthsso.SpringBootApp; +import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationManagerAD; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.AuthenticationManagerImpl; + +import io.oasp.module.test.common.base.ComponentTest; + +/** + * This is the test-case for {@link AuthenticationManagerImpl}. + * + * @author jhcore + * @since 1.1 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringBootApp.class) +public class AuthenticationManagerImplTest extends ComponentTest { + @Inject + AuthenticationManagerAD authenticationManagerAD; + + /** + * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationManagerImpl} . + */ + @Test + public void testAuthenticationManagerImpl() { + + // given + assertThat(this.authenticationManagerAD).isNotNull(); + + } + +} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java new file mode 100644 index 0000000..02803d5 --- /dev/null +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java @@ -0,0 +1,57 @@ +package com.capgemini.devonfw.module.winauth.base; + +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.capgemini.devonfw.module.winauthsso.SpringBootApp; +import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.AuthenticationSourceADImpl; + +import io.oasp.module.test.common.base.ComponentTest; + +/** + * This is the test-case for {@link AuthenticationSourceADImpl}. + * + * @author jhcore + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringBootApp.class) +public class AuthenticationSourceADImplTest extends ComponentTest { + + @Inject + AuthenticationSource authenticationSource; + + /** + * Test method for + * {@link com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationSourceADImpl#searchUserByUsername(java.lang.String)} + * + */ + @Test + public void testSearchUserByUsername() { + + // Given + assertThat(this.authenticationSource).isNotNull(); + + // // When + // String searchValue = "jhcore"; + // + // // Then + // Attributes attributes = this.authenticationSource.searchUserByUsername(searchValue); + // + // assertThat(attributes).isNotNull(); + // + // String cn = attributes.get("cn").toString().substring(4);// Username + // String givenname = attributes.get("givenname").toString().substring(11); // FirstName + // String sn = attributes.get("sn").toString().substring(4);// LastName + // String memberOf = attributes.get("memberof").toString().substring(10); // Groups + // + // assertThat(cn).isEqualTo("jhcore"); + // assertThat(givenname).isEqualTo("Jhonatan Ariel"); + // assertThat(sn).isEqualTo("Core"); + // assertThat(memberOf).isNotNull(); + } +} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java new file mode 100644 index 0000000..b73af0b --- /dev/null +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java @@ -0,0 +1,76 @@ +package com.capgemini.devonfw.module.winauth.base; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.capgemini.devonfw.module.winauthsso.SpringBootApp; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.GroupMapperAD; + +import io.oasp.module.test.common.base.ComponentTest; + +/** + * This is the test-case for {@link GroupMapperAD} + * + * @author jhcore + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringBootApp.class) +public class GroupMapperADTest extends ComponentTest { + + @Inject + private GroupMapperAD groupMapperAD; + + /** + * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.GroupMapperAD}. + */ + @Test + public void testSetGroups() { + + // given + + assertThat(this.groupMapperAD).isNotNull(); + + // when + + HashMap> groups = this.groupMapperAD.getGroups(); + + // then + assertThat(groups).isNotNull(); + + assertThat(groups.containsKey("SESPLAN")).isTrue(); + assertThat(groups.containsKey("ECOMU7")).isTrue(); + assertThat(groups.containsKey("GradoA")).isTrue(); + assertThat(groups.containsKey("TESTGROUP")).isTrue(); + } + + /** + * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.GroupMapperAD}. + */ + @Test + public void testGroupsMapping() { + + String memberOf = + "CN=dlescapgemini.grado-a,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlesgrado-a.apps,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=SAS-Users-Iberia,OU=SAS Users,OU=SAS Groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=gpesapps-a-b-c,OU=DDA - Iberia,OU=Access groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlescapgemini.consultoria,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlescapgemini-v2,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlesvalencia,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlesapps,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=gpibportaliticsvisitors,OU=DDA - Iberia,OU=Access groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=S-ECOMU7,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=GRP-ES-USERS,OU=DDA - Iberia,OU=Access groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=S-ESPLAN,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com"; + + // When + ArrayList groups = this.groupMapperAD.groupsMapping(memberOf); + + // Given + assertThat(groups).isNotNull(); + + // Then + assertThat(groups.contains("SESPLAN")).isTrue(); + assertThat(groups.contains("ECOMU7")).isTrue(); + assertThat(groups.contains("GradoA")).isTrue(); + + assertThat(groups.contains("TESTGROUP")).isFalse();// It isn't mapped with memberOf + } + +} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java new file mode 100644 index 0000000..6fc28d9 --- /dev/null +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java @@ -0,0 +1,56 @@ +package com.capgemini.devonfw.module.winauth.base; + +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.capgemini.devonfw.module.winauthsso.SpringBootApp; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.UserDetailsContextMapperAD; + +import io.oasp.module.test.common.base.ComponentTest; + +/** + * This is the test-case for {@link UserDetailsContextMapperAD} + * + * @author jhcore + * @since 1.1 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringBootApp.class) +public class UserDetailsContextMapperADTest extends ComponentTest { + @Inject + private UserDetailsContextMapperAD userDetailsContextMapperAD; + + /** + * Test method for + * {@link com.capgemini.devonfw.module.winauth.common.impl.security.UserDetailsContextMapperAD#getAuthenticationSource()} + * . + */ + @Test + public void testGetAuthenticationSource() { + + // given + assertThat(this.userDetailsContextMapperAD).isNotNull(); + + // then + assertThat(this.userDetailsContextMapperAD.getAuthenticationSource()).isNotNull(); + } + + /** + * Test method for + * {@link com.capgemini.devonfw.module.winauth.common.impl.security.UserDetailsContextMapperAD#getGroupMapperAD()}. + */ + @Test + public void testGetGroupMapperAD() { + + // given + assertThat(this.userDetailsContextMapperAD).isNotNull(); + + // then + assertThat(this.userDetailsContextMapperAD.getGroupMapperAD()).isNotNull(); + } + +} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java new file mode 100644 index 0000000..8988f15 --- /dev/null +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java @@ -0,0 +1,66 @@ +package com.capgemini.devonfw.module.winauth.base; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.capgemini.devonfw.module.winauthsso.SpringBootApp; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.NegotiateSecurityFilterSSO; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.WinauthSSO_OLD; + +import io.oasp.module.test.common.base.ComponentTest; + +/** + * This is the test-case for {@link WinauthSSO_OLD}. + * + * @author jhcore + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringBootApp.class) + +public class WinauthSSOTest extends ComponentTest { + + private WinauthSSO_OLD ssoDefault = new WinauthSSO_OLD(); + + private WinauthSSO_OLD ssoAuthenticationCustomized = new WinauthSSO_OLD(new NegotiateSecurityFilterSSO()); + + /** + * + */ + @Test + public void testWinauthSSO() { + + assertThat(this.ssoDefault).isNotNull(); + assertThat(this.ssoAuthenticationCustomized).isNotNull(); + } + + /** + * + */ + @Test + public void testWinauthSSODefault() { + + assertThat(this.ssoDefault.getNegotiateSecurityFilter()).isNotNull(); + assertThat(this.ssoDefault.getNegotiateSecurityFilterEntryPoint()).isNotNull(); + assertThat(this.ssoDefault.getNegotiateSecurityFilterProvider()).isNotNull(); + assertThat(this.ssoDefault.getWaffleNegotiateSecurityFilter()).isNotNull(); + assertThat(this.ssoDefault.getWaffleSecurityFilterProviderCollection()).isNotNull(); + assertThat(this.ssoDefault.getWaffleWindowsAuthProvider()).isNotNull(); + } + + /** + * + */ + @Test + public void testWinauthSSOCustomized() { + + assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilter()).isNotNull(); + assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilterEntryPoint()).isNotNull(); + assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilterProvider()).isNotNull(); + assertThat(this.ssoAuthenticationCustomized.getWaffleNegotiateSecurityFilter()).isNotNull(); + assertThat(this.ssoAuthenticationCustomized.getWaffleSecurityFilterProviderCollection()).isNotNull(); + assertThat(this.ssoAuthenticationCustomized.getWaffleWindowsAuthProvider()).isNotNull(); + } + +} diff --git a/modules/winauth-sso/src/test/resources/application.properties b/modules/winauth-sso/src/test/resources/application.properties new file mode 100644 index 0000000..f862ff0 --- /dev/null +++ b/modules/winauth-sso/src/test/resources/application.properties @@ -0,0 +1,56 @@ +# --------------------------------------------------------------------------- +# Base values +# --------------------------------------------------------------------------- + +#Server configuration (LDAP-> Authentication - AD -> Query to Active Directory) + +##Virtual Machine +##LDAP +#devon.winauth.ldap.url=ldap://aguasdevalencia.es/DC=AGUASDEVALENCIA,DC=ES +#devon.winauth.ldap.password=Administrador +#devon.winauth.ldap.userDn=cn=manager,DC=AGUASDEVALENCIA,DC=ES +#devon.winauth.ldap.patterns=ou=Users +#devon.winauth.ldap.userSearchFilter=(sAMAccountName={0}) +#devon.winauth.ldap.userSearchBase= +# +##AD +#devon.winauth.ad.url=ldap://aguasdevalencia.es/DC=AGUASDEVALENCIA,DC=ES +#devon.winauth.ad.domain=aguasdevalencia.es +#devon.winauth.ad.username=Administrador +#devon.winauth.ad.password=Capgemini2016 +#devon.winauth.ad.userSearchFilter= +#devon.winauth.ad.userSearchBase=(uid={0}) +#devon.winauth.ad.searchBy=sAMAccountName +#devon.winauth.ad.rolePrefix=^(.*)CN=([^,]*),.*,DC=AGUASDEVALENCIA,DC=COM$ +# +##Devon Utils +##LDAP +#devon.winauth.ldap.url=ldap://devonUtils/DC=devon,DC=com +#devon.winauth.ldap.password=Capgemini2016 +#devon.winauth.ldap.userDn=cn=dirtelf,DC=devon,DC=com +#devon.winauth.ldap.patterns=ou=Users +#devon.winauth.ldap.userSearchFilter=(sAMAccountName={0}) +#devon.winauth.ldap.userSearchBase= +# +#Capgemini +##AD +#devon.winauth.ad.url=ldap://corp.capgemini.com/OU=ES,OU=Employees,DC=CORP,DC=CAPGEMINI,DC=COM +#devon.winauth.ad.domain=corp.capgemini.com +#devon.winauth.ad.username= +#devon.winauth.ad.password=ENC() +#devon.winauth.ad.userSearchFilter=(uid={0}) +#devon.winauth.ad.userSearchBase= +#devon.winauth.ad.searchBy=sAMAccountName +#devon.winauth.ad.rolePrefix=^(.*)CN=([^,]*),.*,DC=CORP,DC=CAPGEMINI,DC=COM$ + +#Roles mapping (Capgemini) +devon.winauth.groups.SESPLAN=S-ESPLAN +devon.winauth.groups.ECOMU7=S-ECOMU7 +devon.winauth.groups.GradoA=dlescapgemini.grado-a +devon.winauth.groups.TESTGROUP=testGroup + +#devon.winauth.ldap.keyPass=llave +#devon.winauth.ldap.password=ENC(lICZ8b3KOGZONH9m7+7/YgTrM3suZ1Ii) +# +#devon.winauth.ad.encrypt=false +#devon.winauth.ldap.encrypt=true From 03412dff01fd8054e31f0d0ee8be242ecf42aff3 Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Mon, 9 Jan 2017 15:58:48 +0100 Subject: [PATCH 2/9] Tests changed for winauth-sso with new Interface structure --- .../module/winauth/base/WinauthSSOTest.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java index 8988f15..a012050 100644 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java @@ -1,12 +1,17 @@ package com.capgemini.devonfw.module.winauth.base; +import javax.inject.Inject; + +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.capgemini.devonfw.module.winauthsso.SpringBootApp; +import com.capgemini.devonfw.module.winauthsso.common.api.WinauthSSO; import com.capgemini.devonfw.module.winauthsso.common.impl.security.NegotiateSecurityFilterSSO; +import com.capgemini.devonfw.module.winauthsso.common.impl.security.WinauthSSOImpl; import com.capgemini.devonfw.module.winauthsso.common.impl.security.WinauthSSO_OLD; import io.oasp.module.test.common.base.ComponentTest; @@ -21,9 +26,22 @@ public class WinauthSSOTest extends ComponentTest { - private WinauthSSO_OLD ssoDefault = new WinauthSSO_OLD(); + private WinauthSSOImpl ssoDefault = new WinauthSSOImpl(); + + private WinauthSSOImpl ssoAuthenticationCustomized = new WinauthSSOImpl(/* new NegotiateSecurityFilterSSO() */); + + @Inject + private WinauthSSO sso; - private WinauthSSO_OLD ssoAuthenticationCustomized = new WinauthSSO_OLD(new NegotiateSecurityFilterSSO()); + @Inject + private WinauthSSO ssoCustom; + + @Before + public void init() { + + this.ssoCustom.setCustomFilter(new NegotiateSecurityFilterSSO()); + this.ssoAuthenticationCustomized.setCustomFilter(new NegotiateSecurityFilterSSO()); + } /** * @@ -31,6 +49,8 @@ public class WinauthSSOTest extends ComponentTest { @Test public void testWinauthSSO() { + assertThat(this.sso).isNotNull(); + assertThat(this.ssoCustom).isNotNull(); assertThat(this.ssoDefault).isNotNull(); assertThat(this.ssoAuthenticationCustomized).isNotNull(); } @@ -41,8 +61,8 @@ public void testWinauthSSO() { @Test public void testWinauthSSODefault() { - assertThat(this.ssoDefault.getNegotiateSecurityFilter()).isNotNull(); - assertThat(this.ssoDefault.getNegotiateSecurityFilterEntryPoint()).isNotNull(); + assertThat(this.sso.getSSOFilter()).isNotNull(); + assertThat(this.sso.getSSOFilterEntryPoint()).isNotNull(); assertThat(this.ssoDefault.getNegotiateSecurityFilterProvider()).isNotNull(); assertThat(this.ssoDefault.getWaffleNegotiateSecurityFilter()).isNotNull(); assertThat(this.ssoDefault.getWaffleSecurityFilterProviderCollection()).isNotNull(); @@ -55,8 +75,8 @@ public void testWinauthSSODefault() { @Test public void testWinauthSSOCustomized() { - assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilter()).isNotNull(); - assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilterEntryPoint()).isNotNull(); + assertThat(this.ssoCustom.getSSOFilter()).isNotNull(); + assertThat(this.ssoCustom.getSSOFilterEntryPoint()).isNotNull(); assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilterProvider()).isNotNull(); assertThat(this.ssoAuthenticationCustomized.getWaffleNegotiateSecurityFilter()).isNotNull(); assertThat(this.ssoAuthenticationCustomized.getWaffleSecurityFilterProviderCollection()).isNotNull(); From ffb4c1ebde988954221a8c8bcc030a1dda82fc50 Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Mon, 9 Jan 2017 16:43:05 +0100 Subject: [PATCH 3/9] Removed AD implementation from Winauth-sso module --- .../common/api/AuthenticationManagerAD.java | 15 - .../common/api/AuthenticationSource.java | 96 ----- .../winauthsso/common/api/UserData.java | 30 +- .../api/accesscontrol/ActiveDirectory.java | 200 ---------- .../{UserDataAD.java => UserData.java} | 47 +-- .../common/api/to/UserDetailsClientToAD.java | 110 ------ .../security/AuthenticationManagerImpl.java | 298 --------------- .../security/AuthenticationSourceADImpl.java | 342 ------------------ .../common/impl/security/GroupMapperAD.java | 94 ----- .../security/NegotiateSecurityFilterSSO.java | 77 ++-- .../PrincipalAccessControlProviderImplAD.java | 33 -- .../security/UserDetailsContextMapperAD.java | 108 ------ .../common/impl/security/WinauthSSO_OLD.java | 219 ----------- .../base/AuthenticationManagerImplTest.java | 39 -- .../base/AuthenticationSourceADImplTest.java | 57 --- .../winauth/base/GroupMapperADTest.java | 76 ---- .../base/UserDetailsContextMapperADTest.java | 56 --- .../module/winauth/base/WinauthSSOTest.java | 1 - 18 files changed, 75 insertions(+), 1823 deletions(-) delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java rename modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/{UserDataAD.java => UserData.java} (68%) delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java delete mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java delete mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java delete mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java delete mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java delete mode 100644 modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java deleted file mode 100644 index 858f915..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationManagerAD.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.api; - -import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; - -/** - * This class contains the configuration to the Active Directory authentication - * - * @author jhcore - */ -public interface AuthenticationManagerAD { - /** - * @return the LDAP authentication provider - */ - public LdapAuthenticationProvider LdapAuthenticationProvider(); -} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java deleted file mode 100644 index 0864c3a..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/AuthenticationSource.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.api; - -import javax.naming.directory.Attributes; - -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer; - -/** - * This class contains the configuration of the Active Directory - * - * @author jhcore - */ -public interface AuthenticationSource { - - /** - * @return AD username - */ - public String getUsername(); - - /** - * @param username new value of AD username. - */ - public void setUsername(String username); - - /** - * @return AD password - */ - public String getPassword(); - - /** - * @param password new value of AD password. - */ - public void setPassword(String password); - - /** - * @return AD domain - */ - public String getDomain(); - - /** - * @param domain new value of AD getdomain. - */ - public void setDomain(String domain); - - /** - * @param username AD username - * @return The user AD attributes - */ - public Attributes searchUserByUsername(String username); - - /** - * @return userSearchFiler - */ - public String getUserSearchFilter(); - - /** - * @param userSearchFiler new value of userSearchFilter. - */ - public void setUserSearchFilter(String userSearchFiler); - - /** - * @return userSearchBase - */ - public String getUserSearchBase(); - - /** - * @param userSearchBase new value of userSearchBase. - */ - public void setUserSearchBase(String userSearchBase); - - /** - * @return groupsPrefix - */ - public String getRolePrefix(); - - /** - * @param groupsPrefix new value of groupsPrefix. - */ - public void setRolePrefix(String groupsPrefix); - - /** - * @return url - */ - public String getUrl(); - - /** - * @param url new value of url. - */ - public void setUrl(String url); - - /** - * @return the authentication LDAP provider - */ - public LdapAuthenticationProviderConfigurer getLdapAuthenticationProviderConfigurer(); - -} \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java index 25deac4..7c4d1f7 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java @@ -8,8 +8,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; -import com.capgemini.devonfw.module.winauthsso.common.api.to.UserDetailsClientToAD; - /** * Container class for the profile of a user. * @@ -72,20 +70,20 @@ public String getName() { return getUsername(); } - /** - * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link UserData} - * instance. - */ - public UserDetailsClientToAD toClientTo() { - - UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); - clientTo.setId(this.userProfile.getId()); - clientTo.setName(this.userProfile.getName()); - clientTo.setFirstName(this.userProfile.getFirstName()); - clientTo.setLastName(this.userProfile.getLastName()); - clientTo.setGroups((this.userProfile.getGroups())); - return clientTo; - } + // /** + // * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link UserData} + // * instance. + // */ + // public UserDetailsClientToAD toClientTo() { + // + // UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); + // clientTo.setId(this.userProfile.getId()); + // clientTo.setName(this.userProfile.getName()); + // clientTo.setFirstName(this.userProfile.getFirstName()); + // clientTo.setLastName(this.userProfile.getLastName()); + // clientTo.setGroups((this.userProfile.getGroups())); + // return clientTo; + // } @Override public String toString() { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java deleted file mode 100644 index b4ebb40..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/accesscontrol/ActiveDirectory.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.api.accesscontrol; - -import java.util.Properties; - -import javax.naming.Context; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; -import javax.naming.directory.DirContext; -import javax.naming.directory.InitialDirContext; -import javax.naming.directory.SearchControls; -import javax.naming.directory.SearchResult; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.core.userdetails.UsernameNotFoundException; - -/** - * This class contains the configuration to connect with Active Directory - * - * @author jhcore - */ -public class ActiveDirectory { - private static final Logger LOG = LoggerFactory.getLogger(ActiveDirectory.class); - - /** Properties of the DirContext {"@link javax.naming.directory.DirContext} **/ - public Properties properties; - - /** Context of the {@link ActiveDirectory} **/ - public DirContext dirContext; - - /** Encapsulates factors that determine scope of search **/ - public SearchControls searchCtls; - - /** Attributes of the query to ActiveDirectory **/ - public String[] returnAttributes = { "sAMAccountName", "givenName", "sn", "cn", "mail", "memberOf" }; - - /** Domain of the server of ActiveDirectory **/ - public String domainBase; - - /** **/ - public String baseFilter = "(&((&(objectCategory=Person)(objectClass=User)))"; - - /** - * constructor with parameter for initializing a LDAP context - * - * @param username a {@link java.lang.String} object - username com.capgemini.devonfw.module.winauth.common.api.to - * establish a LDAP connection - * @param password a {@link java.lang.String} object - password com.capgemini.devonfw.module.winauth.common.api.to - * establish a LDAP connection - * @param domainController a {@link java.lang.String} object - domain controller name for LDAP connection - */ - public ActiveDirectory(String username, String password, String domainController) { - this.properties = new Properties(); - - this.properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); - this.properties.put(Context.PROVIDER_URL, "LDAP://" + domainController); - this.properties.put(Context.SECURITY_PRINCIPAL, username + "@" + domainController); - this.properties.put(Context.SECURITY_CREDENTIALS, password); - - // initializing active directory LDAP connection - try { - this.dirContext = new InitialDirContext(this.properties); - } catch (NamingException e) { - LOG.error(e.getMessage()); - } - - // default domain base for search - this.domainBase = getDomainBase(domainController); - - // initializing search controls - this.searchCtls = new SearchControls(); - this.searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); - this.searchCtls.setReturningAttributes(this.returnAttributes); - } - - /** - * The constructor. - */ - public ActiveDirectory() { - super(); - } - - /** - * @param username -> AD username - * @param password -> AD password - * @param domainController -> AD domainController - */ - public void connect(String username, String password, String domainController) { - - this.properties = new Properties(); - - this.properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); - this.properties.put(Context.PROVIDER_URL, "LDAP://" + domainController); - this.properties.put(Context.SECURITY_PRINCIPAL, username + "@" + domainController); - this.properties.put(Context.SECURITY_CREDENTIALS, password); - this.properties.put(Context.REFERRAL, "follow"); - // initializing active directory LDAP connection - try { - this.dirContext = new InitialDirContext(this.properties); - } catch (NamingException e) { - LOG.error(e.getMessage()); - } - - // default domain base for search - this.domainBase = getDomainBase(domainController); - - // initializing search controls - this.searchCtls = new SearchControls(); - this.searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); - this.searchCtls.setReturningAttributes(this.returnAttributes); - } - - /** - * @param returnAttributes - */ - @SuppressWarnings("javadoc") - public void setAttributes(String[] returnAttributes) { - - this.searchCtls.setReturningAttributes(this.returnAttributes); - } - - /** - * search the Active directory by username/email id for given search base - * - * @param searchValue a {@link java.lang.String} object - search value used for AD search for eg. username or email - * @param searchBy a {@link java.lang.String} object - scope of search by username or by email id - * @param searchBase a {@link java.lang.String} object - search base value for scope tree - * @return search result a {@link javax.naming.NamingEnumeration} object - active directory search result - */ - @SuppressWarnings("unchecked") - public NamingEnumeration searchUser(String searchValue, String searchBy, String searchBase) { - - String filter = getFilter(searchValue, searchBy); - String base = (null == searchBase) ? this.domainBase : getDomainBase(searchBase); // for eg.: "DC=myjeeva,DC=com"; - @SuppressWarnings("rawtypes") - NamingEnumeration result; - try { - result = this.dirContext.search(base, filter, this.searchCtls); - return result; - } catch (NamingException e) { - e.printStackTrace(); - UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); - LOG.warn("Failed com.capgemini.devonfw.module.winauth.common.api.to get user {}." + searchValue + exception); - throw exception; - } catch (Exception e) { - e.printStackTrace(); - UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); - LOG.warn("Failed com.capgemini.devonfw.module.winauth.common.api.to get user {}." + searchValue + exception); - throw exception; - } - } - - /** - * closes the LDAP connection with Domain controller - */ - public void closeLdapConnection() { - - try { - if (this.dirContext != null) - this.dirContext.close(); - } catch (NamingException e) { - LOG.error(e.getMessage()); - } - } - - /** - * active directory filter string value - * - * @param searchValue a {@link java.lang.String} object - search value of username/email id for active directory - * @param searchBy a {@link java.lang.String} object - scope of search by username or email id - * @return a {@link java.lang.String} object - filter string - */ - private String getFilter(String searchValue, String searchBy) { - - String filter = this.baseFilter; - filter += "(" + searchBy + "=" + searchValue + "))"; - /* - * if (searchBy.equals("email")) { filter += "(mail=" + searchValue + "))"; } else if (searchBy.equals("username")) - * { filter += "(samaccountname=" + searchValue + "))"; } - */ - return filter; - } - - /** - * creating a domain base value from domain controller name - */ - private static String getDomainBase(String base) { - - char[] namePair = base.toUpperCase().toCharArray(); - String dn = "DC="; - for (int i = 0; i < namePair.length; i++) { - if (namePair[i] == '.') { - dn += ",DC=" + namePair[++i]; - } else { - dn += namePair[i]; - } - } - return dn; - } -} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserDataAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java similarity index 68% rename from modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserDataAD.java rename to modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java index 78ee28f..86445d4 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserDataAD.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java @@ -9,14 +9,14 @@ import org.springframework.security.core.userdetails.User; import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; -import com.capgemini.devonfw.module.winauthsso.common.api.to.UserDetailsClientToAD; +//import com.capgemini.devonfw.module.winauthsso.common.api.to.UserDetailsClientToAD; /** * Container class for the profile of a user. * * @author hohwille, jhcore */ -public class UserDataAD extends User implements Principal { +public class UserData extends User implements Principal { private static final long serialVersionUID = 1L; @@ -33,7 +33,7 @@ public class UserDataAD extends User implements Principal { * @param accountNonLocked check if user account is not locked * @param authorities the authorities/permissions the user has */ - public UserDataAD(String username, String password, boolean enabled, boolean accountNonExpired, + public UserData(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); @@ -46,7 +46,7 @@ public UserDataAD(String username, String password, boolean enabled, boolean acc * @param password sets the password * @param authorities the authorities/permissions the user has */ - public UserDataAD(String username, String password, Collection authorities) { + public UserData(String username, String password, Collection authorities) { super(username, password, authorities); } @@ -57,20 +57,21 @@ public String getName() { return getUsername(); } - /** - * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link UserDataAD} - * instance. - */ - public UserDetailsClientToAD toClientTo() { - - UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); - clientTo.setId(this.userProfile.getId()); - clientTo.setName(this.userProfile.getName()); - clientTo.setFirstName(this.userProfile.getFirstName()); - clientTo.setLastName(this.userProfile.getLastName()); - clientTo.setGroups(this.userProfile.getGroups()); - return clientTo; - } + // /** + // * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link + // UserDataAD} + // * instance. + // */ + // public UserDetailsClientToAD toClientTo() { + // + // UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); + // clientTo.setId(this.userProfile.getId()); + // clientTo.setName(this.userProfile.getName()); + // clientTo.setFirstName(this.userProfile.getFirstName()); + // clientTo.setLastName(this.userProfile.getLastName()); + // clientTo.setGroups(this.userProfile.getGroups()); + // return clientTo; + // } @Override public String toString() { @@ -95,9 +96,9 @@ public void setUserProfile(PrincipalProfile userProfile) { } /** - * @return the {@link UserDataAD} of the user currently logged in. + * @return the {@link UserData} of the user currently logged in. */ - public static UserDataAD get() { + public static UserData get() { return get(SecurityContextHolder.getContext().getAuthentication()); } @@ -105,9 +106,9 @@ public static UserDataAD get() { /** * @param authentication is the {@link Authentication} where com.capgemini.devonfw.module.winauth.common.api.to * retrieve the user from. - * @return the {@link UserDataAD} of the logged in user from the given {@link Authentication}. + * @return the {@link UserData} of the logged in user from the given {@link Authentication}. */ - public static UserDataAD get(Authentication authentication) { + public static UserData get(Authentication authentication) { if (authentication == null) { throw new IllegalStateException("Authentication not available!"); @@ -117,7 +118,7 @@ public static UserDataAD get(Authentication authentication) { throw new IllegalStateException("Principal not available!"); } try { - return (UserDataAD) principal; + return (UserData) principal; } catch (ClassCastException e) { throw new IllegalStateException("Principal (" + principal + ") is not an instance of UserDataAD!", e); } diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java deleted file mode 100644 index 65ec395..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/to/UserDetailsClientToAD.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.api.to; - -import java.util.List; - -import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; - -import io.oasp.module.basic.common.api.to.AbstractTo; - -/** - * This is the {@link AbstractTo TO} for the client view on the user AD details. - * - * @author hohwille, jhcore - */ -public class UserDetailsClientToAD extends AbstractTo implements PrincipalProfile { - - /** UID for serialization. */ - private static final long serialVersionUID = 1L; - - private String id; - - private String name; - - private String firstName; - - private String lastName; - - private List groups; - - /** - * The constructor. - */ - public UserDetailsClientToAD() { - - super(); - } - - @Override - public String getId() { - - return this.id; - } - - @Override - public String getName() { - - return this.name; - } - - @Override - public String getFirstName() { - - return this.firstName; - } - - @Override - public String getLastName() { - - return this.lastName; - } - - @Override - public List getGroups() { - - return this.groups; - } - - /** - * Sets the ID. - * - * @param id the ID com.capgemini.devonfw.module.winauth.common.api.to set - */ - public void setId(String id) { - - this.id = id; - } - - /** - * @param name the name com.capgemini.devonfw.module.winauth.common.api.to set - */ - public void setName(String name) { - - this.name = name; - } - - /** - * @param firstName the firstName com.capgemini.devonfw.module.winauth.common.api.to set - */ - public void setFirstName(String firstName) { - - this.firstName = firstName; - } - - /** - * @param lastName the lastName com.capgemini.devonfw.module.winauth.common.api.to set - */ - public void setLastName(String lastName) { - - this.lastName = lastName; - } - - /** - * @param groups of the AD user - */ - public void setGroups(List groups) { - - this.groups = groups; - - } - -} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java deleted file mode 100644 index c4bd322..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationManagerImpl.java +++ /dev/null @@ -1,298 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.impl.security; - -import java.util.Properties; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; -import org.jasypt.properties.EncryptableProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.ldap.DefaultSpringSecurityContextSource; -import org.springframework.security.ldap.authentication.BindAuthenticator; -import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; -import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; -import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; - -import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationManagerAD; - -/** - * Implementation of {@link AuthenticationManagerAD} - * - * @author jhcore - */ -@Named -@Configuration -@ConfigurationProperties(prefix = "devon.winauth.ldap") -public class AuthenticationManagerImpl implements AuthenticationManagerAD { - - /** - * Password of the server authentication - */ - private String password; - - /** - * Server domain - */ - private String url = "ldap://domain.com"; - - private String userSearchFilter = "(uid={0})"; - - private String userSearchBase = ""; - - private String userDn = ""; - - private String keyPass; - - private StandardPBEStringEncryptor encryptor; - - private boolean encrypt = false; - - /** - * @return encryptor - */ - public StandardPBEStringEncryptor getEncryptor() { - - return this.encryptor; - } - - /** - * @param encryptor new value of encryptor. - */ - public void setEncryptor(StandardPBEStringEncryptor encryptor) { - - this.encryptor = encryptor; - } - - /** - * @return encrypt - */ - public boolean isEncrypt() { - - return this.encrypt; - } - - /** - * @param encrypt new value of encrypt. - */ - public void setEncrypt(boolean encrypt) { - - this.encrypt = encrypt; - } - - /** - * @return userDn - */ - public String getUserDn() { - - return this.userDn; - } - - /** - * @param userDn new value of userDn. - */ - public void setUserDn(String userDn) { - - this.userDn = userDn; - } - - @Inject - private UserDetailsContextMapper userDetailsContextMapper; - - private String[] patterns = {}; - - /** - * @return patterns - */ - public String[] getPatterns() { - - return this.patterns; - } - - /** - * @param patterns new value of patterns. - */ - public void setPatterns(String[] patterns) { - - this.patterns = patterns; - } - - @Override - @Bean - public LdapAuthenticationProvider LdapAuthenticationProvider() { - - LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(BindAuthenticator()); - ldapAuthenticationProvider.setUserDetailsContextMapper(this.userDetailsContextMapper); - return ldapAuthenticationProvider; - } - - /** - * @return userDetailsContextMapper - */ - @Bean - public UserDetailsContextMapper getUserDetailsContextMapper() { - - if (this.userDetailsContextMapper != null) - return this.userDetailsContextMapper; - else - return new UserDetailsContextMapperAD(); - } - - /** - * @param userDetailsContextMapper new value of userDetailsContextMapper. - */ - - public void setUserDetailsContextMapper(UserDetailsContextMapper userDetailsContextMapper) { - - this.userDetailsContextMapper = userDetailsContextMapper; - } - - // @Bean - // public UserDetailsContextMapper UserDetailsContextMapper() { - // - // return new UserDetailsContextMapperAD(); - // } - - /** - * The class BindAuthenticator in the package {@link org.springframework.security.ldap.authentication} implements the - * bind authentication strategy. It simply attempts to bind as the user. - * - * @return the bind authentication strategy - */ - @Bean - public BindAuthenticator BindAuthenticator() { - - BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource()); - bindAuthenticator.setUserSearch(userSearch()); - bindAuthenticator.setUserDnPatterns(this.patterns); - return bindAuthenticator; - - } - - /** - * ContextSource implementation which uses Spring LDAP's LdapContextSource as a base class. Used internally by the - * Spring Security LDAP namespace configuration. - * - * @return the LdapContextSource - */ - @Bean - public DefaultSpringSecurityContextSource contextSource() { - - String pass = this.password; - - if (this.encrypt) { - this.encryptor = new StandardPBEStringEncryptor(); - this.encryptor.setPassword(this.keyPass); - - Properties props = new EncryptableProperties(this.encryptor); - props.setProperty("password", this.password); - pass = props.getProperty("password"); - } - - DefaultSpringSecurityContextSource defaultSpringSecurityContextSource = - new DefaultSpringSecurityContextSource(this.url); - defaultSpringSecurityContextSource.setUserDn(this.userDn); - defaultSpringSecurityContextSource.setPassword(pass); - return defaultSpringSecurityContextSource; - } - - /** - * @return keyPass - */ - public String getKeyPass() { - - return this.keyPass; - } - - /** - * @param keyPass new value of keyPass. - */ - public void setKeyPass(String keyPass) { - - this.keyPass = keyPass; - } - - /** - * LdapUserSearch implementation which uses an Ldap filter to locate the user. - * - * @return the LdapUserSearch - */ - @Bean - public FilterBasedLdapUserSearch userSearch() { - - FilterBasedLdapUserSearch filterBasedLdapUserSearch = - new FilterBasedLdapUserSearch(this.userSearchBase, this.userSearchFilter, contextSource()); - return filterBasedLdapUserSearch; - } - - /** - * @return password - */ - public String getPassword() { - - return this.password; - } - - /** - * @param password new value of password. - */ - public void setPassword(String password) { - - this.password = password; - } - - /** - * @return domain - */ - - /** - * @return userSearchFilter - */ - public String getUserSearchFilter() { - - return this.userSearchFilter; - } - - /** - * @return url - */ - public String getUrl() { - - return this.url; - } - - /** - * @param url new value of url. - */ - public void setUrl(String url) { - - this.url = url; - } - - /** - * @param userSearchFilter new value of userSearchFilter. - */ - public void setUserSearchFilter(String userSearchFilter) { - - this.userSearchFilter = userSearchFilter; - } - - /** - * @return userSearchBase - */ - public String getUserSearchBase() { - - return this.userSearchBase; - } - - /** - * @param userSearchBase new value of userSearchBase. - */ - public void setUserSearchBase(String userSearchBase) { - - this.userSearchBase = userSearchBase; - } - -} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java deleted file mode 100644 index 0102f6e..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/AuthenticationSourceADImpl.java +++ /dev/null @@ -1,342 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.impl.security; - -import java.util.Properties; - -import javax.inject.Named; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; -import javax.naming.directory.Attributes; -import javax.naming.directory.SearchResult; - -import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; -import org.jasypt.properties.EncryptableProperties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer; -import org.springframework.security.core.userdetails.UsernameNotFoundException; - -import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; -import com.capgemini.devonfw.module.winauthsso.common.api.accesscontrol.ActiveDirectory; - -/** - * Implementation of {@link AuthenticationSource} - * - * @author jhcore - */ -@ConfigurationProperties(prefix = "devon.winauth.ad") -@Named -public class AuthenticationSourceADImpl implements AuthenticationSource { - - private static final Logger LOG = LoggerFactory.getLogger(AuthenticationSourceADImpl.class); - - /** - * Instance of the ActiveDirectory class. We need it to do the query. - */ - private ActiveDirectory activeDirectory; - - /** - * User name of the server authentication - */ - private String username = ""; - - /** - * Password of the server authentication - */ - private String password; - - /** - * Server domain - */ - private String domain = ""; - - private String userSearchFilter = "(uid={0})"; - - private String userSearchBase = ""; - - private String searchBy = ""; - - private String rolePrefix = ""; - - private String url = ""; - - private StandardPBEStringEncryptor encryptor; - - private String keyPass; - - private boolean encrypt = false; - - /** - * @return searchBy - */ - public String getSearchBy() { - - return this.searchBy; - } - - /** - * @param searchBy new value of searchBy. - */ - public void setSearchBy(String searchBy) { - - this.searchBy = searchBy; - } - - /** - * The constructor. - */ - public AuthenticationSourceADImpl() { - super(); - this.activeDirectory = new ActiveDirectory(); - if (this.searchBy == null || this.searchBy.equals("")) { - this.searchBy = "samaccountname"; - } - - } - - @Override - public LdapAuthenticationProviderConfigurer getLdapAuthenticationProviderConfigurer() { - - LdapAuthenticationProviderConfigurer ldap = - new LdapAuthenticationProviderConfigurer<>(); - - String pass = this.password; - - if (this.encrypt) { - this.encryptor = new StandardPBEStringEncryptor(); - this.encryptor.setPassword(this.keyPass); - - Properties props = new EncryptableProperties(this.encryptor); - props.setProperty("password", this.password); - pass = props.getProperty("password"); - } - - ldap.userSearchBase(this.userSearchBase).userSearchFilter(this.userSearchFilter).rolePrefix(this.rolePrefix) - .contextSource().managerDn(this.username).managerPassword(pass).url(this.url); - - return ldap; - }; - - /** - * @return keyPass - */ - public String getKeyPass() { - - return this.keyPass; - } - - /** - * @param keyPass new value of keyPass. - */ - public void setKeyPass(String keyPass) { - - this.keyPass = keyPass; - } - - /** - * @return encrypt - */ - public boolean isEncrypt() { - - return this.encrypt; - } - - /** - * @param encrypt new value of encrypt. - */ - public void setEncrypt(boolean encrypt) { - - this.encrypt = encrypt; - } - - /** - * The constructor. - * - * @param username - * @param password - * @param domain - */ - @SuppressWarnings("javadoc") - public AuthenticationSourceADImpl(String username, String password, String domain) { - super(); - } - - /** - * @param searchValue -> the value of the user name we are searching - * @return attributes of the user - */ - @Override - public Attributes searchUserByUsername(String searchValue) { - - NamingEnumeration result; - try { - String pass = this.password; - if (this.encrypt) { - this.encryptor = new StandardPBEStringEncryptor(); - this.encryptor.setPassword(this.keyPass); - - Properties props = new EncryptableProperties(this.encryptor); - props.setProperty("password", this.password); - pass = props.getProperty("password"); - } - this.activeDirectory.connect(this.username, pass, this.domain); - - result = this.activeDirectory.searchUser(searchValue, this.searchBy, this.domain); - } finally { - this.activeDirectory.closeLdapConnection(); - } - // (&((&(objectCategory=Person)(objectClass=User)))(samaccountname=Servidor Web)) - try { - Attributes attrs = result.next().getAttributes(); - return attrs; - } catch (NamingException e) { - e.printStackTrace(); - UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); - LOG.error("Failed to get user {}.", this.username, exception); - throw exception; - } - } - - /** - * @return activeDirectory - */ - public ActiveDirectory getActiveDirectory() { - - return this.activeDirectory; - } - - /** - * @param activeDirectory new value of {@link ActiveDirectory}. - */ - public void setActiveDirectory(ActiveDirectory activeDirectory) { - - this.activeDirectory = activeDirectory; - } - - /** - * @return username - */ - @Override - public String getUsername() { - - return this.username; - } - - /** - * @param username new value of username. - */ - @Override - public void setUsername(String username) { - - this.username = username; - } - - /** - * @return password - */ - @Override - public String getPassword() { - - return this.password; - } - - /** - * @param password new value of password. - */ - @Override - public void setPassword(String password) { - - this.password = password; - } - - /** - * @return domain - */ - @Override - public String getDomain() { - - return this.domain; - } - - /** - * @param domain new value of domain. - */ - @Override - public void setDomain(String domain) { - - this.domain = domain; - } - - /** - * @return userSearchFilter - */ - @Override - public String getUserSearchFilter() { - - return this.userSearchFilter; - } - - /** - * @param userSearchFiler new value of userSearchFilter. - */ - @Override - public void setUserSearchFilter(String userSearchFiler) { - - this.userSearchFilter = userSearchFiler; - } - - /** - * @return userSearchBase - */ - @Override - public String getUserSearchBase() { - - return this.userSearchBase; - } - - /** - * @param userSearchBase new value of userSearchBase. - */ - @Override - public void setUserSearchBase(String userSearchBase) { - - this.userSearchBase = userSearchBase; - } - - /** - * @return rolePrefix - */ - @Override - public String getRolePrefix() { - - return this.rolePrefix; - } - - /** - * @param rolePrefix new value of rolePrefix. - */ - @Override - public void setRolePrefix(String rolePrefix) { - - this.rolePrefix = rolePrefix; - } - - /** - * @return url - */ - @Override - public String getUrl() { - - return this.url; - } - - /** - * @param url new value of url. - */ - @Override - public void setUrl(String url) { - - this.url = url; - } -} \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java deleted file mode 100644 index 00851d1..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/GroupMapperAD.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.impl.security; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.inject.Named; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * This class contains the methods to map the AD groups to Application groups. - * - * @author jhcore - */ -@ConfigurationProperties(prefix = "devon.winauth") -@Named("GroupMapperAD") -public class GroupMapperAD { - - /** - * The constructor. - */ - public GroupMapperAD() { - super(); - this.groups = new HashMap<>(); - } - - /** - * - */ - public HashMap> groups; - - /** - * @return groups - */ - public HashMap> getGroups() { - - return this.groups; - } - - /** - * @param groups new value of the user groups. - */ - public void setGroups(HashMap> groups) { - - this.groups = groups; - } - - /** - * @param memberOf chair with the AD groups - * @return an ArrayList with the the mapping groups - */ - public ArrayList groupsMapping(String memberOf) { - - ArrayList result = new ArrayList<>(); - - // Search the CN groups of memberOf - Pattern p = Pattern.compile("CN=[A-Za-z0-9-\\--\\.]*"); - Matcher m = p.matcher(memberOf); - - ArrayList groupsAD = new ArrayList<>(); - - // Delete the substring "CN=" - while (m.find()) { - groupsAD.add(m.group().substring(3)); - } - - // Mapping the groupsAD to groups - for (int i = 0; i < groupsAD.size(); i++) { - if (this.groups.values().toString().contains(groupsAD.get(i))) { - result.add(getKeysByValue(groupsAD.get(i))); - } - } - - return result; - } - - private String getKeysByValue(String value) { - - String result = null; - - for (Entry> e : this.groups.entrySet()) { - for (int i = 0; i < e.getValue().size(); i++) - if (e.getValue().get(i).equals(value)) { - result = e.getKey(); - break; - } - } - return result; - } - -} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java index e87a135..722550f 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java @@ -1,13 +1,10 @@ package com.capgemini.devonfw.module.winauthsso.common.impl.security; -import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.security.core.Authentication; -import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; - import waffle.servlet.spi.SecurityFilterProviderCollection; import waffle.spring.NegotiateSecurityFilter; @@ -36,43 +33,43 @@ public void setProvider(SecurityFilterProviderCollection securityFilterProviderC super.setProvider(securityFilterProviderCollection); } - private AuthenticationSource authenticationSource; - - private GroupMapperAD groupMapperAD; - - /** - * @return authenticationSource - */ - public AuthenticationSource getAuthenticationSource() { - - return this.authenticationSource; - } - - /** - * @param authenticationSource new value of authenticationSource. - */ - @Inject - public void setAuthenticationSource(AuthenticationSource authenticationSource) { - - this.authenticationSource = authenticationSource; - } - - /** - * @return groupMapperAD - */ - public GroupMapperAD getGroupMapperAD() { - - return this.groupMapperAD; - } - - /** - * @param groupMapperAD new value of groupMapperAD. - */ - @Inject - public void setGroupMapperAD(GroupMapperAD groupMapperAD) { - - this.groupMapperAD = groupMapperAD; - } + // private AuthenticationSource authenticationSource; + // + // private GroupMapperAD groupMapperAD; + // + // /** + // * @return authenticationSource + // */ + // public AuthenticationSource getAuthenticationSource() { + // + // return this.authenticationSource; + // } + // + // /** + // * @param authenticationSource new value of authenticationSource. + // */ + // @Inject + // public void setAuthenticationSource(AuthenticationSource authenticationSource) { + // + // this.authenticationSource = authenticationSource; + // } + // + // /** + // * @return groupMapperAD + // */ + // public GroupMapperAD getGroupMapperAD() { + // + // return this.groupMapperAD; + // } + // + // /** + // * @param groupMapperAD new value of groupMapperAD. + // */ + // @Inject + // public void setGroupMapperAD(GroupMapperAD groupMapperAD) { + // + // this.groupMapperAD = groupMapperAD; + // } @Override protected boolean setAuthentication(final HttpServletRequest request, final HttpServletResponse response, diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java deleted file mode 100644 index d274a60..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/PrincipalAccessControlProviderImplAD.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.impl.security; - -import java.util.Collection; - -import javax.inject.Named; - -import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; - -import io.oasp.module.security.common.api.accesscontrol.PrincipalAccessControlProvider; - -/** - * Implementation of PrincipalAccessControlProvider - * - * @author jhcore - */ -@Named -public class PrincipalAccessControlProviderImplAD implements PrincipalAccessControlProvider { - - /** - * The constructor. - */ - public PrincipalAccessControlProviderImplAD() { - - super(); - } - - @Override - public Collection getAccessControlIds(PrincipalProfile principal) { - - return principal.getGroups(); - } - -} \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java deleted file mode 100644 index 9019be6..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/UserDetailsContextMapperAD.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.impl.security; - -import java.util.ArrayList; -import java.util.Collection; - -import javax.inject.Inject; -import javax.naming.directory.Attributes; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.ldap.core.DirContextAdapter; -import org.springframework.ldap.core.DirContextOperations; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; - -import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; -import com.capgemini.devonfw.module.winauthsso.common.api.UserData; -import com.capgemini.devonfw.module.winauthsso.common.impl.security.AuthenticationManagerImpl; - -/** - * Implementation of {@link UserDetailsContextMapper} - * - * @author jhcore - */ -// @Named("UserDetailsContextMapperAD") -public class UserDetailsContextMapperAD implements UserDetailsContextMapper { - - private static final Logger LOG = LoggerFactory.getLogger(AuthenticationManagerImpl.class); - - @Inject - private AuthenticationSource authenticationSource; - - @Inject - private GroupMapperAD groupMapperAD; - - /** - * @return authenticationSource - */ - public AuthenticationSource getAuthenticationSource() { - - return this.authenticationSource; - } - - /** - * @param authenticationSource new value of authenticationSource. - */ - public void setAuthenticationSource(AuthenticationSource authenticationSource) { - - this.authenticationSource = authenticationSource; - } - - /** - * @return groupMapperAD - */ - public GroupMapperAD getGroupMapperAD() { - - return this.groupMapperAD; - } - - /** - * @param groupMapperAD new value of groupMapperAD. - */ - public void setGroupMapperAD(GroupMapperAD groupMapperAD) { - - this.groupMapperAD = groupMapperAD; - } - - @Override - public UserDetails mapUserFromContext(DirContextOperations ctx, String username, - Collection authorities) { - - UserData user = new UserData(username, "", authorities); - - try { - Attributes attributes = this.authenticationSource.searchUserByUsername(username); - - String cn = attributes.get("cn").toString().substring(4);// Username - String givenname = attributes.get("givenname").toString().substring(11); // FirstName - String sn = attributes.get("sn").toString().substring(4);// LastName - String memberOf = attributes.get("memberof").toString().substring(10); // Groups - - PrincipalProfileImpl userProfile = new PrincipalProfileImpl(); - userProfile.setName(cn); - userProfile.setFirstName(givenname); - userProfile.setLastName(sn); - userProfile.setId(cn); - ArrayList groups = this.groupMapperAD.groupsMapping(memberOf); - - userProfile.setGroups(groups); - - user.setUserProfile(userProfile); - } catch (Exception e) { - e.printStackTrace(); - UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e); - LOG.warn("Failed com.capgemini.devonfw.module.winauth.common.impl.security get user {} in Active Directory." - + username + exception); - throw exception; - } - return user; - } - - @Override - public void mapUserToContext(UserDetails user, DirContextAdapter ctx) { - - } -} diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java deleted file mode 100644 index ab7057d..0000000 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSO_OLD.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.capgemini.devonfw.module.winauthsso.common.impl.security; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Named; - -import waffle.servlet.spi.NegotiateSecurityFilterProvider; -import waffle.servlet.spi.SecurityFilterProvider; -import waffle.servlet.spi.SecurityFilterProviderCollection; -import waffle.spring.NegotiateSecurityFilter; -import waffle.spring.NegotiateSecurityFilterEntryPoint; -import waffle.spring.WindowsAuthenticationProvider; -import waffle.windows.auth.impl.WindowsAuthProviderImpl; - -/** - * This class initialize all Waffle Single Sign On configuration. - * - * @author jhcore - */ -@Named -public class WinauthSSO_OLD { - - private WindowsAuthenticationProvider waffleWindowsAuthProvider; - - private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider; - - private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection; - - private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint; - - private NegotiateSecurityFilter waffleNegotiateSecurityFilter; - - /** - * The constructor. - */ - public WinauthSSO_OLD() { - this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilter(); - init(); - } - - /** - * The constructor with arguments. - * - * @param waffleNegotiateSecurityFilter contains the authentication customized - */ - public WinauthSSO_OLD(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { - this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; - init(); - } - - /** - * Initialize the variables of the class - */ - public void init() { - - this.waffleWindowsAuthProvider = waffleWindowsAuthProvider(); - - this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider(); - - this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection(); - - this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint(); - - this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter(); - } - - /** - * @return the WindowsAuthProvider - */ - private WindowsAuthenticationProvider waffleWindowsAuthProvider() { - - WindowsAuthenticationProvider windowsAuthenticationProvider = new WindowsAuthenticationProvider(); - windowsAuthenticationProvider.setAuthProvider(new WindowsAuthProviderImpl()); - return windowsAuthenticationProvider; - } - - /** - * @return negotiateSecurityFilterProvider - */ - private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider() { - - return new NegotiateSecurityFilterProvider(this.waffleWindowsAuthProvider.getAuthProvider()); - } - - /** - * @return SecurityFilterProviderCollection - */ - private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection() { - - final List securityFilterProviders = new ArrayList<>(); - - securityFilterProviders.add(this.negotiateSecurityFilterProvider); - - return new SecurityFilterProviderCollection(securityFilterProviders.toArray(new SecurityFilterProvider[] {})); - } - - /** - * @return NegotiateSecurityFilterEntryPoint - */ - private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint() { - - this.negotiateSecurityFilterEntryPoint = new NegotiateSecurityFilterEntryPoint(); - - this.negotiateSecurityFilterEntryPoint.setProvider(this.waffleSecurityFilterProviderCollection); - - return this.negotiateSecurityFilterEntryPoint; - } - - /** - * @return NegotiateSecurityFilter - */ - public NegotiateSecurityFilter getNegotiateSecurityFilter() { - - if (this.waffleNegotiateSecurityFilter == null) { - this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilterSSO(); - } - - this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); - return this.waffleNegotiateSecurityFilter; - } - - /** - * @return NegotiateSecurityFilter - */ - private NegotiateSecurityFilter waffleNegotiateSecurityFilter() { - - this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); - - return this.waffleNegotiateSecurityFilter; - } - - /* - * GETTERS and SETTERS - */ - - /** - * @return waffleWindowsAuthProvider - */ - public WindowsAuthenticationProvider getWaffleWindowsAuthProvider() { - - return this.waffleWindowsAuthProvider; - } - - /** - * @param waffleWindowsAuthProvider new value of waffleWindowsAuthProvider. - */ - public void setWaffleWindowsAuthProvider(WindowsAuthenticationProvider waffleWindowsAuthProvider) { - - this.waffleWindowsAuthProvider = waffleWindowsAuthProvider; - } - - /** - * @return negotiateSecurityFilterProvider - */ - public NegotiateSecurityFilterProvider getNegotiateSecurityFilterProvider() { - - return this.negotiateSecurityFilterProvider; - } - - /** - * @param negotiateSecurityFilterProvider new value of negotiateSecurityFilterProvider. - */ - public void setNegotiateSecurityFilterProvider(NegotiateSecurityFilterProvider negotiateSecurityFilterProvider) { - - this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider; - } - - /** - * @return waffleSecurityFilterProviderCollection - */ - public SecurityFilterProviderCollection getWaffleSecurityFilterProviderCollection() { - - return this.waffleSecurityFilterProviderCollection; - } - - /** - * @param waffleSecurityFilterProviderCollection new value of waffleSecurityFilterProviderCollection. - */ - public void setWaffleSecurityFilterProviderCollection( - SecurityFilterProviderCollection waffleSecurityFilterProviderCollection) { - - this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection; - } - - /** - * @return negotiateSecurityFilterEntryPoint - */ - public NegotiateSecurityFilterEntryPoint getNegotiateSecurityFilterEntryPoint() { - - return this.negotiateSecurityFilterEntryPoint; - } - - /** - * @param negotiateSecurityFilterEntryPoint new value of negotiateSecurityFilterEntryPoint. - */ - public void setNegotiateSecurityFilterEntryPoint( - NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint) { - - this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint; - } - - /** - * @return waffleNegotiateSecurityFilter - */ - public NegotiateSecurityFilter getWaffleNegotiateSecurityFilter() { - - return this.waffleNegotiateSecurityFilter; - } - - /** - * @param waffleNegotiateSecurityFilter new value of waffleNegotiateSecurityFilter. - */ - public void setWaffleNegotiateSecurityFilter(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { - - this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; - } - -} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java deleted file mode 100644 index caf9f4f..0000000 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.capgemini.devonfw.module.winauth.base; - -import javax.inject.Inject; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.capgemini.devonfw.module.winauthsso.SpringBootApp; -import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationManagerAD; -import com.capgemini.devonfw.module.winauthsso.common.impl.security.AuthenticationManagerImpl; - -import io.oasp.module.test.common.base.ComponentTest; - -/** - * This is the test-case for {@link AuthenticationManagerImpl}. - * - * @author jhcore - * @since 1.1 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SpringBootApp.class) -public class AuthenticationManagerImplTest extends ComponentTest { - @Inject - AuthenticationManagerAD authenticationManagerAD; - - /** - * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationManagerImpl} . - */ - @Test - public void testAuthenticationManagerImpl() { - - // given - assertThat(this.authenticationManagerAD).isNotNull(); - - } - -} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java deleted file mode 100644 index 02803d5..0000000 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.capgemini.devonfw.module.winauth.base; - -import javax.inject.Inject; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.capgemini.devonfw.module.winauthsso.SpringBootApp; -import com.capgemini.devonfw.module.winauthsso.common.api.AuthenticationSource; -import com.capgemini.devonfw.module.winauthsso.common.impl.security.AuthenticationSourceADImpl; - -import io.oasp.module.test.common.base.ComponentTest; - -/** - * This is the test-case for {@link AuthenticationSourceADImpl}. - * - * @author jhcore - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SpringBootApp.class) -public class AuthenticationSourceADImplTest extends ComponentTest { - - @Inject - AuthenticationSource authenticationSource; - - /** - * Test method for - * {@link com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationSourceADImpl#searchUserByUsername(java.lang.String)} - * - */ - @Test - public void testSearchUserByUsername() { - - // Given - assertThat(this.authenticationSource).isNotNull(); - - // // When - // String searchValue = "jhcore"; - // - // // Then - // Attributes attributes = this.authenticationSource.searchUserByUsername(searchValue); - // - // assertThat(attributes).isNotNull(); - // - // String cn = attributes.get("cn").toString().substring(4);// Username - // String givenname = attributes.get("givenname").toString().substring(11); // FirstName - // String sn = attributes.get("sn").toString().substring(4);// LastName - // String memberOf = attributes.get("memberof").toString().substring(10); // Groups - // - // assertThat(cn).isEqualTo("jhcore"); - // assertThat(givenname).isEqualTo("Jhonatan Ariel"); - // assertThat(sn).isEqualTo("Core"); - // assertThat(memberOf).isNotNull(); - } -} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java deleted file mode 100644 index b73af0b..0000000 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.capgemini.devonfw.module.winauth.base; - -import java.util.ArrayList; -import java.util.HashMap; - -import javax.inject.Inject; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.capgemini.devonfw.module.winauthsso.SpringBootApp; -import com.capgemini.devonfw.module.winauthsso.common.impl.security.GroupMapperAD; - -import io.oasp.module.test.common.base.ComponentTest; - -/** - * This is the test-case for {@link GroupMapperAD} - * - * @author jhcore - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SpringBootApp.class) -public class GroupMapperADTest extends ComponentTest { - - @Inject - private GroupMapperAD groupMapperAD; - - /** - * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.GroupMapperAD}. - */ - @Test - public void testSetGroups() { - - // given - - assertThat(this.groupMapperAD).isNotNull(); - - // when - - HashMap> groups = this.groupMapperAD.getGroups(); - - // then - assertThat(groups).isNotNull(); - - assertThat(groups.containsKey("SESPLAN")).isTrue(); - assertThat(groups.containsKey("ECOMU7")).isTrue(); - assertThat(groups.containsKey("GradoA")).isTrue(); - assertThat(groups.containsKey("TESTGROUP")).isTrue(); - } - - /** - * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.GroupMapperAD}. - */ - @Test - public void testGroupsMapping() { - - String memberOf = - "CN=dlescapgemini.grado-a,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlesgrado-a.apps,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=SAS-Users-Iberia,OU=SAS Users,OU=SAS Groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=gpesapps-a-b-c,OU=DDA - Iberia,OU=Access groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlescapgemini.consultoria,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlescapgemini-v2,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlesvalencia,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=dlesapps,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=gpibportaliticsvisitors,OU=DDA - Iberia,OU=Access groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=S-ECOMU7,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=GRP-ES-USERS,OU=DDA - Iberia,OU=Access groups,OU=Groups,OU=Resources,DC=corp,DC=capgemini,DC=com, CN=S-ESPLAN,OU=DDA - Iberia,OU=Distribution lists,OU=Resources,DC=corp,DC=capgemini,DC=com"; - - // When - ArrayList groups = this.groupMapperAD.groupsMapping(memberOf); - - // Given - assertThat(groups).isNotNull(); - - // Then - assertThat(groups.contains("SESPLAN")).isTrue(); - assertThat(groups.contains("ECOMU7")).isTrue(); - assertThat(groups.contains("GradoA")).isTrue(); - - assertThat(groups.contains("TESTGROUP")).isFalse();// It isn't mapped with memberOf - } - -} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java deleted file mode 100644 index 6fc28d9..0000000 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.capgemini.devonfw.module.winauth.base; - -import javax.inject.Inject; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.capgemini.devonfw.module.winauthsso.SpringBootApp; -import com.capgemini.devonfw.module.winauthsso.common.impl.security.UserDetailsContextMapperAD; - -import io.oasp.module.test.common.base.ComponentTest; - -/** - * This is the test-case for {@link UserDetailsContextMapperAD} - * - * @author jhcore - * @since 1.1 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SpringBootApp.class) -public class UserDetailsContextMapperADTest extends ComponentTest { - @Inject - private UserDetailsContextMapperAD userDetailsContextMapperAD; - - /** - * Test method for - * {@link com.capgemini.devonfw.module.winauth.common.impl.security.UserDetailsContextMapperAD#getAuthenticationSource()} - * . - */ - @Test - public void testGetAuthenticationSource() { - - // given - assertThat(this.userDetailsContextMapperAD).isNotNull(); - - // then - assertThat(this.userDetailsContextMapperAD.getAuthenticationSource()).isNotNull(); - } - - /** - * Test method for - * {@link com.capgemini.devonfw.module.winauth.common.impl.security.UserDetailsContextMapperAD#getGroupMapperAD()}. - */ - @Test - public void testGetGroupMapperAD() { - - // given - assertThat(this.userDetailsContextMapperAD).isNotNull(); - - // then - assertThat(this.userDetailsContextMapperAD.getGroupMapperAD()).isNotNull(); - } - -} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java index a012050..0f9d460 100644 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java @@ -12,7 +12,6 @@ import com.capgemini.devonfw.module.winauthsso.common.api.WinauthSSO; import com.capgemini.devonfw.module.winauthsso.common.impl.security.NegotiateSecurityFilterSSO; import com.capgemini.devonfw.module.winauthsso.common.impl.security.WinauthSSOImpl; -import com.capgemini.devonfw.module.winauthsso.common.impl.security.WinauthSSO_OLD; import io.oasp.module.test.common.base.ComponentTest; From 21504f816064c73ea9a895c9d710864ac604a06b Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Mon, 9 Jan 2017 16:54:49 +0100 Subject: [PATCH 4/9] Removed AD dependencies from Winauth-sso module --- modules/winauth-sso/pom.xml | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/modules/winauth-sso/pom.xml b/modules/winauth-sso/pom.xml index ba021be..a33c1cf 100644 --- a/modules/winauth-sso/pom.xml +++ b/modules/winauth-sso/pom.xml @@ -26,38 +26,6 @@ provided - - - org.jasypt - jasypt - compile - - - - - - org.springframework.security - spring-security-ldap - - - org.apache.directory.server - apacheds-server-jndi - - - - org.springframework.security.kerberos - spring-security-kerberos-core - - - org.springframework.security.kerberos - spring-security-kerberos-web - - - org.springframework.security.kerberos - spring-security-kerberos-client - - - org.hibernate @@ -125,10 +93,5 @@ oasp4j-beanmapping - - - - - From ab25aa4c3a5da9b430652508d1f67b9746852f12 Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Mon, 9 Jan 2017 17:26:50 +0100 Subject: [PATCH 5/9] Changed structure of the AD module from 'winauth' to 'winauth-ad' --- modules/pom.xml | 2 +- .../AuthenticationManagerImplTest.java | 0 modules/{winauth => winauth-ad}/pom.xml | 2 +- .../module/winauthad}/SpringBootApp.java | 2 +- .../common/api/AuthenticationManagerAD.java | 2 +- .../common/api/AuthenticationSource.java | 2 +- .../common/api/PrincipalProfile.java | 2 +- .../winauthad}/common/api/UserData.java | 4 +- .../winauthad}/common/api/Usermanagement.java | 2 +- .../api/accesscontrol/ActiveDirectory.java | 2 +- .../common/api/security/UserDataAD.java | 6 +-- .../common/api/to/UserDetailsClientToAD.java | 4 +- .../security/AuthenticationManagerImpl.java | 4 +- .../security/AuthenticationSourceADImpl.java | 6 +-- .../common/impl/security/GroupMapperAD.java | 2 +- .../security/NegotiateSecurityFilterSSO.java | 4 +- .../PrincipalAccessControlProviderImplAD.java | 6 +-- .../impl/security/PrincipalProfileImpl.java | 4 +- .../security/UserDetailsContextMapperAD.java | 6 +-- .../common/impl/security/WinauthSSO.java | 2 +- .../src/main/resources/application.properties | 0 .../base/AuthenticationManagerImplTest.java | 39 +++++++++++++++++++ .../base/AuthenticationSourceADImplTest.java | 8 ++-- .../winauthad}/base/GroupMapperADTest.java | 6 +-- .../base/UserDetailsContextMapperADTest.java | 6 +-- .../winauthad}/base/WinauthSSOTest.java | 8 ++-- .../src/test/resources/application.properties | 0 modules/winauth/.gitignore | 19 --------- 28 files changed, 85 insertions(+), 65 deletions(-) rename modules/{winauth/src/test/java/com/capgemini/devonfw/module/winauth/base => winauth-ad}/AuthenticationManagerImplTest.java (100%) rename modules/{winauth => winauth-ad}/pom.xml (98%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/SpringBootApp.java (90%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/AuthenticationManagerAD.java (86%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/AuthenticationSource.java (97%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/PrincipalProfile.java (93%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/UserData.java (96%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/Usermanagement.java (85%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/accesscontrol/ActiveDirectory.java (98%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/security/UserDataAD.java (94%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/api/to/UserDetailsClientToAD.java (92%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/AuthenticationManagerImpl.java (97%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/AuthenticationSourceADImpl.java (96%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/GroupMapperAD.java (96%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/NegotiateSecurityFilterSSO.java (93%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/PrincipalAccessControlProviderImplAD.java (79%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/PrincipalProfileImpl.java (92%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/UserDetailsContextMapperAD.java (93%) rename modules/{winauth/src/main/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad}/common/impl/security/WinauthSSO.java (98%) rename modules/{winauth => winauth-ad}/src/main/resources/application.properties (100%) create mode 100644 modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java rename modules/{winauth/src/test/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad}/base/AuthenticationSourceADImplTest.java (85%) rename modules/{winauth/src/test/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad}/base/GroupMapperADTest.java (93%) rename modules/{winauth/src/test/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad}/base/UserDetailsContextMapperADTest.java (87%) rename modules/{winauth/src/test/java/com/capgemini/devonfw/module/winauth => winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad}/base/WinauthSSOTest.java (87%) rename modules/{winauth => winauth-ad}/src/test/resources/application.properties (100%) delete mode 100644 modules/winauth/.gitignore diff --git a/modules/pom.xml b/modules/pom.xml index 4db23fd..474f9a4 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -17,7 +17,7 @@ foo reporting i18n - winauth + winauth-ad winauth-sso async diff --git a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java b/modules/winauth-ad/AuthenticationManagerImplTest.java similarity index 100% rename from modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationManagerImplTest.java rename to modules/winauth-ad/AuthenticationManagerImplTest.java diff --git a/modules/winauth/pom.xml b/modules/winauth-ad/pom.xml similarity index 98% rename from modules/winauth/pom.xml rename to modules/winauth-ad/pom.xml index 23cce86..83c8826 100644 --- a/modules/winauth/pom.xml +++ b/modules/winauth-ad/pom.xml @@ -7,7 +7,7 @@ dev-SNAPSHOT com.capgemini.devonfw.modules - devonfw-winauth + devonfw-winauth-ad ${devonfw.version} ${project.artifactId} Active Directory base authentication. diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/SpringBootApp.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java similarity index 90% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/SpringBootApp.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java index d13c3cb..c053cb5 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/SpringBootApp.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth; +package com.capgemini.devonfw.module.winauthad; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/AuthenticationManagerAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/AuthenticationManagerAD.java similarity index 86% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/AuthenticationManagerAD.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/AuthenticationManagerAD.java index bf9589f..ca8886f 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/AuthenticationManagerAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/AuthenticationManagerAD.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.api; +package com.capgemini.devonfw.module.winauthad.common.api; import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/AuthenticationSource.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/AuthenticationSource.java similarity index 97% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/AuthenticationSource.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/AuthenticationSource.java index d22f210..b275cb4 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/AuthenticationSource.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/AuthenticationSource.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.api; +package com.capgemini.devonfw.module.winauthad.common.api; import javax.naming.directory.Attributes; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/PrincipalProfile.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/PrincipalProfile.java similarity index 93% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/PrincipalProfile.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/PrincipalProfile.java index 4d1b43e..a2461ad 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/PrincipalProfile.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/PrincipalProfile.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.api; +package com.capgemini.devonfw.module.winauthad.common.api; import java.security.Principal; import java.util.List; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/UserData.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/UserData.java similarity index 96% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/UserData.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/UserData.java index c0bae2f..a043452 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/UserData.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/UserData.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.api; +package com.capgemini.devonfw.module.winauthad.common.api; import java.security.Principal; import java.util.Collection; @@ -8,7 +8,7 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; -import com.capgemini.devonfw.module.winauth.common.api.to.UserDetailsClientToAD; +import com.capgemini.devonfw.module.winauthad.common.api.to.UserDetailsClientToAD; /** * Container class for the profile of a user. diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/Usermanagement.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/Usermanagement.java similarity index 85% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/Usermanagement.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/Usermanagement.java index 3deaef9..b2533c1 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/Usermanagement.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/Usermanagement.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.api; +package com.capgemini.devonfw.module.winauthad.common.api; /** * Interface to get a user from its login. diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/accesscontrol/ActiveDirectory.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java similarity index 98% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/accesscontrol/ActiveDirectory.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java index 23498d2..71eeb7a 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/accesscontrol/ActiveDirectory.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.api.accesscontrol; +package com.capgemini.devonfw.module.winauthad.common.api.accesscontrol; import java.util.Properties; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/security/UserDataAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/security/UserDataAD.java similarity index 94% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/security/UserDataAD.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/security/UserDataAD.java index c685223..b2b9295 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/security/UserDataAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/security/UserDataAD.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.api.security; +package com.capgemini.devonfw.module.winauthad.common.api.security; import java.security.Principal; import java.util.Collection; @@ -8,8 +8,8 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; -import com.capgemini.devonfw.module.winauth.common.api.PrincipalProfile; -import com.capgemini.devonfw.module.winauth.common.api.to.UserDetailsClientToAD; +import com.capgemini.devonfw.module.winauthad.common.api.PrincipalProfile; +import com.capgemini.devonfw.module.winauthad.common.api.to.UserDetailsClientToAD; /** * Container class for the profile of a user. diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/to/UserDetailsClientToAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/to/UserDetailsClientToAD.java similarity index 92% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/to/UserDetailsClientToAD.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/to/UserDetailsClientToAD.java index 0c8269c..d3d878e 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/api/to/UserDetailsClientToAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/to/UserDetailsClientToAD.java @@ -1,8 +1,8 @@ -package com.capgemini.devonfw.module.winauth.common.api.to; +package com.capgemini.devonfw.module.winauthad.common.api.to; import java.util.List; -import com.capgemini.devonfw.module.winauth.common.api.PrincipalProfile; +import com.capgemini.devonfw.module.winauthad.common.api.PrincipalProfile; import io.oasp.module.basic.common.api.to.AbstractTo; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/AuthenticationManagerImpl.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java similarity index 97% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/AuthenticationManagerImpl.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java index 9e8cc68..8534d6e 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/AuthenticationManagerImpl.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import java.util.Properties; @@ -16,7 +16,7 @@ import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; -import com.capgemini.devonfw.module.winauth.common.api.AuthenticationManagerAD; +import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationManagerAD; /** * Implementation of {@link AuthenticationManagerAD} diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/AuthenticationSourceADImpl.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java similarity index 96% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/AuthenticationSourceADImpl.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java index 6b1ddc4..b2ef4fe 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/AuthenticationSourceADImpl.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import java.util.Properties; @@ -17,8 +17,8 @@ import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import com.capgemini.devonfw.module.winauth.common.api.AuthenticationSource; -import com.capgemini.devonfw.module.winauth.common.api.accesscontrol.ActiveDirectory; +import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationSource; +import com.capgemini.devonfw.module.winauthad.common.api.accesscontrol.ActiveDirectory; /** * Implementation of {@link AuthenticationSource} diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/GroupMapperAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/GroupMapperAD.java similarity index 96% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/GroupMapperAD.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/GroupMapperAD.java index 8c078f5..f5d23cf 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/GroupMapperAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/GroupMapperAD.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import java.util.ArrayList; import java.util.HashMap; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/NegotiateSecurityFilterSSO.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/NegotiateSecurityFilterSSO.java similarity index 93% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/NegotiateSecurityFilterSSO.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/NegotiateSecurityFilterSSO.java index 7e61ed2..225a86e 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/NegotiateSecurityFilterSSO.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/NegotiateSecurityFilterSSO.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; @@ -6,7 +6,7 @@ import org.springframework.security.core.Authentication; -import com.capgemini.devonfw.module.winauth.common.api.AuthenticationSource; +import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationSource; import waffle.servlet.spi.SecurityFilterProviderCollection; import waffle.spring.NegotiateSecurityFilter; diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/PrincipalAccessControlProviderImplAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/PrincipalAccessControlProviderImplAD.java similarity index 79% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/PrincipalAccessControlProviderImplAD.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/PrincipalAccessControlProviderImplAD.java index 7346ca2..f2ecf82 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/PrincipalAccessControlProviderImplAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/PrincipalAccessControlProviderImplAD.java @@ -1,16 +1,16 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import java.util.Collection; import javax.inject.Named; -import com.capgemini.devonfw.module.winauth.common.api.PrincipalProfile; +import com.capgemini.devonfw.module.winauthad.common.api.PrincipalProfile; import io.oasp.module.security.common.api.accesscontrol.PrincipalAccessControlProvider; /** * Implementation of PrincipalAccessControlProvider - * + * * @author jhcore */ @Named diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/PrincipalProfileImpl.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/PrincipalProfileImpl.java similarity index 92% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/PrincipalProfileImpl.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/PrincipalProfileImpl.java index adfcfcd..e5204a9 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/PrincipalProfileImpl.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/PrincipalProfileImpl.java @@ -1,9 +1,9 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import java.util.List; import java.util.Locale; -import com.capgemini.devonfw.module.winauth.common.api.PrincipalProfile; +import com.capgemini.devonfw.module.winauthad.common.api.PrincipalProfile; /** * Implementation of {@link PrincipalProfile}. diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/UserDetailsContextMapperAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java similarity index 93% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/UserDetailsContextMapperAD.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java index 050262e..ba34c8c 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/UserDetailsContextMapperAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import java.util.ArrayList; import java.util.Collection; @@ -15,8 +15,8 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; -import com.capgemini.devonfw.module.winauth.common.api.AuthenticationSource; -import com.capgemini.devonfw.module.winauth.common.api.UserData; +import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationSource; +import com.capgemini.devonfw.module.winauthad.common.api.UserData; /** * Implementation of {@link UserDetailsContextMapper} diff --git a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/WinauthSSO.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/WinauthSSO.java similarity index 98% rename from modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/WinauthSSO.java rename to modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/WinauthSSO.java index daeda13..03032c8 100644 --- a/modules/winauth/src/main/java/com/capgemini/devonfw/module/winauth/common/impl/security/WinauthSSO.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/WinauthSSO.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.common.impl.security; +package com.capgemini.devonfw.module.winauthad.common.impl.security; import java.util.ArrayList; import java.util.List; diff --git a/modules/winauth/src/main/resources/application.properties b/modules/winauth-ad/src/main/resources/application.properties similarity index 100% rename from modules/winauth/src/main/resources/application.properties rename to modules/winauth-ad/src/main/resources/application.properties diff --git a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java new file mode 100644 index 0000000..dc4ce1b --- /dev/null +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java @@ -0,0 +1,39 @@ +package com.capgemini.devonfw.module.winauthad.base; + +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.capgemini.devonfw.module.winauthad.SpringBootApp; +import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationManagerAD; +import com.capgemini.devonfw.module.winauthad.common.impl.security.AuthenticationManagerImpl; + +import io.oasp.module.test.common.base.ComponentTest; + +/** + * This is the test-case for {@link AuthenticationManagerImpl}. + * + * @author jhcore + * @since 1.1 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringBootApp.class) +public class AuthenticationManagerImplTest extends ComponentTest { + @Inject + AuthenticationManagerAD authenticationManagerAD; + + /** + * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationManagerImpl} . + */ + @Test + public void testAuthenticationManagerImpl() { + + // given + assertThat(this.authenticationManagerAD).isNotNull(); + + } + +} diff --git a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationSourceADImplTest.java similarity index 85% rename from modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java rename to modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationSourceADImplTest.java index 45a8da7..23958b2 100644 --- a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/AuthenticationSourceADImplTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationSourceADImplTest.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.base; +package com.capgemini.devonfw.module.winauthad.base; import javax.inject.Inject; @@ -7,9 +7,9 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauth.SpringBootApp; -import com.capgemini.devonfw.module.winauth.common.api.AuthenticationSource; -import com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationSourceADImpl; +import com.capgemini.devonfw.module.winauthad.SpringBootApp; +import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationSource; +import com.capgemini.devonfw.module.winauthad.common.impl.security.AuthenticationSourceADImpl; import io.oasp.module.test.common.base.ComponentTest; diff --git a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/GroupMapperADTest.java similarity index 93% rename from modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java rename to modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/GroupMapperADTest.java index d34ba03..8f6a025 100644 --- a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/GroupMapperADTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/GroupMapperADTest.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.base; +package com.capgemini.devonfw.module.winauthad.base; import java.util.ArrayList; import java.util.HashMap; @@ -10,8 +10,8 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauth.SpringBootApp; -import com.capgemini.devonfw.module.winauth.common.impl.security.GroupMapperAD; +import com.capgemini.devonfw.module.winauthad.SpringBootApp; +import com.capgemini.devonfw.module.winauthad.common.impl.security.GroupMapperAD; import io.oasp.module.test.common.base.ComponentTest; diff --git a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/UserDetailsContextMapperADTest.java similarity index 87% rename from modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java rename to modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/UserDetailsContextMapperADTest.java index 24fa1c8..cb5c3e4 100644 --- a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/UserDetailsContextMapperADTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/UserDetailsContextMapperADTest.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.base; +package com.capgemini.devonfw.module.winauthad.base; import javax.inject.Inject; @@ -7,8 +7,8 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauth.SpringBootApp; -import com.capgemini.devonfw.module.winauth.common.impl.security.UserDetailsContextMapperAD; +import com.capgemini.devonfw.module.winauthad.SpringBootApp; +import com.capgemini.devonfw.module.winauthad.common.impl.security.UserDetailsContextMapperAD; import io.oasp.module.test.common.base.ComponentTest; diff --git a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/WinauthSSOTest.java similarity index 87% rename from modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java rename to modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/WinauthSSOTest.java index 862d06e..b90afe6 100644 --- a/modules/winauth/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/WinauthSSOTest.java @@ -1,13 +1,13 @@ -package com.capgemini.devonfw.module.winauth.base; +package com.capgemini.devonfw.module.winauthad.base; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauth.SpringBootApp; -import com.capgemini.devonfw.module.winauth.common.impl.security.NegotiateSecurityFilterSSO; -import com.capgemini.devonfw.module.winauth.common.impl.security.WinauthSSO; +import com.capgemini.devonfw.module.winauthad.SpringBootApp; +import com.capgemini.devonfw.module.winauthad.common.impl.security.NegotiateSecurityFilterSSO; +import com.capgemini.devonfw.module.winauthad.common.impl.security.WinauthSSO; import io.oasp.module.test.common.base.ComponentTest; diff --git a/modules/winauth/src/test/resources/application.properties b/modules/winauth-ad/src/test/resources/application.properties similarity index 100% rename from modules/winauth/src/test/resources/application.properties rename to modules/winauth-ad/src/test/resources/application.properties diff --git a/modules/winauth/.gitignore b/modules/winauth/.gitignore deleted file mode 100644 index d2295d8..0000000 --- a/modules/winauth/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -*.class -*.classpath -*.project -*.iml -.* -target/ -jsclient/ -bin/ -eclipse-target/ -**/src/generated/ -**/tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* From e3f60c635c99f9aa23ea4555a4e6dc9210705118 Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Tue, 10 Jan 2017 09:06:08 +0100 Subject: [PATCH 6/9] Removed Single sign-on implementation from new module winauth-ad --- .../AuthenticationManagerImplTest.java | 39 ---- modules/winauth-ad/pom.xml | 6 - .../security/NegotiateSecurityFilterSSO.java | 84 ------- .../common/impl/security/WinauthSSO.java | 219 ------------------ .../module/winauthad/base/WinauthSSOTest.java | 66 ------ .../base/WinauthSSOTest.java | 2 +- 6 files changed, 1 insertion(+), 415 deletions(-) delete mode 100644 modules/winauth-ad/AuthenticationManagerImplTest.java delete mode 100644 modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/NegotiateSecurityFilterSSO.java delete mode 100644 modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/WinauthSSO.java delete mode 100644 modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/WinauthSSOTest.java rename modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/{winauth => winauthsso}/base/WinauthSSOTest.java (98%) diff --git a/modules/winauth-ad/AuthenticationManagerImplTest.java b/modules/winauth-ad/AuthenticationManagerImplTest.java deleted file mode 100644 index ddcb378..0000000 --- a/modules/winauth-ad/AuthenticationManagerImplTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.capgemini.devonfw.module.winauth.base; - -import javax.inject.Inject; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.capgemini.devonfw.module.winauth.SpringBootApp; -import com.capgemini.devonfw.module.winauth.common.api.AuthenticationManagerAD; -import com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationManagerImpl; - -import io.oasp.module.test.common.base.ComponentTest; - -/** - * This is the test-case for {@link AuthenticationManagerImpl}. - * - * @author jhcore - * @since 1.1 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SpringBootApp.class) -public class AuthenticationManagerImplTest extends ComponentTest { - @Inject - AuthenticationManagerAD authenticationManagerAD; - - /** - * Test method for {@link com.capgemini.devonfw.module.winauth.common.impl.security.AuthenticationManagerImpl} . - */ - @Test - public void testAuthenticationManagerImpl() { - - // given - assertThat(this.authenticationManagerAD).isNotNull(); - - } - -} diff --git a/modules/winauth-ad/pom.xml b/modules/winauth-ad/pom.xml index 83c8826..399390f 100644 --- a/modules/winauth-ad/pom.xml +++ b/modules/winauth-ad/pom.xml @@ -13,12 +13,6 @@ Active Directory base authentication. - - - com.github.dblock.waffle - waffle-spring-security3 - - javax.servlet diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/NegotiateSecurityFilterSSO.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/NegotiateSecurityFilterSSO.java deleted file mode 100644 index 225a86e..0000000 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/NegotiateSecurityFilterSSO.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.capgemini.devonfw.module.winauthad.common.impl.security; - -import javax.inject.Inject; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.core.Authentication; - -import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationSource; - -import waffle.servlet.spi.SecurityFilterProviderCollection; -import waffle.spring.NegotiateSecurityFilter; - -/** - * This is a dummy implementation of NegotiateSecurityFilterSSO. The functionality is the same of the class - * NegotiateSecurityFilter. Is created to inject the bean of the class WinauthSSO in the case of we don't want to - * implement our own Filter and build the UserDetails. - * - * In a case we want to implement a new UserDetail, we can implement NegotiateSecurityFilterSSO and build a User in the - * method boolean setAuthentication(HttpServletRequest, HttpServletResponse, Authentication). - * - * @author jhcore - */ -public class NegotiateSecurityFilterSSO extends NegotiateSecurityFilter { - - /** - * The constructor. - */ - public NegotiateSecurityFilterSSO() { - super(); - } - - @Override - public void setProvider(SecurityFilterProviderCollection securityFilterProviderCollection) { - - super.setProvider(securityFilterProviderCollection); - } - - private AuthenticationSource authenticationSource; - - private GroupMapperAD groupMapperAD; - - /** - * @return authenticationSource - */ - public AuthenticationSource getAuthenticationSource() { - - return this.authenticationSource; - } - - /** - * @param authenticationSource new value of authenticationSource. - */ - @Inject - public void setAuthenticationSource(AuthenticationSource authenticationSource) { - - this.authenticationSource = authenticationSource; - } - - /** - * @return groupMapperAD - */ - public GroupMapperAD getGroupMapperAD() { - - return this.groupMapperAD; - } - - /** - * @param groupMapperAD new value of groupMapperAD. - */ - @Inject - public void setGroupMapperAD(GroupMapperAD groupMapperAD) { - - this.groupMapperAD = groupMapperAD; - } - - @Override - protected boolean setAuthentication(final HttpServletRequest request, final HttpServletResponse response, - final Authentication authentication) { - - return super.setAuthentication(request, response, authentication); - } - -} diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/WinauthSSO.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/WinauthSSO.java deleted file mode 100644 index 03032c8..0000000 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/WinauthSSO.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.capgemini.devonfw.module.winauthad.common.impl.security; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Named; - -import waffle.servlet.spi.NegotiateSecurityFilterProvider; -import waffle.servlet.spi.SecurityFilterProvider; -import waffle.servlet.spi.SecurityFilterProviderCollection; -import waffle.spring.NegotiateSecurityFilter; -import waffle.spring.NegotiateSecurityFilterEntryPoint; -import waffle.spring.WindowsAuthenticationProvider; -import waffle.windows.auth.impl.WindowsAuthProviderImpl; - -/** - * This class initialize all Waffle Single Sign On configuration. - * - * @author jhcore - */ -@Named -public class WinauthSSO { - - private WindowsAuthenticationProvider waffleWindowsAuthProvider; - - private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider; - - private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection; - - private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint; - - private NegotiateSecurityFilter waffleNegotiateSecurityFilter; - - /** - * The constructor. - */ - public WinauthSSO() { - this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilter(); - init(); - } - - /** - * The constructor with arguments. - * - * @param waffleNegotiateSecurityFilter contains the authentication customized - */ - public WinauthSSO(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { - this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; - init(); - } - - /** - * Initialize the variables of the class - */ - public void init() { - - this.waffleWindowsAuthProvider = waffleWindowsAuthProvider(); - - this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider(); - - this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection(); - - this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint(); - - this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter(); - } - - /** - * @return the WindowsAuthProvider - */ - private WindowsAuthenticationProvider waffleWindowsAuthProvider() { - - WindowsAuthenticationProvider windowsAuthenticationProvider = new WindowsAuthenticationProvider(); - windowsAuthenticationProvider.setAuthProvider(new WindowsAuthProviderImpl()); - return windowsAuthenticationProvider; - } - - /** - * @return negotiateSecurityFilterProvider - */ - private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider() { - - return new NegotiateSecurityFilterProvider(this.waffleWindowsAuthProvider.getAuthProvider()); - } - - /** - * @return SecurityFilterProviderCollection - */ - private SecurityFilterProviderCollection waffleSecurityFilterProviderCollection() { - - final List securityFilterProviders = new ArrayList<>(); - - securityFilterProviders.add(this.negotiateSecurityFilterProvider); - - return new SecurityFilterProviderCollection(securityFilterProviders.toArray(new SecurityFilterProvider[] {})); - } - - /** - * @return NegotiateSecurityFilterEntryPoint - */ - private NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint() { - - this.negotiateSecurityFilterEntryPoint = new NegotiateSecurityFilterEntryPoint(); - - this.negotiateSecurityFilterEntryPoint.setProvider(this.waffleSecurityFilterProviderCollection); - - return this.negotiateSecurityFilterEntryPoint; - } - - /** - * @return NegotiateSecurityFilter - */ - public NegotiateSecurityFilter getNegotiateSecurityFilter() { - - if (this.waffleNegotiateSecurityFilter == null) { - this.waffleNegotiateSecurityFilter = new NegotiateSecurityFilterSSO(); - } - - this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); - return this.waffleNegotiateSecurityFilter; - } - - /** - * @return NegotiateSecurityFilter - */ - private NegotiateSecurityFilter waffleNegotiateSecurityFilter() { - - this.waffleNegotiateSecurityFilter.setProvider(this.waffleSecurityFilterProviderCollection); - - return this.waffleNegotiateSecurityFilter; - } - - /* - * GETTERS and SETTERS - */ - - /** - * @return waffleWindowsAuthProvider - */ - public WindowsAuthenticationProvider getWaffleWindowsAuthProvider() { - - return this.waffleWindowsAuthProvider; - } - - /** - * @param waffleWindowsAuthProvider new value of waffleWindowsAuthProvider. - */ - public void setWaffleWindowsAuthProvider(WindowsAuthenticationProvider waffleWindowsAuthProvider) { - - this.waffleWindowsAuthProvider = waffleWindowsAuthProvider; - } - - /** - * @return negotiateSecurityFilterProvider - */ - public NegotiateSecurityFilterProvider getNegotiateSecurityFilterProvider() { - - return this.negotiateSecurityFilterProvider; - } - - /** - * @param negotiateSecurityFilterProvider new value of negotiateSecurityFilterProvider. - */ - public void setNegotiateSecurityFilterProvider(NegotiateSecurityFilterProvider negotiateSecurityFilterProvider) { - - this.negotiateSecurityFilterProvider = negotiateSecurityFilterProvider; - } - - /** - * @return waffleSecurityFilterProviderCollection - */ - public SecurityFilterProviderCollection getWaffleSecurityFilterProviderCollection() { - - return this.waffleSecurityFilterProviderCollection; - } - - /** - * @param waffleSecurityFilterProviderCollection new value of waffleSecurityFilterProviderCollection. - */ - public void setWaffleSecurityFilterProviderCollection( - SecurityFilterProviderCollection waffleSecurityFilterProviderCollection) { - - this.waffleSecurityFilterProviderCollection = waffleSecurityFilterProviderCollection; - } - - /** - * @return negotiateSecurityFilterEntryPoint - */ - public NegotiateSecurityFilterEntryPoint getNegotiateSecurityFilterEntryPoint() { - - return this.negotiateSecurityFilterEntryPoint; - } - - /** - * @param negotiateSecurityFilterEntryPoint new value of negotiateSecurityFilterEntryPoint. - */ - public void setNegotiateSecurityFilterEntryPoint( - NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint) { - - this.negotiateSecurityFilterEntryPoint = negotiateSecurityFilterEntryPoint; - } - - /** - * @return waffleNegotiateSecurityFilter - */ - public NegotiateSecurityFilter getWaffleNegotiateSecurityFilter() { - - return this.waffleNegotiateSecurityFilter; - } - - /** - * @param waffleNegotiateSecurityFilter new value of waffleNegotiateSecurityFilter. - */ - public void setWaffleNegotiateSecurityFilter(NegotiateSecurityFilter waffleNegotiateSecurityFilter) { - - this.waffleNegotiateSecurityFilter = waffleNegotiateSecurityFilter; - } - -} diff --git a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/WinauthSSOTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/WinauthSSOTest.java deleted file mode 100644 index b90afe6..0000000 --- a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/WinauthSSOTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.capgemini.devonfw.module.winauthad.base; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.capgemini.devonfw.module.winauthad.SpringBootApp; -import com.capgemini.devonfw.module.winauthad.common.impl.security.NegotiateSecurityFilterSSO; -import com.capgemini.devonfw.module.winauthad.common.impl.security.WinauthSSO; - -import io.oasp.module.test.common.base.ComponentTest; - -/** - * This is the test-case for {@link WinauthSSO}. - * - * @author jhcore - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SpringBootApp.class) - -public class WinauthSSOTest extends ComponentTest { - - private WinauthSSO ssoDefault = new WinauthSSO(); - - private WinauthSSO ssoAuthenticationCustomized = new WinauthSSO(new NegotiateSecurityFilterSSO()); - - /** - * - */ - @Test - public void testWinauthSSO() { - - assertThat(this.ssoDefault).isNotNull(); - assertThat(this.ssoAuthenticationCustomized).isNotNull(); - } - - /** - * - */ - @Test - public void testWinauthSSODefault() { - - assertThat(this.ssoDefault.getNegotiateSecurityFilter()).isNotNull(); - assertThat(this.ssoDefault.getNegotiateSecurityFilterEntryPoint()).isNotNull(); - assertThat(this.ssoDefault.getNegotiateSecurityFilterProvider()).isNotNull(); - assertThat(this.ssoDefault.getWaffleNegotiateSecurityFilter()).isNotNull(); - assertThat(this.ssoDefault.getWaffleSecurityFilterProviderCollection()).isNotNull(); - assertThat(this.ssoDefault.getWaffleWindowsAuthProvider()).isNotNull(); - } - - /** - * - */ - @Test - public void testWinauthSSOCustomized() { - - assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilter()).isNotNull(); - assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilterEntryPoint()).isNotNull(); - assertThat(this.ssoAuthenticationCustomized.getNegotiateSecurityFilterProvider()).isNotNull(); - assertThat(this.ssoAuthenticationCustomized.getWaffleNegotiateSecurityFilter()).isNotNull(); - assertThat(this.ssoAuthenticationCustomized.getWaffleSecurityFilterProviderCollection()).isNotNull(); - assertThat(this.ssoAuthenticationCustomized.getWaffleWindowsAuthProvider()).isNotNull(); - } - -} diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/WinauthSSOTest.java similarity index 98% rename from modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java rename to modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/WinauthSSOTest.java index 0f9d460..bf5ac83 100644 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauth/base/WinauthSSOTest.java +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/WinauthSSOTest.java @@ -1,4 +1,4 @@ -package com.capgemini.devonfw.module.winauth.base; +package com.capgemini.devonfw.module.winauthsso.base; import javax.inject.Inject; From 079c6689f611dcfd55477dc08085065d0519f69b Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Tue, 10 Jan 2017 10:23:21 +0100 Subject: [PATCH 7/9] Code clean up --- .../module/winauthad/SpringBootApp.java | 1 - .../api/accesscontrol/ActiveDirectory.java | 5 +- .../security/AuthenticationManagerImpl.java | 6 --- .../security/AuthenticationSourceADImpl.java | 2 +- .../security/UserDetailsContextMapperAD.java | 1 - .../module/winauthsso/SpringBootApp.java | 1 - .../winauthsso/common/api/UserData.java | 15 ------ .../common/api/security/UserData.java | 17 ------ .../security/NegotiateSecurityFilterSSO.java | 38 ------------- .../common/impl/security/WinauthSSOImpl.java | 8 --- .../src/test/resources/application.properties | 54 ++----------------- 11 files changed, 6 insertions(+), 142 deletions(-) diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java index c053cb5..9bff32a 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java @@ -5,7 +5,6 @@ @SuppressWarnings("javadoc") @SpringBootApplication -// @EntityScan(basePackages = { "devonfw.winauthSample" }) public class SpringBootApp { /** * Entry point for spring-boot based app diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java index 71eeb7a..76cce05 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java @@ -174,10 +174,7 @@ private String getFilter(String searchValue, String searchBy) { String filter = this.baseFilter; filter += "(" + searchBy + "=" + searchValue + "))"; - /* - * if (searchBy.equals("email")) { filter += "(mail=" + searchValue + "))"; } else if (searchBy.equals("username")) - * { filter += "(samaccountname=" + searchValue + "))"; } - */ + return filter; } diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java index 8534d6e..6f910b6 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java @@ -149,12 +149,6 @@ public void setUserDetailsContextMapper(UserDetailsContextMapper userDetailsCont this.userDetailsContextMapper = userDetailsContextMapper; } - // @Bean - // public UserDetailsContextMapper UserDetailsContextMapper() { - // - // return new UserDetailsContextMapperAD(); - // } - /** * The class BindAuthenticator in the package {@link org.springframework.security.ldap.authentication} implements the * bind authentication strategy. It simply attempts to bind as the user. diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java index b2ef4fe..5e4cfce 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java @@ -186,7 +186,7 @@ public Attributes searchUserByUsername(String searchValue) { } finally { this.activeDirectory.closeLdapConnection(); } - // (&((&(objectCategory=Person)(objectClass=User)))(samaccountname=Servidor Web)) + try { Attributes attrs = result.next().getAttributes(); return attrs; diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java index ba34c8c..6ac0abc 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java @@ -23,7 +23,6 @@ * * @author jhcore */ -// @Named("UserDetailsContextMapperAD") public class UserDetailsContextMapperAD implements UserDetailsContextMapper { private static final Logger LOG = LoggerFactory.getLogger(AuthenticationManagerImpl.class); diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java index 6894e16..6a8d8a0 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java @@ -5,7 +5,6 @@ @SuppressWarnings("javadoc") @SpringBootApplication -// @EntityScan(basePackages = { "devonfw.winauthSample" }) public class SpringBootApp { /** * Entry point for spring-boot based app diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java index 7c4d1f7..9a9cd7f 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java @@ -70,21 +70,6 @@ public String getName() { return getUsername(); } - // /** - // * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link UserData} - // * instance. - // */ - // public UserDetailsClientToAD toClientTo() { - // - // UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); - // clientTo.setId(this.userProfile.getId()); - // clientTo.setName(this.userProfile.getName()); - // clientTo.setFirstName(this.userProfile.getFirstName()); - // clientTo.setLastName(this.userProfile.getLastName()); - // clientTo.setGroups((this.userProfile.getGroups())); - // return clientTo; - // } - @Override public String toString() { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java index 86445d4..e9eb2e3 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java @@ -9,7 +9,6 @@ import org.springframework.security.core.userdetails.User; import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; -//import com.capgemini.devonfw.module.winauthsso.common.api.to.UserDetailsClientToAD; /** * Container class for the profile of a user. @@ -57,22 +56,6 @@ public String getName() { return getUsername(); } - // /** - // * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link - // UserDataAD} - // * instance. - // */ - // public UserDetailsClientToAD toClientTo() { - // - // UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); - // clientTo.setId(this.userProfile.getId()); - // clientTo.setName(this.userProfile.getName()); - // clientTo.setFirstName(this.userProfile.getFirstName()); - // clientTo.setLastName(this.userProfile.getLastName()); - // clientTo.setGroups(this.userProfile.getGroups()); - // return clientTo; - // } - @Override public String toString() { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java index 722550f..87589d8 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java @@ -33,44 +33,6 @@ public void setProvider(SecurityFilterProviderCollection securityFilterProviderC super.setProvider(securityFilterProviderCollection); } - // private AuthenticationSource authenticationSource; - // - // private GroupMapperAD groupMapperAD; - // - // /** - // * @return authenticationSource - // */ - // public AuthenticationSource getAuthenticationSource() { - // - // return this.authenticationSource; - // } - // - // /** - // * @param authenticationSource new value of authenticationSource. - // */ - // @Inject - // public void setAuthenticationSource(AuthenticationSource authenticationSource) { - // - // this.authenticationSource = authenticationSource; - // } - // - // /** - // * @return groupMapperAD - // */ - // public GroupMapperAD getGroupMapperAD() { - // - // return this.groupMapperAD; - // } - // - // /** - // * @param groupMapperAD new value of groupMapperAD. - // */ - // @Inject - // public void setGroupMapperAD(GroupMapperAD groupMapperAD) { - // - // this.groupMapperAD = groupMapperAD; - // } - @Override protected boolean setAuthentication(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java index 3bde755..6e40874 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java @@ -22,14 +22,6 @@ @Named public class WinauthSSOImpl implements WinauthSSO { - // @Override - // public NegotiateSecurityFilterEntryPoint getNegotiateSecurityFilterEntryPoint() { - // - // // TODO Auto-generated method stub - // return null; - // } - // - private WindowsAuthenticationProvider waffleWindowsAuthProvider; private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider; diff --git a/modules/winauth-sso/src/test/resources/application.properties b/modules/winauth-sso/src/test/resources/application.properties index f862ff0..3f6374f 100644 --- a/modules/winauth-sso/src/test/resources/application.properties +++ b/modules/winauth-sso/src/test/resources/application.properties @@ -2,55 +2,9 @@ # Base values # --------------------------------------------------------------------------- -#Server configuration (LDAP-> Authentication - AD -> Query to Active Directory) - -##Virtual Machine -##LDAP -#devon.winauth.ldap.url=ldap://aguasdevalencia.es/DC=AGUASDEVALENCIA,DC=ES -#devon.winauth.ldap.password=Administrador -#devon.winauth.ldap.userDn=cn=manager,DC=AGUASDEVALENCIA,DC=ES -#devon.winauth.ldap.patterns=ou=Users -#devon.winauth.ldap.userSearchFilter=(sAMAccountName={0}) -#devon.winauth.ldap.userSearchBase= -# -##AD -#devon.winauth.ad.url=ldap://aguasdevalencia.es/DC=AGUASDEVALENCIA,DC=ES -#devon.winauth.ad.domain=aguasdevalencia.es -#devon.winauth.ad.username=Administrador -#devon.winauth.ad.password=Capgemini2016 -#devon.winauth.ad.userSearchFilter= -#devon.winauth.ad.userSearchBase=(uid={0}) -#devon.winauth.ad.searchBy=sAMAccountName -#devon.winauth.ad.rolePrefix=^(.*)CN=([^,]*),.*,DC=AGUASDEVALENCIA,DC=COM$ -# -##Devon Utils -##LDAP -#devon.winauth.ldap.url=ldap://devonUtils/DC=devon,DC=com -#devon.winauth.ldap.password=Capgemini2016 -#devon.winauth.ldap.userDn=cn=dirtelf,DC=devon,DC=com -#devon.winauth.ldap.patterns=ou=Users -#devon.winauth.ldap.userSearchFilter=(sAMAccountName={0}) -#devon.winauth.ldap.userSearchBase= -# -#Capgemini -##AD -#devon.winauth.ad.url=ldap://corp.capgemini.com/OU=ES,OU=Employees,DC=CORP,DC=CAPGEMINI,DC=COM -#devon.winauth.ad.domain=corp.capgemini.com -#devon.winauth.ad.username= -#devon.winauth.ad.password=ENC() -#devon.winauth.ad.userSearchFilter=(uid={0}) -#devon.winauth.ad.userSearchBase= -#devon.winauth.ad.searchBy=sAMAccountName -#devon.winauth.ad.rolePrefix=^(.*)CN=([^,]*),.*,DC=CORP,DC=CAPGEMINI,DC=COM$ #Roles mapping (Capgemini) -devon.winauth.groups.SESPLAN=S-ESPLAN -devon.winauth.groups.ECOMU7=S-ECOMU7 -devon.winauth.groups.GradoA=dlescapgemini.grado-a -devon.winauth.groups.TESTGROUP=testGroup - -#devon.winauth.ldap.keyPass=llave -#devon.winauth.ldap.password=ENC(lICZ8b3KOGZONH9m7+7/YgTrM3suZ1Ii) -# -#devon.winauth.ad.encrypt=false -#devon.winauth.ldap.encrypt=true +#devon.winauth.groups.SESPLAN=S-ESPLAN +#devon.winauth.groups.ECOMU7=S-ECOMU7 +#devon.winauth.groups.GradoA=dlescapgemini.grado-a +#devon.winauth.groups.TESTGROUP=testGroup From eb8e0a2a74872e6f9c71f8b49bdb279510f35261 Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Tue, 10 Jan 2017 10:23:21 +0100 Subject: [PATCH 8/9] Code clean up application properties final clean up --- .../module/winauthad/SpringBootApp.java | 1 - .../api/accesscontrol/ActiveDirectory.java | 5 +- .../security/AuthenticationManagerImpl.java | 6 --- .../security/AuthenticationSourceADImpl.java | 2 +- .../security/UserDetailsContextMapperAD.java | 1 - .../module/winauthsso/SpringBootApp.java | 1 - .../winauthsso/common/api/UserData.java | 15 ------ .../common/api/security/UserData.java | 17 ------- .../security/NegotiateSecurityFilterSSO.java | 38 -------------- .../common/impl/security/WinauthSSOImpl.java | 8 --- .../src/test/resources/application.properties | 51 ------------------- 11 files changed, 2 insertions(+), 143 deletions(-) diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java index c053cb5..9bff32a 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java @@ -5,7 +5,6 @@ @SuppressWarnings("javadoc") @SpringBootApplication -// @EntityScan(basePackages = { "devonfw.winauthSample" }) public class SpringBootApp { /** * Entry point for spring-boot based app diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java index 71eeb7a..76cce05 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/api/accesscontrol/ActiveDirectory.java @@ -174,10 +174,7 @@ private String getFilter(String searchValue, String searchBy) { String filter = this.baseFilter; filter += "(" + searchBy + "=" + searchValue + "))"; - /* - * if (searchBy.equals("email")) { filter += "(mail=" + searchValue + "))"; } else if (searchBy.equals("username")) - * { filter += "(samaccountname=" + searchValue + "))"; } - */ + return filter; } diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java index 8534d6e..6f910b6 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationManagerImpl.java @@ -149,12 +149,6 @@ public void setUserDetailsContextMapper(UserDetailsContextMapper userDetailsCont this.userDetailsContextMapper = userDetailsContextMapper; } - // @Bean - // public UserDetailsContextMapper UserDetailsContextMapper() { - // - // return new UserDetailsContextMapperAD(); - // } - /** * The class BindAuthenticator in the package {@link org.springframework.security.ldap.authentication} implements the * bind authentication strategy. It simply attempts to bind as the user. diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java index b2ef4fe..5e4cfce 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/AuthenticationSourceADImpl.java @@ -186,7 +186,7 @@ public Attributes searchUserByUsername(String searchValue) { } finally { this.activeDirectory.closeLdapConnection(); } - // (&((&(objectCategory=Person)(objectClass=User)))(samaccountname=Servidor Web)) + try { Attributes attrs = result.next().getAttributes(); return attrs; diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java index ba34c8c..6ac0abc 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/common/impl/security/UserDetailsContextMapperAD.java @@ -23,7 +23,6 @@ * * @author jhcore */ -// @Named("UserDetailsContextMapperAD") public class UserDetailsContextMapperAD implements UserDetailsContextMapper { private static final Logger LOG = LoggerFactory.getLogger(AuthenticationManagerImpl.class); diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java index 6894e16..6a8d8a0 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java @@ -5,7 +5,6 @@ @SuppressWarnings("javadoc") @SpringBootApplication -// @EntityScan(basePackages = { "devonfw.winauthSample" }) public class SpringBootApp { /** * Entry point for spring-boot based app diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java index 7c4d1f7..9a9cd7f 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/UserData.java @@ -70,21 +70,6 @@ public String getName() { return getUsername(); } - // /** - // * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link UserData} - // * instance. - // */ - // public UserDetailsClientToAD toClientTo() { - // - // UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); - // clientTo.setId(this.userProfile.getId()); - // clientTo.setName(this.userProfile.getName()); - // clientTo.setFirstName(this.userProfile.getFirstName()); - // clientTo.setLastName(this.userProfile.getLastName()); - // clientTo.setGroups((this.userProfile.getGroups())); - // return clientTo; - // } - @Override public String toString() { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java index 86445d4..e9eb2e3 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/api/security/UserData.java @@ -9,7 +9,6 @@ import org.springframework.security.core.userdetails.User; import com.capgemini.devonfw.module.winauthsso.common.api.PrincipalProfile; -//import com.capgemini.devonfw.module.winauthsso.common.api.to.UserDetailsClientToAD; /** * Container class for the profile of a user. @@ -57,22 +56,6 @@ public String getName() { return getUsername(); } - // /** - // * @return an instance of {@link UserDetailsClientToAD} with the client side representation of this {@link - // UserDataAD} - // * instance. - // */ - // public UserDetailsClientToAD toClientTo() { - // - // UserDetailsClientToAD clientTo = new UserDetailsClientToAD(); - // clientTo.setId(this.userProfile.getId()); - // clientTo.setName(this.userProfile.getName()); - // clientTo.setFirstName(this.userProfile.getFirstName()); - // clientTo.setLastName(this.userProfile.getLastName()); - // clientTo.setGroups(this.userProfile.getGroups()); - // return clientTo; - // } - @Override public String toString() { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java index 722550f..87589d8 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/NegotiateSecurityFilterSSO.java @@ -33,44 +33,6 @@ public void setProvider(SecurityFilterProviderCollection securityFilterProviderC super.setProvider(securityFilterProviderCollection); } - // private AuthenticationSource authenticationSource; - // - // private GroupMapperAD groupMapperAD; - // - // /** - // * @return authenticationSource - // */ - // public AuthenticationSource getAuthenticationSource() { - // - // return this.authenticationSource; - // } - // - // /** - // * @param authenticationSource new value of authenticationSource. - // */ - // @Inject - // public void setAuthenticationSource(AuthenticationSource authenticationSource) { - // - // this.authenticationSource = authenticationSource; - // } - // - // /** - // * @return groupMapperAD - // */ - // public GroupMapperAD getGroupMapperAD() { - // - // return this.groupMapperAD; - // } - // - // /** - // * @param groupMapperAD new value of groupMapperAD. - // */ - // @Inject - // public void setGroupMapperAD(GroupMapperAD groupMapperAD) { - // - // this.groupMapperAD = groupMapperAD; - // } - @Override protected boolean setAuthentication(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java index 3bde755..6e40874 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java @@ -22,14 +22,6 @@ @Named public class WinauthSSOImpl implements WinauthSSO { - // @Override - // public NegotiateSecurityFilterEntryPoint getNegotiateSecurityFilterEntryPoint() { - // - // // TODO Auto-generated method stub - // return null; - // } - // - private WindowsAuthenticationProvider waffleWindowsAuthProvider; private NegotiateSecurityFilterProvider negotiateSecurityFilterProvider; diff --git a/modules/winauth-sso/src/test/resources/application.properties b/modules/winauth-sso/src/test/resources/application.properties index f862ff0..82b246b 100644 --- a/modules/winauth-sso/src/test/resources/application.properties +++ b/modules/winauth-sso/src/test/resources/application.properties @@ -2,55 +2,4 @@ # Base values # --------------------------------------------------------------------------- -#Server configuration (LDAP-> Authentication - AD -> Query to Active Directory) -##Virtual Machine -##LDAP -#devon.winauth.ldap.url=ldap://aguasdevalencia.es/DC=AGUASDEVALENCIA,DC=ES -#devon.winauth.ldap.password=Administrador -#devon.winauth.ldap.userDn=cn=manager,DC=AGUASDEVALENCIA,DC=ES -#devon.winauth.ldap.patterns=ou=Users -#devon.winauth.ldap.userSearchFilter=(sAMAccountName={0}) -#devon.winauth.ldap.userSearchBase= -# -##AD -#devon.winauth.ad.url=ldap://aguasdevalencia.es/DC=AGUASDEVALENCIA,DC=ES -#devon.winauth.ad.domain=aguasdevalencia.es -#devon.winauth.ad.username=Administrador -#devon.winauth.ad.password=Capgemini2016 -#devon.winauth.ad.userSearchFilter= -#devon.winauth.ad.userSearchBase=(uid={0}) -#devon.winauth.ad.searchBy=sAMAccountName -#devon.winauth.ad.rolePrefix=^(.*)CN=([^,]*),.*,DC=AGUASDEVALENCIA,DC=COM$ -# -##Devon Utils -##LDAP -#devon.winauth.ldap.url=ldap://devonUtils/DC=devon,DC=com -#devon.winauth.ldap.password=Capgemini2016 -#devon.winauth.ldap.userDn=cn=dirtelf,DC=devon,DC=com -#devon.winauth.ldap.patterns=ou=Users -#devon.winauth.ldap.userSearchFilter=(sAMAccountName={0}) -#devon.winauth.ldap.userSearchBase= -# -#Capgemini -##AD -#devon.winauth.ad.url=ldap://corp.capgemini.com/OU=ES,OU=Employees,DC=CORP,DC=CAPGEMINI,DC=COM -#devon.winauth.ad.domain=corp.capgemini.com -#devon.winauth.ad.username= -#devon.winauth.ad.password=ENC() -#devon.winauth.ad.userSearchFilter=(uid={0}) -#devon.winauth.ad.userSearchBase= -#devon.winauth.ad.searchBy=sAMAccountName -#devon.winauth.ad.rolePrefix=^(.*)CN=([^,]*),.*,DC=CORP,DC=CAPGEMINI,DC=COM$ - -#Roles mapping (Capgemini) -devon.winauth.groups.SESPLAN=S-ESPLAN -devon.winauth.groups.ECOMU7=S-ECOMU7 -devon.winauth.groups.GradoA=dlescapgemini.grado-a -devon.winauth.groups.TESTGROUP=testGroup - -#devon.winauth.ldap.keyPass=llave -#devon.winauth.ldap.password=ENC(lICZ8b3KOGZONH9m7+7/YgTrM3suZ1Ii) -# -#devon.winauth.ad.encrypt=false -#devon.winauth.ldap.encrypt=true From 8515d77ccca3d2124197484446ad9d78a40b83ff Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Tue, 17 Jan 2017 13:55:31 +0100 Subject: [PATCH 9/9] Added Spring Boot autoconfiguration to both modules --- .../module/winauthad/config/ModuleConfig.java | 15 +++++++++++++++ .../src/main/resources/META-INF/spring.factories | 1 + .../base/AuthenticationManagerImplTest.java | 1 - .../base/AuthenticationSourceADImplTest.java | 1 - .../module/winauthad/base/GroupMapperADTest.java | 1 - .../module/winauthad/base}/SpringBootApp.java | 4 +++- .../base/UserDetailsContextMapperADTest.java | 1 - .../common/impl/security/WinauthSSOImpl.java | 3 +++ .../module/winauthsso/config/ModuleConfig.java | 15 +++++++++++++++ .../src/main/resources/META-INF/spring.factories | 1 + .../module/winauthsso/base}/SpringBootApp.java | 4 +++- .../module/winauthsso/base/WinauthSSOTest.java | 7 +++---- 12 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/config/ModuleConfig.java create mode 100644 modules/winauth-ad/src/main/resources/META-INF/spring.factories rename modules/winauth-ad/src/{main/java/com/capgemini/devonfw/module/winauthad => test/java/com/capgemini/devonfw/module/winauthad/base}/SpringBootApp.java (67%) create mode 100644 modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/config/ModuleConfig.java create mode 100644 modules/winauth-sso/src/main/resources/META-INF/spring.factories rename modules/winauth-sso/src/{main/java/com/capgemini/devonfw/module/winauthsso => test/java/com/capgemini/devonfw/module/winauthsso/base}/SpringBootApp.java (67%) diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/config/ModuleConfig.java b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/config/ModuleConfig.java new file mode 100644 index 0000000..6fae0b7 --- /dev/null +++ b/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/config/ModuleConfig.java @@ -0,0 +1,15 @@ +package com.capgemini.devonfw.module.winauthad.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * Spring Boot autoconfiguration for WinauthAD module + * + * @author pparrado + * + */ +@Configuration +@ComponentScan(basePackages = { "com.capgemini.devonfw.module.winauthad" }) +public class ModuleConfig { +} diff --git a/modules/winauth-ad/src/main/resources/META-INF/spring.factories b/modules/winauth-ad/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..73ebfef --- /dev/null +++ b/modules/winauth-ad/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.capgemini.devonfw.module.winauthad.config.ModuleConfig \ No newline at end of file diff --git a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java index dc4ce1b..5b5023d 100644 --- a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationManagerImplTest.java @@ -7,7 +7,6 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauthad.SpringBootApp; import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationManagerAD; import com.capgemini.devonfw.module.winauthad.common.impl.security.AuthenticationManagerImpl; diff --git a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationSourceADImplTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationSourceADImplTest.java index 23958b2..b59d4c6 100644 --- a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationSourceADImplTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/AuthenticationSourceADImplTest.java @@ -7,7 +7,6 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauthad.SpringBootApp; import com.capgemini.devonfw.module.winauthad.common.api.AuthenticationSource; import com.capgemini.devonfw.module.winauthad.common.impl.security.AuthenticationSourceADImpl; diff --git a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/GroupMapperADTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/GroupMapperADTest.java index 8f6a025..a71d9e4 100644 --- a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/GroupMapperADTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/GroupMapperADTest.java @@ -10,7 +10,6 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauthad.SpringBootApp; import com.capgemini.devonfw.module.winauthad.common.impl.security.GroupMapperAD; import io.oasp.module.test.common.base.ComponentTest; diff --git a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/SpringBootApp.java similarity index 67% rename from modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java rename to modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/SpringBootApp.java index 9bff32a..06b49c8 100644 --- a/modules/winauth-ad/src/main/java/com/capgemini/devonfw/module/winauthad/SpringBootApp.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/SpringBootApp.java @@ -1,10 +1,12 @@ -package com.capgemini.devonfw.module.winauthad; +package com.capgemini.devonfw.module.winauthad.base; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; @SuppressWarnings("javadoc") @SpringBootApplication +@ComponentScan(basePackages = { "com.capgemini.devonfw.module.winauthad" }) public class SpringBootApp { /** * Entry point for spring-boot based app diff --git a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/UserDetailsContextMapperADTest.java b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/UserDetailsContextMapperADTest.java index cb5c3e4..cd69f67 100644 --- a/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/UserDetailsContextMapperADTest.java +++ b/modules/winauth-ad/src/test/java/com/capgemini/devonfw/module/winauthad/base/UserDetailsContextMapperADTest.java @@ -7,7 +7,6 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauthad.SpringBootApp; import com.capgemini.devonfw.module.winauthad.common.impl.security.UserDetailsContextMapperAD; import io.oasp.module.test.common.base.ComponentTest; diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java index 6e40874..ac916c9 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/common/impl/security/WinauthSSOImpl.java @@ -5,6 +5,8 @@ import javax.inject.Named; +import org.springframework.stereotype.Component; + import com.capgemini.devonfw.module.winauthsso.common.api.WinauthSSO; import waffle.servlet.spi.NegotiateSecurityFilterProvider; @@ -19,6 +21,7 @@ * @author pparrado * */ +@Component @Named public class WinauthSSOImpl implements WinauthSSO { diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/config/ModuleConfig.java b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/config/ModuleConfig.java new file mode 100644 index 0000000..a2bf17a --- /dev/null +++ b/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/config/ModuleConfig.java @@ -0,0 +1,15 @@ +package com.capgemini.devonfw.module.winauthsso.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * Spring Boot autoconfiguration for WinauthSSO module + * + * @author pparrado + * + */ +@Configuration +@ComponentScan(basePackages = { "com.capgemini.devonfw.module.winauthsso" }) +public class ModuleConfig { +} diff --git a/modules/winauth-sso/src/main/resources/META-INF/spring.factories b/modules/winauth-sso/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..a0bf8f7 --- /dev/null +++ b/modules/winauth-sso/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.capgemini.devonfw.module.winauthsso.config.ModuleConfig \ No newline at end of file diff --git a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/SpringBootApp.java similarity index 67% rename from modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java rename to modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/SpringBootApp.java index 6a8d8a0..c13e6d2 100644 --- a/modules/winauth-sso/src/main/java/com/capgemini/devonfw/module/winauthsso/SpringBootApp.java +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/SpringBootApp.java @@ -1,10 +1,12 @@ -package com.capgemini.devonfw.module.winauthsso; +package com.capgemini.devonfw.module.winauthsso.base; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; @SuppressWarnings("javadoc") @SpringBootApplication +@ComponentScan(basePackages = { "com.capgemini.devonfw.module.winauthsso" }) public class SpringBootApp { /** * Entry point for spring-boot based app diff --git a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/WinauthSSOTest.java b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/WinauthSSOTest.java index bf5ac83..fc8ca85 100644 --- a/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/WinauthSSOTest.java +++ b/modules/winauth-sso/src/test/java/com/capgemini/devonfw/module/winauthsso/base/WinauthSSOTest.java @@ -8,7 +8,6 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.capgemini.devonfw.module.winauthsso.SpringBootApp; import com.capgemini.devonfw.module.winauthsso.common.api.WinauthSSO; import com.capgemini.devonfw.module.winauthsso.common.impl.security.NegotiateSecurityFilterSSO; import com.capgemini.devonfw.module.winauthsso.common.impl.security.WinauthSSOImpl; @@ -16,18 +15,17 @@ import io.oasp.module.test.common.base.ComponentTest; /** - * This is the test-case for {@link WinauthSSO_OLD}. + * This is the test-case for {@link WinauthSSO}. * * @author jhcore */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = SpringBootApp.class) - public class WinauthSSOTest extends ComponentTest { private WinauthSSOImpl ssoDefault = new WinauthSSOImpl(); - private WinauthSSOImpl ssoAuthenticationCustomized = new WinauthSSOImpl(/* new NegotiateSecurityFilterSSO() */); + private WinauthSSOImpl ssoAuthenticationCustomized = new WinauthSSOImpl(); @Inject private WinauthSSO sso; @@ -35,6 +33,7 @@ public class WinauthSSOTest extends ComponentTest { @Inject private WinauthSSO ssoCustom; + @SuppressWarnings("javadoc") @Before public void init() {