Skip to content
Snippets Groups Projects
Unverified Commit 6a593b69 authored by Martin Weise's avatar Martin Weise
Browse files

still not working

parent c9bb216b
No related branches found
No related tags found
3 merge requests!81New stable release,!43Merge dev to master,!33Draft: merge dev to master
Showing
with 269 additions and 197 deletions
...@@ -6,7 +6,7 @@ target/ ...@@ -6,7 +6,7 @@ target/
### Generated ### ### Generated ###
ready ready
*.jks *.pem
### STS ### ### STS ###
.apt_generated .apt_generated
......
...@@ -9,4 +9,4 @@ use TU Wien SSO ...@@ -9,4 +9,4 @@ use TU Wien SSO
## Development ## Development
Context metadata for IdP: `http://localhost:9097/context/saml/metadata` Context metadata for IdP: `http://localhost:9097/saml/metadata`
\ No newline at end of file \ No newline at end of file
...@@ -33,19 +33,6 @@ ...@@ -33,19 +33,6 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>${spring-saml.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
...@@ -60,6 +47,16 @@ ...@@ -60,6 +47,16 @@
<artifactId>javax.ws.rs-api</artifactId> <artifactId>javax.ws.rs-api</artifactId>
<version>${javax-rs.version}</version> <version>${javax-rs.version}</version>
</dependency> </dependency>
<!-- SAML -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>${spring-saml.version}</version>
</dependency>
<!-- Entity and API --> <!-- Entity and API -->
<dependency> <dependency>
<groupId>at.tuwien</groupId> <groupId>at.tuwien</groupId>
...@@ -74,6 +71,11 @@ ...@@ -74,6 +71,11 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- Testing --> <!-- Testing -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -5,11 +5,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -5,11 +5,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import springfox.documentation.oas.annotations.EnableOpenApi; import springfox.documentation.oas.annotations.EnableOpenApi;
@EnableWebMvc
@EnableOpenApi @EnableOpenApi
@EnableWebSecurity
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class FdaAuthenticationServiceApplication { public class FdaAuthenticationServiceApplication {
......
package at.tuwien.endpoints; package at.tuwien.endpoints;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.saml.metadata.MetadataManager;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; @RestController("/api/auth")
import java.util.Set;
/**
* https://www.baeldung.com/spring-security-saml
*/
@Log4j2
@RestController
@CrossOrigin(origins = "*")
@ControllerAdvice
@RequestMapping("/api/auth")
public class AuthenticationEndpoint { public class AuthenticationEndpoint {
private final MetadataManager metadataManager; @RequestMapping("/")
public String index() {
@Autowired return "index";
public AuthenticationEndpoint(MetadataManager metadataManager) {
this.metadataManager = metadataManager;
} }
// @GetMapping @RequestMapping("/hello")
// @ApiOperation(value = "Check user authentication", notes = "Check if the user is authenticated") public String hello() {
// @ApiResponses({ return "hello";
// @ApiResponse(code = 202, message = "User is authenticated."),
// @ApiResponse(code = 401, message = "The user is not authenticated"),
// })
// public ResponseEntity<?> status() {
// final Authentication auth = SecurityContextHolder.getContext()
// .getAuthentication();
// if (auth.isAuthenticated()) {
// return ResponseEntity.status(HttpStatus.ACCEPTED)
// .build();
// }
// return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
// .build();
// }
//
@RequestMapping(value = "/discovery", method = RequestMethod.GET)
public String idpSelection(HttpServletRequest request) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth == null) {
log.debug("Current authentication instance from security context is null");
} else {
log.debug("Current authentication instance from security context: {}", this.getClass().getSimpleName());
}
if (auth == null || (auth instanceof AnonymousAuthenticationToken)) {
final Set<String> idps = metadataManager.getIDPEntityNames();
for (String idp : idps) {
log.debug("Configured Identity Provider for SSO: {}", idp);
}
return "pages/discovery";
} else {
log.warn("The current user is already logged.");
return "redirect:/landing";
}
} }
} }
\ No newline at end of file
...@@ -16,9 +16,6 @@ eureka: ...@@ -16,9 +16,6 @@ eureka:
fda: fda:
ready.path: /ready ready.path: /ready
identity.provider: identity.provider:
discovery:
url: http://localhost:9097/context/saml/discovery
response: http://localhost:9097/context/saml/login
metadata: https://idp.zid.tuwien.ac.at/saml2 metadata: https://idp.zid.tuwien.ac.at/saml2
issuer: issuer:
cert: /okta.crt cert: /okta.crt
......
...@@ -6,6 +6,7 @@ spring: ...@@ -6,6 +6,7 @@ spring:
loadbalancer.ribbon.enabled: false loadbalancer.ribbon.enabled: false
security: security:
saml2: saml2:
metadata: ./rest-service/src/main/resources/saml/metadata.xml
relyingparty: relyingparty:
registration: registration:
okta-saml: okta-saml:
...@@ -15,7 +16,14 @@ spring: ...@@ -15,7 +16,14 @@ spring:
- certificate-location: "classpath:x509/okta.crt" - certificate-location: "classpath:x509/okta.crt"
singlesignon.url: https://dev-13953915.okta.com/app/dev-13953915_testtusaml_1/exk26nye6eBAomvJW5d7/sso/saml singlesignon.url: https://dev-13953915.okta.com/app/dev-13953915_testtusaml_1/exk26nye6eBAomvJW5d7/sso/saml
singlesignon.sign-request: false singlesignon.sign-request: false
server.port: 9097 server:
port: 9097
ssl.enabled: true
ssl:
key-alias: dbrepo
key-store: classpath:saml/dbrepo.p12
key-store-password: dbrepo
key-store-type: pkcs12
logging: logging:
pattern.console: "%d %highlight(%-5level) %msg%n" pattern.console: "%d %highlight(%-5level) %msg%n"
level: level:
...@@ -26,13 +34,3 @@ eureka: ...@@ -26,13 +34,3 @@ eureka:
client.serviceUrl.defaultZone: http://localhost:9090/eureka/ client.serviceUrl.defaultZone: http://localhost:9090/eureka/
fda: fda:
ready.path: ./ready ready.path: ./ready
\ No newline at end of file
identity.provider:
metadata: ./rest-service/src/main/resources/idp_metadata.xml
discovery:
url: http://localhost:9097/context/saml/discovery
response: http://localhost:9097/context/saml/login
saml:
keystore:
location: ./dbrepo.jks
alias: dbrepo
password: dbrepo
\ No newline at end of file
File added
File added
...@@ -34,4 +34,24 @@ ...@@ -34,4 +34,24 @@
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location="https://dev-13953915.okta.com/app/dev-13953915_testtusaml_1/exk26nye6eBAomvJW5d7/sso/saml"/> Location="https://dev-13953915.okta.com/app/dev-13953915_testtusaml_1/exk26nye6eBAomvJW5d7/sso/saml"/>
</md:IDPSSODescriptor> </md:IDPSSODescriptor>
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="https://dbrepo.ossdip.at/api/auth"
index="1" />
</md:SPSSODescriptor>
<md:Organization>
<md:OrganizationName xml:lang="en-US">Technische Universität Wien</md:OrganizationName>
<md:OrganizationDisplayName xml:lang="en-US">TU Wien</md:OrganizationDisplayName>
<md:OrganizationURL xml:lang="en-US">https://tuwien.ac.at</md:OrganizationURL>
</md:Organization>
<md:ContactPerson contactType="technical">
<md:GivenName>Martin Weise</md:GivenName>
<md:EmailAddress>martin.weise@tuwien.ac.at</md:EmailAddress>
</md:ContactPerson>
<md:ContactPerson contactType="support">
<md:GivenName>Andreas Rauber</md:GivenName>
<md:EmailAddress>andreas.rauber@tuwien.ac.at</md:EmailAddress>
</md:ContactPerson>
</md:EntityDescriptor> </md:EntityDescriptor>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<md:EntityDescriptor entityID="http://www.okta.com/exk26nye6eBAomvJW5d7"
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
<md:IDPSSODescriptor WantAuthnRequestsSigned="false"
protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:KeyDescriptor use="signing">
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xm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Hh9Gg/rl04O4Uk12f9YJF1k5Qko
ZQ3Kaxf/5nKw3mJL4wzmJz3ezeEn4M5VyC6BfhIcIC+asScsEgjRNQQ/SrgG7ywl0C3i+P41Nw9x
cWXQ6pepnLVR9q1aaLv2cyZ7RiN0JyKxruWdZPAluPODEp65TpfKbfCBXM00Bikm4MW76rXH2sjI
uUmMDfGSFmR+urDPJdc8kL26X0kwUrbEXXsT3g==
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</md:KeyDescriptor>
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</md:NameIDFormat>
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="https://dev-13953915.okta.com/app/dev-13953915_testtusaml_1/exk26nye6eBAomvJW5d7/sso/saml"/>
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location="https://dev-13953915.okta.com/app/dev-13953915_testtusaml_1/exk26nye6eBAomvJW5d7/sso/saml"/>
</md:IDPSSODescriptor>
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="http://localhost:9097/api/auth"
index="1" />
</md:SPSSODescriptor>
<md:Organization>
<md:OrganizationName xml:lang="en-US">Technische Universität Wien</md:OrganizationName>
<md:OrganizationDisplayName xml:lang="en-US">TU Wien</md:OrganizationDisplayName>
<md:OrganizationURL xml:lang="en-US">https://tuwien.ac.at</md:OrganizationURL>
</md:Organization>
<md:ContactPerson contactType="technical">
<md:GivenName>Martin Weise</md:GivenName>
<md:EmailAddress>martin.weise@tuwien.ac.at</md:EmailAddress>
</md:ContactPerson>
<md:ContactPerson contactType="support">
<md:GivenName>Andreas Rauber</md:GivenName>
<md:EmailAddress>andreas.rauber@tuwien.ac.at</md:EmailAddress>
</md:ContactPerson>
</md:EntityDescriptor>
\ No newline at end of file
<?xml version="1.0"?> <?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" <md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
validUntil="2021-10-13T10:33:48Z" validUntil="2021-10-13T15:46:10Z"
cacheDuration="PT604800S" cacheDuration="PT604800S"
entityID="at:tuwien:dbrepo:auth"> entityID="at:tuwien:dbrepo:auth">
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"> <md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat> <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="http://localhost:9097/api/auth" Location="https://dbrepo.ossdip.at/api/auth"
index="1" /> index="1" />
</md:SPSSODescriptor> </md:SPSSODescriptor>
<md:Organization>
<md:OrganizationName xml:lang="en-US">Technische Universität Wien</md:OrganizationName>
<md:OrganizationDisplayName xml:lang="en-US">TU Wien</md:OrganizationDisplayName>
<md:OrganizationURL xml:lang="en-US">https://tuwien.ac.at</md:OrganizationURL>
</md:Organization>
<md:ContactPerson contactType="technical"> <md:ContactPerson contactType="technical">
<md:GivenName>Martin Weise</md:GivenName> <md:GivenName>Martin Weise</md:GivenName>
<md:EmailAddress>martin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MUgNTP52GE24HGNtLi1qoJFlcDyqSMo59ahy2cI2qBDLKobkx/J3vWraV0T9VuG
WCLKTVXkcGdtwlfFRjlBz4pYg1htmf5X6DYO8A4jqv2Il9DjXA6USbW1FzXSLr9O
he8Y4IWS6wY7bCkjCWDcRQJMEhg76fsO3txE+FiYruq9RUWhiF1myv4Q6W+CyBFC
Dfvp7OOGAN6dEOM4+qR9sdjoSYKEBpsr6GtPAQw4dy753ec5
-----END CERTIFICATE-----
\ No newline at end of file
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCmvl9NZd4qV53j
8U1irMwR0RXR2tl0i3FqXUxGYUHabIADLciAzl83vFnPMmJFeubnDBGfkP2Z7Q+9
6fgwuxhXVVovT4uCwNcUGW66LzwemYJKnauy6muPooyllLO/mHAehhtdber7H9dw
j8gdTjIDGRgw/owElsMGYOt1XxXRpnmh6QzvprT38Lt7OTfRlvlz//p0PoYzfeI2
95fSGuIAl2rVAOQJq/n/Nl3dbTQ4KdLn0raf5am1ah+S904br34JFyDfziswLGNR
Q4SuYxFUXmfyV8TsxmJeRRfBa6JFofbAsuvzJ/TcJDiaLcsWjbWzKQTz8tWhTA1U
5McU0sLTAgMBAAECggEALFYeXSQjCLs3Xm7BFuW/dVVVKfG5NIYHaDLanzQpIH0N
JMs9rxIwu083yiIpgzQExZat8PHKnO0t7F+UANEezcoCKuZJwECqb8u7Z4I7yB8l
R9XY27/9Tbn5D+YUTXOpDFS4XgVmH9P9ow54NWKfZbd8eTqV3HqB7OZEdXcNBCuD
1RPpEB+UJx+7HMfqRfyjSF0fKOEPjq2aBw3DfYuwiU2O/L9n5KftU05AQA8FTGe+
gOnnGjEIPvwykspB8pgKri9TB3RAs22mrho1L7j3ThEBa+sauvUWsKG72WjHjzKJ
07WGa28uW2qhXxGZD5aAbOmLHHV2d9F81OpeRnM7kQKBgQDZO9cBdO2lvGVsnAVi
O0G1gSficX/jFUEKb15EzvyEuEElCFcIOWZgvmn+9Zr4TAJLzgSUgGTlREvLM4Zf
mh2RR2fXRMbmPiI+37+E/841Aa5b/pfJj4kolz2Y3FmlrztPTlPkx8kFckdW4HSH
WHM3VlIfWSWdGQye8EuPC5+mXQKBgQDEf+4M8q16q4SxnX2Yci46cZbnS98n7QG/
HnuVElmnodxV7OOc773x7/nyoW8j3hhD9GWQkPjQMbT5c8pMix5+/AG2vvjtzhJW
klnYz7iw2k6+OY1oMSPu+f/wBpXOhJCniAFjPJCXwpSA+h0KuaxfOhxxOZl++E8c
gEmbc1Ua7wKBgQChBt6F0esnY9O7ApxrCInYxXiPPpsR9XtVBODYGKbOqtZ/YQNC
sWnWZM+lkuHhFFbPYlO60MH5wPp+Eh+VVmR8gHXU+MKHgZ9ZA/qv1/8/A5P/1WUm
oCOH1zRtz0kUrCRG0UUW3ZGBXAjNuWwnt8UQTAhr/GUJYrwcRPt9eZxKcQKBgQDE
P3RTUCd8RULQVRczoo2S5xEsTbVA3c8Jvnr0hhAugFRbKKymdzXAJMj/zsT+EHkx
nSu2d2NYIty46jDXw3WgozVe+1oHvvDHr4C2LbcqQc205CvbLIDT0rEPWrRRPkpu
V0Hzh3BtcPL54VIR/SAvNw1i84Des0XnlCRvcX9E1wKBgQC8DgYnsMEGFpVBp1xT
0ER0XSq5njl6vAoUCkw3jN+dkWxYjI9sWQtP5pyrE0kWDG8h9/mbRG5rTFK7PzK6
Vilqp7hws3NuKec3uRBtoeZI2wIBVfBihTLM7AhUROsrbf2ocP1jfEvl7yd49UYI
i/dStaqfpozr864eytU8Pzct3g==
-----END PRIVATE KEY-----
\ No newline at end of file
package at.tuwien.config; package at.tuwien.config;
import at.tuwien.service.UserService;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.app.VelocityEngine;
import org.opensaml.saml2.metadata.provider.*; import org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider;
import org.opensaml.saml2.metadata.provider.MetadataProvider;
import org.opensaml.saml2.metadata.provider.MetadataProviderException;
import org.opensaml.xml.parse.ParserPool; import org.opensaml.xml.parse.ParserPool;
import org.opensaml.xml.parse.StaticBasicParserPool; import org.opensaml.xml.parse.StaticBasicParserPool;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -48,42 +48,26 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher; ...@@ -48,42 +48,26 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
/**
*
*/
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true) @EnableGlobalMethodSecurity(securedEnabled = true)
public class SamlConfig extends WebSecurityConfigurerAdapter implements InitializingBean, DisposableBean { public class SamlConfig extends WebSecurityConfigurerAdapter implements InitializingBean, DisposableBean {
private final UserService userService;
private Timer backgroundTaskTimer; private Timer backgroundTaskTimer;
private MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager; private MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager;
@Autowired @Value("${spring.security.saml2.metadata}")
public SamlConfig(UserService userService) { private String serviceMetadataPath;
this.userService = userService;
}
@Value("${fda.saml.keystore.location}") @Value("${server.ssl.key-store}")
private String samlKeystoreLocation; private String samlKeystoreLocation;
@Value("${fda.saml.keystore.alias}") @Value("${server.ssl.key-alias}")
private String samlKeystoreAlias; private String samlKeystoreAlias;
@Value("${fda.saml.keystore.password}") @Value("${server.ssl.key-store-password}")
private String samlKeystorePassword; private String samlKeystorePassword;
@Value("${fda.identity.provider.metadata}")
private String identityProviderMetadataPath;
@Value("${fda.identity.provider.discovery.url}")
private String identityProviderDiscoveryUrl;
@Value("${fda.identity.provider.discovery.response}")
private String identityProviderDiscoveryResponseUrl;
/* The filter is waiting for connections on URL suffixed with filterSuffix and presents SP metadata there */ /* The filter is waiting for connections on URL suffixed with filterSuffix and presents SP metadata there */
@Bean @Bean
public MetadataDisplayFilter metadataDisplayFilter() { public MetadataDisplayFilter metadataDisplayFilter() {
...@@ -121,7 +105,7 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -121,7 +105,7 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
/* Processing filter for WebSSO profile messages */ /* Processing filter for WebSSO profile messages */
@Bean @Bean
public SAMLProcessingFilter samlWebSSOProcessingFilter() throws Exception { public SAMLProcessingFilter samlWebSSOProcessingFilter() throws Exception {
SAMLProcessingFilter samlWebSSOProcessingFilter = new SAMLProcessingFilter(); final SAMLProcessingFilter samlWebSSOProcessingFilter = new SAMLProcessingFilter();
samlWebSSOProcessingFilter.setAuthenticationManager(authenticationManager()); samlWebSSOProcessingFilter.setAuthenticationManager(authenticationManager());
samlWebSSOProcessingFilter.setAuthenticationSuccessHandler(successRedirectHandler()); samlWebSSOProcessingFilter.setAuthenticationSuccessHandler(successRedirectHandler());
samlWebSSOProcessingFilter.setAuthenticationFailureHandler(authenticationFailureHandler()); samlWebSSOProcessingFilter.setAuthenticationFailureHandler(authenticationFailureHandler());
...@@ -151,8 +135,7 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -151,8 +135,7 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
return logoutHandler; return logoutHandler;
} }
/* Filter processing incoming logout messages. First argument determines URL user will be redirected to after /* Filter processing incoming logout messages */
successful global logout */
@Bean @Bean
public SAMLLogoutProcessingFilter samlLogoutProcessingFilter() { public SAMLLogoutProcessingFilter samlLogoutProcessingFilter() {
return new SAMLLogoutProcessingFilter(successLogoutHandler(), return new SAMLLogoutProcessingFilter(successLogoutHandler(),
...@@ -217,39 +200,24 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -217,39 +200,24 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
return new SAMLProcessorImpl(bindings); return new SAMLProcessorImpl(bindings);
} }
/** /* Define the security filter chain in order to support SSO Auth by using SAML 2.0 */
* Define the security filter chain in order to support SSO Auth by using SAML 2.0
*
* @return Filter chain proxy
* @throws Exception
*/
@Bean @Bean
public FilterChainProxy samlFilter() throws Exception { public FilterChainProxy samlFilter() throws Exception {
List<SecurityFilterChain> chains = new ArrayList<>(); List<SecurityFilterChain> chains = new ArrayList<>();
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/context/saml/login/**"), chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
samlWebSSOProcessingFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
samlDiscovery()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
samlEntryPoint())); samlEntryPoint()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/context/saml/logout/**"), chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"),
samlLogoutFilter())); samlLogoutFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/context/saml/metadata/**"), chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"),
metadataDisplayFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/context/saml/SSO/**"),
samlWebSSOProcessingFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/context/saml/SSOHoK/**"),
samlWebSSOHoKProcessingFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/context/saml/SingleLogout/**"),
samlLogoutProcessingFilter())); samlLogoutProcessingFilter()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/context/saml/discovery/**"),
samlDiscovery()));
return new FilterChainProxy(chains); return new FilterChainProxy(chains);
} }
/** /* Returns the authentication manager currently used by Spring. */
* Returns the authentication manager currently used by Spring.
* It represents a bean definition with the aim allow wiring from
* other classes performing the Inversion of Control (IoC).
*
* @throws Exception
*/
@Bean @Bean
@Override @Override
public AuthenticationManager authenticationManagerBean() throws Exception { public AuthenticationManager authenticationManagerBean() throws Exception {
...@@ -258,9 +226,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -258,9 +226,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
/** /**
* Defines the web based security configuration. * Defines the web based security configuration.
*
* @param http It allows configuring web based security for specific http requests.
* @throws Exception
*/ */
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
...@@ -282,9 +247,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -282,9 +247,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
/** /**
* Sets a custom authentication provider. * Sets a custom authentication provider.
*
* @param auth SecurityBuilder used to create an AuthenticationManager.
* @throws Exception
*/ */
@Override @Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {
...@@ -326,7 +288,7 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -326,7 +288,7 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
@Qualifier("idp-ssocircle") @Qualifier("idp-ssocircle")
public ExtendedMetadataDelegate ssoCircleExtendedMetadataProvider() throws MetadataProviderException { public ExtendedMetadataDelegate ssoCircleExtendedMetadataProvider() throws MetadataProviderException {
final FilesystemMetadataProvider filesystemMetadataProvider = new FilesystemMetadataProvider( final FilesystemMetadataProvider filesystemMetadataProvider = new FilesystemMetadataProvider(
new File(identityProviderMetadataPath)); new File(serviceMetadataPath));
filesystemMetadataProvider.setParserPool(parserPool()); filesystemMetadataProvider.setParserPool(parserPool());
final ExtendedMetadataDelegate extendedMetadataDelegate = new ExtendedMetadataDelegate(filesystemMetadataProvider, final ExtendedMetadataDelegate extendedMetadataDelegate = new ExtendedMetadataDelegate(filesystemMetadataProvider,
extendedMetadata()); extendedMetadata());
...@@ -338,10 +300,8 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -338,10 +300,8 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
/* IDP Discovery Service */ /* IDP Discovery Service */
@Bean @Bean
public SAMLDiscovery samlDiscovery() { public SAMLDiscovery samlDiscovery() throws MetadataProviderException {
SAMLDiscovery idpDiscovery = new SAMLDiscovery(); return new SAMLDiscovery();
idpDiscovery.setIdpSelectionPath("/api/auth/discovery");
return idpDiscovery;
} }
/* Setup advanced info about metadata */ /* Setup advanced info about metadata */
...@@ -350,8 +310,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -350,8 +310,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
ExtendedMetadata extendedMetadata = new ExtendedMetadata(); ExtendedMetadata extendedMetadata = new ExtendedMetadata();
extendedMetadata.setLocal(true); extendedMetadata.setLocal(true);
extendedMetadata.setIdpDiscoveryEnabled(true); extendedMetadata.setIdpDiscoveryEnabled(true);
extendedMetadata.setIdpDiscoveryURL(identityProviderDiscoveryUrl);
extendedMetadata.setIdpDiscoveryResponseURL(identityProviderDiscoveryResponseUrl);
extendedMetadata.setSignMetadata(true); extendedMetadata.setSignMetadata(true);
extendedMetadata.setEcpEnabled(true); extendedMetadata.setEcpEnabled(true);
return extendedMetadata; return extendedMetadata;
...@@ -360,23 +318,23 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -360,23 +318,23 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
/* Entry point to initialize authentication, default values taken from properties file */ /* Entry point to initialize authentication, default values taken from properties file */
@Bean @Bean
public SAMLEntryPoint samlEntryPoint() { public SAMLEntryPoint samlEntryPoint() {
SAMLEntryPoint samlEntryPoint = new SAMLEntryPoint(); final SAMLEntryPoint samlEntryPoint = new SAMLEntryPoint();
samlEntryPoint.setDefaultProfileOptions(defaultWebSSOProfileOptions()); samlEntryPoint.setDefaultProfileOptions(defaultWebSSOProfileOptions());
return samlEntryPoint; return samlEntryPoint;
} }
@Bean @Bean
public WebSSOProfileOptions defaultWebSSOProfileOptions() { public WebSSOProfileOptions defaultWebSSOProfileOptions() {
WebSSOProfileOptions webSSOProfileOptions = new WebSSOProfileOptions(); final WebSSOProfileOptions webSSOProfileOptions = new WebSSOProfileOptions();
webSSOProfileOptions.setIncludeScoping(false); webSSOProfileOptions.setIncludeScoping(false);
return webSSOProfileOptions; return webSSOProfileOptions;
} }
@Bean @Bean
public KeyManager keyManager() { public KeyManager keyManager() {
DefaultResourceLoader loader = new DefaultResourceLoader(); final DefaultResourceLoader loader = new DefaultResourceLoader();
Resource storeFile = loader.getResource(samlKeystoreLocation); final Resource storeFile = loader.getResource(samlKeystoreLocation);
Map<String, String> passwords = new HashMap<>(); final Map<String, String> passwords = new HashMap<>();
passwords.put(samlKeystoreAlias, samlKeystorePassword); passwords.put(samlKeystoreAlias, samlKeystorePassword);
return new JKSKeyManager(storeFile, samlKeystorePassword, passwords, samlKeystoreAlias); return new JKSKeyManager(storeFile, samlKeystorePassword, passwords, samlKeystoreAlias);
} }
...@@ -429,8 +387,8 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali ...@@ -429,8 +387,8 @@ public class SamlConfig extends WebSecurityConfigurerAdapter implements Initiali
/* SAML Authentication Provider responsible for validating of received SAML messages */ /* SAML Authentication Provider responsible for validating of received SAML messages */
@Bean @Bean
public SAMLAuthenticationProvider samlAuthenticationProvider() { public SAMLAuthenticationProvider samlAuthenticationProvider() {
SAMLAuthenticationProvider samlAuthenticationProvider = new SAMLAuthenticationProvider(); final SAMLAuthenticationProvider samlAuthenticationProvider = new SAMLAuthenticationProvider();
samlAuthenticationProvider.setUserDetails(userService); // samlAuthenticationProvider.setUserDetails(userService);
samlAuthenticationProvider.setForcePrincipalAsString(false); samlAuthenticationProvider.setForcePrincipalAsString(false);
return samlAuthenticationProvider; return samlAuthenticationProvider;
} }
......
package at.tuwien.service;
import lombok.extern.log4j.Log4j2;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.saml.SAMLCredential;
import org.springframework.security.saml.userdetails.SAMLUserDetailsService;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Log4j2
@Service
public class UserService implements SAMLUserDetailsService {
@Override
public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException {
final String userID = credential.getNameID().getValue();
log.debug("Logged in user {}", userID);
List<GrantedAuthority> authorities = new ArrayList<>();
GrantedAuthority authority = new SimpleGrantedAuthority("ROLE_USER");
authorities.add(authority);
return new User(userID, "<abc123>", true, true, true, true, authorities);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment