use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class AuthenticationProviderBeanDefinitionParserTests method externalUserServicePasswordEncoderAndSaltSourceWork.
@Test
public void externalUserServicePasswordEncoderAndSaltSourceWork() throws Exception {
appContext = new InMemoryXmlApplicationContext(" <authentication-manager>" + " <authentication-provider user-service-ref='customUserService'>" + " <password-encoder ref='customPasswordEncoder'>" + " <salt-source ref='saltSource'/>" + " </password-encoder>" + " </authentication-provider>" + " </authentication-manager>" + " <b:bean id='customPasswordEncoder' " + "class='org.springframework.security.authentication.encoding.Md5PasswordEncoder'/>" + " <b:bean id='saltSource' " + " class='" + ReflectionSaltSource.class.getName() + "'>" + " <b:property name='userPropertyToUse' value='username'/>" + " </b:bean>" + " <b:bean id='customUserService' " + " class='org.springframework.security.provisioning.InMemoryUserDetailsManager'>" + " <b:constructor-arg>" + " <b:props>" + " <b:prop key='bob'>f117f0862384e9497ff4f470e3522606,ROLE_A</b:prop>" + " </b:props>" + " </b:constructor-arg>" + " </b:bean>");
getProvider().authenticate(bob);
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class LdapProviderBeanDefinitionParserTests method supportsPasswordComparisonAuthentication.
@Test
public void supportsPasswordComparisonAuthentication() {
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath:test-server.ldif' port='0'/>" + "<authentication-manager>" + " <ldap-authentication-provider user-dn-pattern='uid={0},ou=people'>" + " <password-compare />" + " </ldap-authentication-provider>" + "</authentication-manager>");
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER, AuthenticationManager.class);
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("ben", "benspassword"));
assertThat(auth).isNotNull();
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class LdapProviderBeanDefinitionParserTests method inetOrgContextMapperIsSupported.
@Test
public void inetOrgContextMapperIsSupported() {
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server url='ldap://127.0.0.1:343/dc=springframework,dc=org' port='0'/>" + "<authentication-manager>" + " <ldap-authentication-provider user-details-class='inetOrgPerson' />" + "</authentication-manager>");
ProviderManager providerManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER, ProviderManager.class);
assertThat(providerManager.getProviders()).hasSize(1);
assertThat(providerManager.getProviders()).extracting("userDetailsContextMapper").allSatisfy((contextMapper) -> assertThat(contextMapper).isInstanceOf(InetOrgPersonContextMapper.class));
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class LdapProviderBeanDefinitionParserTests method supportsCryptoPasswordEncoder.
// SEC-2472
@Test
public void supportsCryptoPasswordEncoder() {
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath:test-server.ldif' port='0'/>" + "<authentication-manager>" + " <ldap-authentication-provider user-dn-pattern='uid={0},ou=people'>" + " <password-compare>" + " <password-encoder ref='pe' />" + " </password-compare>" + " </ldap-authentication-provider>" + "</authentication-manager>" + "<b:bean id='pe' class='org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' />");
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER, AuthenticationManager.class);
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("bcrypt", "password"));
assertThat(auth).isNotNull();
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class LdapProviderBeanDefinitionParserTests method ldapAuthenticationProviderWorksWithPlaceholders.
@Test
public void ldapAuthenticationProviderWorksWithPlaceholders() {
System.setProperty("udp", "people");
System.setProperty("gsf", "member");
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server />" + "<authentication-manager>" + " <ldap-authentication-provider user-dn-pattern='uid={0},ou=${udp}' group-search-filter='${gsf}={0}' />" + "</authentication-manager>" + "<b:bean id='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer' class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer' />");
ProviderManager providerManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER, ProviderManager.class);
assertThat(providerManager.getProviders()).hasSize(1);
AuthenticationProvider authenticationProvider = providerManager.getProviders().get(0);
assertThat(authenticationProvider).extracting("authenticator.userDnFormat").satisfies((messageFormats) -> assertThat(messageFormats).isEqualTo(new MessageFormat[] { new MessageFormat("uid={0},ou=people") }));
assertThat(authenticationProvider).extracting("authoritiesPopulator.groupSearchFilter").satisfies((searchFilter) -> assertThat(searchFilter).isEqualTo("member={0}"));
}
Aggregations