Commit 09cd130d authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

847: Implement development / debugging flag

Task-Url: https://minfba.de.dariah.eu/mantisbt/view.php?id=847
parent 3ed9d234
......@@ -4,7 +4,7 @@
<parent>
<groupId>eu.dariah.de</groupId>
<artifactId>dariahsp</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>dariahsp-core</artifactId>
<name>dariahsp - core library</name>
......@@ -107,4 +107,5 @@
<version>${eu.dariah.de.dariahsp.dariahsp-core.version}</version>
</project>
package eu.dariah.de.dariahsp;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
public interface DebugAwareAuthenticationProvider extends AuthenticationProvider {
public Authentication getAuthentication();
}
package eu.dariah.de.dariahsp.local;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import eu.dariah.de.dariahsp.DebugAwareAuthenticationProvider;
import eu.dariah.de.dariahsp.model.User;
import eu.dariah.de.dariahsp.model.UserImpl;
import eu.dariah.de.dariahsp.service.UserService;
public class LocalAuthenticationProvider implements AuthenticationProvider {
public class LocalAuthenticationProvider implements DebugAwareAuthenticationProvider, InitializingBean {
private UserService userService;
private UserDetailsService localUserDb;
private PasswordEncoder encoder;
private String authDebugUser;
private Authentication authDebug;
public UserService getUserService() { return userService; }
public void setUserService(UserService userService) { this.userService = userService; }
......@@ -26,8 +33,34 @@ public class LocalAuthenticationProvider implements AuthenticationProvider {
public PasswordEncoder getEncoder() { return encoder; }
public void setEncoder(PasswordEncoder encoder) { this.encoder = encoder; }
public String isAuthDebugUser() { return authDebugUser; }
public void setAuthDebugUser(String authDebugUser) { this.authDebugUser = authDebugUser; }
@Override
public void afterPropertiesSet() throws Exception {
if (authDebugUser!=null && (System.getProperty("saml")==null || !Boolean.parseBoolean(System.getProperty("saml")))) {
UserDetails user = getLocalUserDb().loadUserByUsername(authDebugUser);
if (user==null) {
user = new UserImpl();
((UserImpl)user).setUsername(authDebugUser);
user = userService.getUserDetails(user);
}
UsernamePasswordAuthenticationToken testAuth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword().hashCode(), user.getAuthorities());
testAuth.setDetails(user);
userService.saveUser((User)user);
authDebug = testAuth;
}
}
@Override
public Authentication getAuthentication() {
if (authDebug!=null && (System.getProperty("saml")==null || !Boolean.parseBoolean(System.getProperty("saml")))) {
SecurityContextHolder.getContext().setAuthentication(authDebug);
}
return SecurityContextHolder.getContext().getAuthentication();
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
try {
......
......@@ -2,10 +2,14 @@ package eu.dariah.de.dariahsp.saml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.saml.SAMLCredential;
import eu.dariah.de.dariahsp.DebugAwareAuthenticationProvider;
import eu.dariah.de.dariahsp.saml.attributequery.SAMLAttributeAggregationService;
public class SAMLAuthenticationProvider extends org.springframework.security.saml.SAMLAuthenticationProvider {
public class SAMLAuthenticationProvider extends org.springframework.security.saml.SAMLAuthenticationProvider implements DebugAwareAuthenticationProvider {
protected static final Logger logger = LoggerFactory.getLogger(SAMLAuthenticationProvider.class);
private SAMLAttributeAggregationService attributeAggregationService = null;
......@@ -21,4 +25,10 @@ public class SAMLAuthenticationProvider extends org.springframework.security.sam
}
return super.getUserDetails(credential);
}
@Override
public Authentication getAuthentication() {
// No debugging user with SAML!
return SecurityContextHolder.getContext().getAuthentication();
}
}
......@@ -5,12 +5,13 @@ import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.AuthenticationProvider;
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 org.springframework.security.core.userdetails.UserDetails;
import eu.dariah.de.dariahsp.DebugAwareAuthenticationProvider;
import eu.dariah.de.dariahsp.exceptions.SecurityConfigException;
import eu.dariah.de.dariahsp.model.Role;
import eu.dariah.de.dariahsp.model.UserImpl;
......@@ -18,13 +19,16 @@ import eu.dariah.de.dariahsp.model.web.AuthPojo;
public class AuthInfoHelper {
private static final Logger logger = LoggerFactory.getLogger(AuthInfoHelper.class);
private RoleLevelVoter roleLevelVoter;
private DebugAwareAuthenticationProvider authenticationProvider;
public RoleLevelVoter getRoleLevelVoter() { return roleLevelVoter; }
public void setRoleLevelVoter(RoleLevelVoter roleLevelVoter) { this.roleLevelVoter = roleLevelVoter; }
public DebugAwareAuthenticationProvider getAuthenticationProvider() { return authenticationProvider; }
public void setAuthenticationProvider(DebugAwareAuthenticationProvider authenticationProvider) { this.authenticationProvider = authenticationProvider; }
public AuthPojo getAuth(HttpServletRequest request) {
return this.getCurrentUserDetails(request);
......@@ -40,7 +44,7 @@ public class AuthInfoHelper {
}
public AuthPojo getCurrentUserDetails(HttpServletRequest request) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Authentication auth = authenticationProvider.getAuthentication();
AuthPojo authPojo;
if (auth!=null && auth.isAuthenticated()==true) {
if (auth.getDetails()!=null && auth.getDetails() instanceof UserDetails) {
......
......@@ -3,7 +3,7 @@
<parent>
<groupId>eu.dariah.de</groupId>
<artifactId>dariahsp</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>dariahsp-sample</artifactId>
<packaging>war</packaging>
......@@ -20,7 +20,7 @@
<dependency>
<groupId>eu.dariah.de</groupId>
<artifactId>dariahsp-core</artifactId>
<version>${project.version}</version>
<version>${eu.dariah.de.dariahsp.dariahsp-core.version}</version>
</dependency>
<dependency>
<groupId>de.unibamberg.minf.core</groupId>
......@@ -122,4 +122,5 @@
<scope>test</scope>
</dependency>
</dependencies>
<version>${eu.dariah.de.dariahsp.dariahsp-sample.version}</version>
</project>
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.dariah.de</groupId>
<artifactId>dariahsp</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>dariahsp - parent pom</name>
<description>Metapackage for the DARIAH Service Provider (dariahsp) library</description>
<packaging>pom</packaging>
......@@ -20,6 +20,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<eu.dariah.de.dariahsp.dariahsp-core.version>1.2.1-SNAPSHOT</eu.dariah.de.dariahsp.dariahsp-core.version>
<eu.dariah.de.dariahsp.dariahsp-sample.version>1.2.0-SNAPSHOT</eu.dariah.de.dariahsp.dariahsp-sample.version>
<de.unibamberg.minf.core.core-metamodel.version>4.2.1-SNAPSHOT</de.unibamberg.minf.core.core-metamodel.version>
<de.unibamberg.minf.core.core-util.version>2.0.0-SNAPSHOT</de.unibamberg.minf.core.core-util.version>
......
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