Skip to content

Commit

Permalink
MID-4207 ldap configuration through "ldap" spring profile
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Oct 26, 2017
1 parent 15e0c9a commit 0099104
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 28 deletions.
Expand Up @@ -42,18 +42,18 @@ public class LdapSecurityConfig {
@Value("${auth.ldap.host}")
private String ldapHost;

@Value("${auth.ldap.manager}")
@Value("${auth.ldap.manager:#{null}}")
private String ldapUserDn;
@Value("${auth.ldap.manager.password}")
@Value("${auth.ldap.password:#{null}}")
private String ldapUserPassword;

@Value("${auth.ldap.dn.pattern:}")
@Value("${auth.ldap.dn.pattern:#{null}}")
private String ldapDnPattern;

@Value("${auth.ldap.search.pattern:}")
@Value("${auth.ldap.search.pattern:#{null}}")
private String ldapSearchPattern;

@Value("${auth.ldap.search.subtree}")
@Value("${auth.ldap.search.subtree:true}")
private boolean searchSubtree;

@Bean
Expand Down
Expand Up @@ -88,11 +88,17 @@ public class MidPointSpringApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
System.setProperty("xml.catalog.className", CatalogImpl.class.getName());

SpringApplication.run(MidPointSpringApplication.class, args);
configureApplication(new SpringApplicationBuilder()).run(args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return configureApplication(application);
}

private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder application) {
System.setProperty("spring.config.location", "${midpoint.home}/");

return application.sources(MidPointSpringApplication.class);
}

Expand Down
Expand Up @@ -19,7 +19,9 @@
import com.evolveum.midpoint.security.api.SecurityContextManager;
import com.evolveum.midpoint.security.enforcer.api.SecurityEnforcer;
import com.evolveum.midpoint.web.security.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -45,6 +47,9 @@
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private AuthenticationProvider authenticationProvider;

@Bean
public WicketLoginUrlAuthenticationEntryPoint wicketAuthenticationEntryPoint() {
return new WicketLoginUrlAuthenticationEntryPoint("/login");
Expand Down Expand Up @@ -118,14 +123,15 @@ protected void configure(HttpSecurity http) throws Exception {
http.headers().disable();
}

@Profile({"!ldap", "!cas"})
@Bean
public AuthenticationProvider authenticationProvider() {
return new MidPointAuthenticationProvider();
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
auth.authenticationProvider(authenticationProvider);
}

@Bean
Expand Down
8 changes: 8 additions & 0 deletions gui/admin-gui/src/main/resources/application-cas.yml
@@ -0,0 +1,8 @@
#auth:
# cas:
# midpoint:
# host: http://localhost:8080/midpoint
# send:
# renew: false
# server:
# host: http://localhost:9090/
11 changes: 11 additions & 0 deletions gui/admin-gui/src/main/resources/application-ldap.yml
@@ -0,0 +1,11 @@
#auth:
# ldap:
# host: ldap://localhost:389/dc=example,dc=com
# manager: cn=admin,dc=example,dc=com
# password: secret
# dn:
# pattern: uid={0},ou=people
#
# search:
# pattern: (uid={0})
# subtree: true
4 changes: 4 additions & 0 deletions gui/admin-gui/src/main/resources/application.yml
Expand Up @@ -10,5 +10,9 @@ server:
tomcat:
basedir: ${midpoint.home}

auth:
logout:
url: /

# more properties with default values can be found here:
# https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
2 changes: 0 additions & 2 deletions gui/admin-gui/src/main/resources/ctx-webapp.xml
Expand Up @@ -23,8 +23,6 @@
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true" default-autowire="byName">

<context:property-placeholder location="classpath:midpoint-config.properties"/> <!-- change classpath to e.g ${midpoint.home} -->

<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="com.evolveum.midpoint.web"/>
Expand Down
17 changes: 0 additions & 17 deletions gui/admin-gui/src/main/resources/midpoint-config.properties

This file was deleted.

Expand Up @@ -112,9 +112,13 @@ public MidPointPrincipal getPrincipal(String username) throws ObjectNotFoundExce
PrismObject<UserType> user;
try {
user = findByUsername(username, result);

if (user == null) {
throw new ObjectNotFoundException("Couldn't find user with name '" + username + "'");
}
} catch (ObjectNotFoundException ex) {
LOGGER.trace("Couldn't find user with name '{}', reason: {}.", username, ex.getMessage(), ex);
throw ex;
LOGGER.trace("Couldn't find user with name '{}', reason: {}.", username, ex.getMessage(), ex);
throw ex;
} catch (Exception ex) {
LOGGER.warn("Error getting user with name '{}', reason: {}.", username, ex.getMessage(), ex);
throw new SystemException(ex.getMessage(), ex);
Expand Down

0 comments on commit 0099104

Please sign in to comment.