Commit 12871092 authored by Magnus Westergaard's avatar Magnus Westergaard
Browse files

authorization-server: Local test user for offsite development.

parent 4062ea51
......@@ -15,6 +15,7 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy;
import org.springframework.ldap.core.support.LdapContextSource;
......@@ -25,7 +26,6 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.ldap.userdetails.LdapUserDetails;
import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper;
import org.springframework.security.ldap.userdetails.UserDetailsContextMapper;
......@@ -36,9 +36,8 @@ import org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilt
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.web.filter.CompositeFilter;
import org.springframework.security.core.userdetails.UserDetailsService;
import no.deichman.auth.service.SimpleUserDetailsService;
@Profile("!noldap")
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
......@@ -63,8 +62,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private OAuth2ClientContext oauth2ClientContext;
@Inject
private UserDetailsService userDetailsService;
protected SecurityConfig() {
super();
}
@Inject
public SecurityConfig(OAuth2ClientContext oauth2ClientContext) {
......@@ -74,12 +74,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
/** TODO Can we authenticate with Active Directory?
ActiveDirectoryLdapAuthenticationProvider adProvider = new ActiveDirectoryLdapAuthenticationProvider(domain, url);
auth.userDetailsService(userDetailsService)
.passwordEncoder(encoder());
*/
auth
.ldapAuthentication()
.userDetailsContextMapper(userDetailsContextMapper())
......@@ -110,11 +104,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return contextSource;
}
@Bean
public BCryptPasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
@Bean
@ConfigurationProperties("oslo")
public ClientResources oslo() {
......
package no.deichman.auth.config.dev;
import no.deichman.auth.config.SecurityConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@Profile("noldap")
@Configuration
@EnableWebSecurity
public class DevSecurityConfig extends SecurityConfig {
public DevSecurityConfig() {
super();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("test").password(encoder().encode("test")).roles("TKAT_EDIT", "CATALOG_SUPER", "DEV");
}
@Bean
public BCryptPasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
}
package no.deichman.auth.service;
import java.util.Arrays;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;
@Component
public class SimpleUserDetailsService implements UserDetailsService {
//TODO LDAP integration goes in here
@Override
public UserDetails loadUserByUsername(String userName) {
String devuser = System.getenv("DEVUSER");
if (devuser != null) {
SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_TKAT_EDIT");
return new org.springframework.security.core.userdetails.User(devuser, "$2a$04$KCHiUvn1uHxBVVg56rcLvu7aJAMPlF75E.KnuZRGW7f.HAqp.xbhO", Arrays.asList(simpleGrantedAuthority));
}
return null;
}
}
......@@ -22,7 +22,6 @@ import no.deichman.auth.DeichmanAuthServer;
import no.deichman.auth.config.CustomLdapUserDetails;
import no.deichman.auth.config.SimpleCorsFilter;
import no.deichman.auth.controller.LogoutController;
import no.deichman.auth.service.SimpleUserDetailsService;
@RunWith(SpringRunner.class)
@SpringBootTest
......@@ -60,11 +59,6 @@ public class AppTest {
new LogoutController().exit(this.servletRequest, this.servletResponse);
}
@Test
public void testUserService() {
new SimpleUserDetailsService().loadUserByUsername("euleruser");
}
@Test
public void testUserDetails() {
CustomLdapUserDetails ud = new CustomLdapUserDetails(this.details, this.ctx);
......
......@@ -17,4 +17,8 @@ services:
context: sibyl
dockerfile: Dockerfile-dev
authorization-server:
environment:
- SPRING_PROFILES_ACTIVE=noldap
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment