Skip to content

Commit 6a05511

Browse files
committed
SAML: added support for encrypted assertions
1 parent bce5d3a commit 6a05511

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/auth/impl/saml/SAMLConfiguration.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import java.util.ArrayList;
44
import java.util.Arrays;
55
import java.util.Collection;
6+
import java.util.HashMap;
67
import java.util.List;
8+
import java.util.Map;
79
import java.util.Timer;
810

911
import javax.inject.Inject;
@@ -22,6 +24,8 @@
2224
import org.springframework.context.annotation.Configuration;
2325
import org.springframework.context.annotation.Lazy;
2426
import org.springframework.core.env.Environment;
27+
import org.springframework.core.io.FileSystemResource;
28+
import org.springframework.core.io.Resource;
2529
import org.springframework.security.authentication.AuthenticationManager;
2630
import org.springframework.security.core.GrantedAuthority;
2731
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -34,6 +38,7 @@
3438
import org.springframework.security.saml.SAMLProcessingFilter;
3539
import org.springframework.security.saml.context.SAMLContextProviderImpl;
3640
import org.springframework.security.saml.key.EmptyKeyManager;
41+
import org.springframework.security.saml.key.JKSKeyManager;
3742
import org.springframework.security.saml.key.KeyManager;
3843
import org.springframework.security.saml.log.SAMLDefaultLogger;
3944
import org.springframework.security.saml.metadata.CachingMetadataManager;
@@ -100,13 +105,19 @@ public WebSSOProfile webSSOprofile() {
100105

101106
@Bean
102107
public KeyManager keyManager() {
103-
return new EmptyKeyManager();
104-
//TODO A keystore can optionally be used to (1) verify IDP response and (2) sign auth requests
105-
// ClassPathResource storeFile = new ClassPathResource("/saml-keystore.jks");
106-
// String storePass = "samlstorepass";
107-
// Map<String, String> passwords = new HashMap<>();
108-
// passwords.put("mykeyalias", "mykeypass");
109-
// return new JKSKeyManager(storeFile, storePass, passwords, "mykeyalias");
108+
String keystore = environment.getProperty("proxy.saml.keystore");
109+
if (keystore == null || keystore.isEmpty()) {
110+
return new EmptyKeyManager();
111+
} else {
112+
String certName = environment.getProperty("proxy.saml.encryption-cert-name");
113+
String certPW = environment.getProperty("proxy.saml.encryption-cert-password");
114+
String keystorePW = environment.getProperty("proxy.saml.keystore-password", certPW);
115+
116+
Resource keystoreFile = new FileSystemResource(keystore);
117+
Map<String, String> passwords = new HashMap<>();
118+
passwords.put(certName, certPW);
119+
return new JKSKeyManager(keystoreFile, keystorePW, passwords, certName);
120+
}
110121
}
111122

112123
@Bean
@@ -243,12 +254,7 @@ public WebSSOProfileConsumerHoKImpl hokWebSSOprofileConsumer() {
243254
public SAMLFilterSet samlFilter() throws Exception {
244255
List<SecurityFilterChain> chains = new ArrayList<SecurityFilterChain>();
245256
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"), samlEntryPoint()));
246-
// chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"), samlLogoutFilter()));
247257
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"), samlWebSSOProcessingFilter()));
248-
// chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/metadata/**"), metadataDisplayFilter()));
249-
// chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSOHoK/**"), samlWebSSOHoKProcessingFilter()));
250-
// chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"), samlLogoutProcessingFilter()));
251-
// chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"), samlIDPDiscovery()));
252258
return new SAMLFilterSet(chains);
253259
}
254260

0 commit comments

Comments
 (0)