org.springframework.security.saml.key.KeyManager Java Examples
The following examples show how to use
org.springframework.security.saml.key.KeyManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InsightsSecurityConfigurationAdapterSAML.java From Insights with Apache License 2.0 | 7 votes |
/** * Used to load .Jks file * * @return */ @Bean @Conditional(InsightsSAMLBeanInitializationCondition.class) public KeyManager keyManager() { Resource storeFile = resourceLoaderService.getResource("file:" + singleSignOnConfig.getKeyStoreFilePath()); Map<String, String> passwords = new HashMap<>(); passwords.put(singleSignOnConfig.getKeyAlias(), singleSignOnConfig.getKeyPass()); return new JKSKeyManager(storeFile, singleSignOnConfig.getKeyStorePass(), passwords, singleSignOnConfig.getKeyAlias()); }
Example #2
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 6 votes |
@Test(expected = IllegalArgumentException.class) public void testArguments_der_and_pem_error() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer .publicKeyPEMLocation("classpath:localhost.cert") .privateKeyDERLocation("classpath:localhost.key.der"); configurer.init(builder); configurer.configure(builder); ArgumentCaptor<KeyManager> providerCaptor = ArgumentCaptor.forClass(KeyManager.class); verify(builder).setSharedObject(eq(KeyManager.class), providerCaptor.capture()); verify(keyManagerProperties, never()).getDefaultKey(); verify(keyManagerProperties, never()).getKeyPasswords(); verify(keyManagerProperties, never()).getPrivateKeyDerLocation(); verify(keyManagerProperties, never()).getPublicKeyPemLocation(); verify(keyManagerProperties).getStoreLocation(); verify(keyManagerProperties).getStorePass(); assertThat(providerCaptor.getValue()).isNotNull(); KeyManager keyManager = providerCaptor.getValue(); assertThat(keyManager.getAvailableCredentials()).containsExactly("localhost"); assertThat(keyManager.getDefaultCredential().getEntityId()).isEqualTo("localhost"); assertThat(keyManager.getDefaultCredentialName()).isEqualTo("localhost"); }
Example #3
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 6 votes |
@Test public void testArguments_der_and_pem() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer .publicKeyPEMLocation("classpath:localhost.cert") .privateKeyDERLocation("classpath:localhost.key.der") .defaultKey("localhost") .keyPassword("localhost", ""); configurer.init(builder); configurer.configure(builder); ArgumentCaptor<KeyManager> providerCaptor = ArgumentCaptor.forClass(KeyManager.class); verify(builder).setSharedObject(eq(KeyManager.class), providerCaptor.capture()); verify(keyManagerProperties, never()).getDefaultKey(); verify(keyManagerProperties, never()).getKeyPasswords(); verify(keyManagerProperties, never()).getPrivateKeyDerLocation(); verify(keyManagerProperties, never()).getPublicKeyPemLocation(); verify(keyManagerProperties).getStoreLocation(); verify(keyManagerProperties).getStorePass(); assertThat(providerCaptor.getValue()).isNotNull(); KeyManager keyManager = providerCaptor.getValue(); assertThat(keyManager.getAvailableCredentials()).containsExactly("localhost"); assertThat(keyManager.getDefaultCredential().getEntityId()).isEqualTo("localhost"); assertThat(keyManager.getDefaultCredentialName()).isEqualTo("localhost"); }
Example #4
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 6 votes |
@Test public void testArguments_keystore_location() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer .storeLocation("classpath:KeyStore.jks") .storePass("password") .defaultKey("default") .keyPassword("default", "password"); configurer.init(builder); configurer.configure(builder); ArgumentCaptor<KeyManager> providerCaptor = ArgumentCaptor.forClass(KeyManager.class); verify(builder).setSharedObject(eq(KeyManager.class), providerCaptor.capture()); verify(keyManagerProperties, never()).getDefaultKey(); verify(keyManagerProperties, never()).getKeyPasswords(); verify(keyManagerProperties, never()).getStoreLocation(); verify(keyManagerProperties, never()).getStorePass(); verify(keyManagerProperties).getPrivateKeyDerLocation(); verify(keyManagerProperties).getPublicKeyPemLocation(); assertThat(providerCaptor.getValue()).isNotNull(); KeyManager keyManager = providerCaptor.getValue(); assertThat(keyManager.getAvailableCredentials()).containsExactly("default"); assertThat(keyManager.getDefaultCredential().getEntityId()).isEqualTo("default"); assertThat(keyManager.getDefaultCredentialName()).isEqualTo("default"); }
Example #5
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 6 votes |
@Test public void testArguments_keystore() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer .keyStore(new KeystoreFactory(new DefaultResourceLoader()).createEmptyKeystore()); configurer.init(builder); configurer.configure(builder); ArgumentCaptor<KeyManager> providerCaptor = ArgumentCaptor.forClass(KeyManager.class); verify(builder).setSharedObject(eq(KeyManager.class), providerCaptor.capture()); verify(keyManagerProperties).getDefaultKey(); verify(keyManagerProperties).getKeyPasswords(); verify(keyManagerProperties).getPrivateKeyDerLocation(); verify(keyManagerProperties).getPublicKeyPemLocation(); verify(keyManagerProperties).getStoreLocation(); verify(keyManagerProperties).getStorePass(); assertThat(providerCaptor.getValue()).isNotNull(); KeyManager keyManager = providerCaptor.getValue(); assertThat(keyManager.getAvailableCredentials()).isEmpty(); }
Example #6
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 6 votes |
@Before public void setup() { SAMLSSOProperties properties = mock(SAMLSSOProperties.class); keyManagerProperties = mock(KeyManagerProperties.class); when(properties.getKeyManager()).thenReturn(keyManagerProperties); // when(keyManagerProperties.getDefaultKey()).thenReturn("default"); // when(keyManagerProperties.getKeyPasswords()).thenReturn(Collections.singletonMap("default", "password")); // when(keyManagerProperties.getPrivateKeyDerLocation()).thenReturn("classpath:localhost:key.der"); // when(keyManagerProperties.getPublicKeyPemLocation()).thenReturn("classpath:localhost.cert"); // when(keyManagerProperties.getStoreLocation()).thenReturn("classpath:KeyStore.jks"); // when(keyManagerProperties.getStorePass()).thenReturn("storePass"); builder = mock(ServiceProviderBuilder.class); when(builder.getSharedObject(KeyManager.class)).thenReturn(null); when(builder.getSharedObject(SAMLSSOProperties.class)).thenReturn(properties); when(builder.getSharedObject(ResourceLoader.class)).thenReturn(new DefaultResourceLoader()); }
Example #7
Source File: WebSecurityConfig.java From spring-boot-security-saml-sample with Apache License 2.0 | 5 votes |
@Bean public KeyManager keyManager() { DefaultResourceLoader loader = new DefaultResourceLoader(); Resource storeFile = loader .getResource("classpath:/saml/samlKeystore.jks"); String storePass = "nalle123"; Map<String, String> passwords = new HashMap<String, String>(); passwords.put("apollo", "nalle123"); String defaultKey = "apollo"; return new JKSKeyManager(storeFile, storePass, passwords, defaultKey); }
Example #8
Source File: SAMLConfig.java From spring-boot-security-saml-samples with MIT License | 5 votes |
@Bean public MetadataGenerator metadataGenerator(KeyManager keyManager) { MetadataGenerator generator = new MetadataGenerator(); generator.setEntityId("localhost-demo"); generator.setExtendedMetadata(extendedMetadata()); generator.setIncludeDiscoveryExtension(false); generator.setKeyManager(keyManager); return generator; }
Example #9
Source File: WebSecurityConfig.java From spring-tsers-auth with Apache License 2.0 | 5 votes |
@Bean public KeyManager keyManager() { DefaultResourceLoader loader = new DefaultResourceLoader(); Resource storeFile = loader .getResource("classpath:/saml/samlKeystore.jks"); String storePass = "nalle123"; Map<String, String> passwords = new HashMap<String, String>(); passwords.put("apollo", "nalle123"); String defaultKey = "apollo"; return new JKSKeyManager(storeFile, storePass, passwords, defaultKey); }
Example #10
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 5 votes |
@Test public void testProperties() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer.init(builder); configurer.configure(builder); ArgumentCaptor<KeyManager> providerCaptor = ArgumentCaptor.forClass(KeyManager.class); verify(builder).setSharedObject(eq(KeyManager.class), providerCaptor.capture()); assertThat(providerCaptor.getValue()).isNotNull(); KeyManager keyManager = providerCaptor.getValue(); assertThat(keyManager).isExactlyInstanceOf(EmptyKeyManager.class); }
Example #11
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 5 votes |
@Test public void configure_forConstructor() throws Exception { KeyManager keyManager = mock(KeyManager.class); KeyManagerConfigurer configurer = new KeyManagerConfigurer(keyManager); configurer.init(builder); configurer.configure(builder); verify(builder).setSharedObject(eq(KeyManager.class), eq(keyManager)); verifyZeroInteractions(keyManager, keyManagerProperties); }
Example #12
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 5 votes |
@Test public void configure_forBean() throws Exception { KeyManager keyManager = mock(KeyManager.class); when(builder.getSharedObject(KeyManager.class)).thenReturn(keyManager); KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer.init(builder); configurer.configure(builder); verify(builder, never()).setSharedObject(any(), any()); verifyZeroInteractions(keyManager, keyManagerProperties); }
Example #13
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 5 votes |
@Test public void configure() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer.init(builder); configurer.configure(builder); verify(builder).setSharedObject(eq(KeyManager.class), any(KeyManager.class)); }
Example #14
Source File: KeyManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 5 votes |
@Test public void init() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer.init(builder); verify(builder).getSharedObject(eq(KeyManager.class)); verify(builder).getSharedObject(eq(SAMLSSOProperties.class)); }
Example #15
Source File: SAMLServiceProviderSecurityConfiguration.java From spring-boot-security-saml with MIT License | 5 votes |
@Override public void afterPropertiesSet() { //All existing beans are thrown as shared objects to the ServiceProviderSecurityBuilder, which will wire all //beans/objects related to spring security SAML. serviceProviderBuilder.setSharedObject(ParserPool.class, ParserPoolHolder.getPool()); serviceProviderBuilder.setSharedObject(WebSSOProfileConsumerImpl.class, (WebSSOProfileConsumerImpl) webSSOProfileConsumer); serviceProviderBuilder.setSharedObject(WebSSOProfileConsumerHoKImpl.class, hokWebSSOProfileConsumer); serviceProviderBuilder.setSharedObject(ServiceProviderEndpoints.class, new ServiceProviderEndpoints()); serviceProviderBuilder.setSharedObject(ResourceLoader.class, resourceLoader); serviceProviderBuilder.setSharedObject(SAMLSSOProperties.class, sAMLSsoProperties); serviceProviderBuilder.setSharedObject(ExtendedMetadata.class, extendedMetadata); serviceProviderBuilder.setSharedObject(LocalExtendedMetadata.class, localExtendedMetadata); serviceProviderBuilder.setSharedObject(SAMLAuthenticationProvider.class, samlAuthenticationProvider); serviceProviderBuilder.setSharedObject(SAMLContextProvider.class, samlContextProvider); serviceProviderBuilder.setSharedObject(KeyManager.class, keyManager); serviceProviderBuilder.setSharedObject(MetadataManager.class, metadataManager); serviceProviderBuilder.setSharedObject(MetadataGenerator.class, metadataGenerator); serviceProviderBuilder.setSharedObject(SAMLProcessor.class, samlProcessor); serviceProviderBuilder.setSharedObject(WebSSOProfile.class, webSSOProfile); serviceProviderBuilder.setSharedObject(WebSSOProfileECPImpl.class, ecpProfile); serviceProviderBuilder.setSharedObject(WebSSOProfileHoKImpl.class, hokWebSSOProfile); serviceProviderBuilder.setSharedObject(SingleLogoutProfile.class, sloProfile); serviceProviderBuilder.setSharedObject(WebSSOProfileConsumer.class, webSSOProfileConsumer); serviceProviderBuilder.setSharedObject(WebSSOProfileConsumerHoKImpl.class, hokWebSSOProfileConsumer); serviceProviderBuilder.setSharedObject(SAMLLogger.class, samlLogger); serviceProviderBuilder.setSharedObject(ApplicationEventPublisher.class, eventPublisher); }
Example #16
Source File: KeyManagerConfigurer.java From spring-boot-security-saml with MIT License | 5 votes |
@Override public void init(ServiceProviderBuilder builder) throws Exception { keyManagerBean = builder.getSharedObject(KeyManager.class); config = builder.getSharedObject(SAMLSSOProperties.class).getKeyManager(); resourceLoader = builder.getSharedObject(ResourceLoader.class); keystoreFactory = new KeystoreFactory(resourceLoader); }
Example #17
Source File: TLSConfigurer.java From spring-boot-security-saml with MIT License | 5 votes |
@Override public void configure(ServiceProviderBuilder builder) throws Exception { KeyManager keyManager = builder.getSharedObject(KeyManager.class); TLSProtocolConfigurer configurer = createDefaultTlsProtocolConfigurer(); configurer.setProtocolName(Optional.ofNullable(protocolName).orElseGet(config::getProtocolName)); configurer.setProtocolPort(Optional.ofNullable(protocolPort).orElseGet(config::getProtocolPort)); configurer.setSslHostnameVerification(Optional.ofNullable(sslHostnameVerification).orElseGet(config::getSslHostnameVerification)); configurer.setTrustedKeys(Optional.ofNullable(trustedKeys).orElseGet(config::getTrustedKeys)); configurer.setKeyManager(keyManager); configurer.afterPropertiesSet(); builder.setSharedObject(TLSProtocolConfigurer.class, configurer); }
Example #18
Source File: DSLSAMLContextProviderLB.java From spring-boot-security-saml with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override @Autowired(required = false) public void setKeyManager(KeyManager keyManager) { super.setKeyManager(keyManager); }
Example #19
Source File: KeyManagerConfigurer.java From spring-boot-security-saml with MIT License | 4 votes |
public KeyManagerConfigurer(KeyManager keyManager) { this.keyManager = keyManager; }
Example #20
Source File: SAMLConfig.java From spring-boot-security-saml-samples with MIT License | 4 votes |
@Bean public KeyManager keyManager(KeystoreFactory keystoreFactory) { KeyStore keystore = keystoreFactory.loadKeystore("classpath:/localhost.cert", "classpath:/localhost.key.der", "localhost", ""); return new JKSKeyManager(keystore, ImmutableMap.of("localhost", ""), "localhost"); }
Example #21
Source File: SAMLConfig.java From spring-boot-security-saml-samples with MIT License | 4 votes |
@Bean public TLSProtocolConfigurer tlsProtocolConfigurer(KeyManager keyManager) { TLSProtocolConfigurer configurer = new TLSProtocolConfigurer(); configurer.setKeyManager(keyManager); return configurer; }
Example #22
Source File: AuthenticationHandler.java From blackduck-alert with Apache License 2.0 | 4 votes |
@Bean public KeyManager keyManager() { return new EmptyKeyManager(); }
Example #23
Source File: DSLMetadataGenerator.java From spring-boot-security-saml with MIT License | 2 votes |
/** * Key manager provides information about private certificate and trusted keys provide in addition to * cryptographic material present in entity metadata documents. * * @param keyManager key manager */ @Override @Autowired(required = false) public void setKeyManager(KeyManager keyManager) { super.setKeyManager(keyManager); }
Example #24
Source File: DSLMetadataManager.java From spring-boot-security-saml with MIT License | 2 votes |
/** * Key manager provides information about private certificate and trusted keys provide in addition to * cryptographic material present in entity metadata documents. * * @param keyManager key manager */ @Override @Autowired(required = false) public void setKeyManager(KeyManager keyManager) { super.setKeyManager(keyManager); }
Example #25
Source File: DSLSAMLContextProviderImpl.java From spring-boot-security-saml with MIT License | 2 votes |
/** * Key manager provides information about private certificate and trusted keys provide in addition to * cryptographic material present in entity metadata documents. * * @param keyManager key manager */ @Override @Autowired(required = false) public void setKeyManager(KeyManager keyManager) { super.setKeyManager(keyManager); }