|
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.Arrays; |
5 | 5 | import java.util.Collection; |
| 6 | +import java.util.HashMap; |
6 | 7 | import java.util.List; |
| 8 | +import java.util.Map; |
7 | 9 | import java.util.Timer; |
8 | 10 |
|
9 | 11 | import javax.inject.Inject; |
|
22 | 24 | import org.springframework.context.annotation.Configuration; |
23 | 25 | import org.springframework.context.annotation.Lazy; |
24 | 26 | import org.springframework.core.env.Environment; |
| 27 | +import org.springframework.core.io.FileSystemResource; |
| 28 | +import org.springframework.core.io.Resource; |
25 | 29 | import org.springframework.security.authentication.AuthenticationManager; |
26 | 30 | import org.springframework.security.core.GrantedAuthority; |
27 | 31 | import org.springframework.security.core.authority.SimpleGrantedAuthority; |
|
34 | 38 | import org.springframework.security.saml.SAMLProcessingFilter; |
35 | 39 | import org.springframework.security.saml.context.SAMLContextProviderImpl; |
36 | 40 | import org.springframework.security.saml.key.EmptyKeyManager; |
| 41 | +import org.springframework.security.saml.key.JKSKeyManager; |
37 | 42 | import org.springframework.security.saml.key.KeyManager; |
38 | 43 | import org.springframework.security.saml.log.SAMLDefaultLogger; |
39 | 44 | import org.springframework.security.saml.metadata.CachingMetadataManager; |
@@ -100,13 +105,19 @@ public WebSSOProfile webSSOprofile() { |
100 | 105 |
|
101 | 106 | @Bean |
102 | 107 | 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 | + } |
110 | 121 | } |
111 | 122 |
|
112 | 123 | @Bean |
@@ -243,12 +254,7 @@ public WebSSOProfileConsumerHoKImpl hokWebSSOprofileConsumer() { |
243 | 254 | public SAMLFilterSet samlFilter() throws Exception { |
244 | 255 | List<SecurityFilterChain> chains = new ArrayList<SecurityFilterChain>(); |
245 | 256 | chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"), samlEntryPoint())); |
246 | | -// chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"), samlLogoutFilter())); |
247 | 257 | 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())); |
252 | 258 | return new SAMLFilterSet(chains); |
253 | 259 | } |
254 | 260 |
|
|
0 commit comments