use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class LdapProviderBeanDefinitionParserTests method simpleProviderAuthenticatesCorrectly.
@Test
public void simpleProviderAuthenticatesCorrectly() {
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath:test-server.ldif' port='0'/>" + "<authentication-manager>" + " <ldap-authentication-provider group-search-filter='member={0}' />" + "</authentication-manager>");
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER, AuthenticationManager.class);
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("ben", "benspassword"));
UserDetails ben = (UserDetails) auth.getPrincipal();
assertThat(ben.getAuthorities()).hasSize(3);
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class LdapProviderBeanDefinitionParserTests method multipleProvidersAreSupported.
@Test
public void multipleProvidersAreSupported() {
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath:test-server.ldif' port='0'/>" + "<authentication-manager>" + " <ldap-authentication-provider group-search-filter='member={0}' />" + " <ldap-authentication-provider group-search-filter='uniqueMember={0}' />" + "</authentication-manager>");
ProviderManager providerManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER, ProviderManager.class);
assertThat(providerManager.getProviders()).hasSize(2);
assertThat(providerManager.getProviders()).extracting("authoritiesPopulator.groupSearchFilter").containsExactly("member={0}", "uniqueMember={0}");
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class LdapProviderBeanDefinitionParserTests method supportsPasswordComparisonAuthenticationWithPasswordEncoder.
@Test
public void supportsPasswordComparisonAuthenticationWithPasswordEncoder() {
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-attribute='uid'>" + " <password-encoder ref='passwordEncoder' />" + " </password-compare>" + " </ldap-authentication-provider>" + "</authentication-manager>" + "<b:bean id='passwordEncoder' class='org.springframework.security.crypto.password.NoOpPasswordEncoder' factory-method='getInstance' />");
AuthenticationManager authenticationManager = this.appCtx.getBean(BeanIds.AUTHENTICATION_MANAGER, AuthenticationManager.class);
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("ben", "ben"));
assertThat(auth).isNotNull();
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class AuthenticationProviderBeanDefinitionParserTests method providerWithMd5PasswordEncoderWorks.
@Test
public void providerWithMd5PasswordEncoderWorks() {
// @formatter:off
this.appContext = new InMemoryXmlApplicationContext(" <authentication-manager>" + " <authentication-provider>" + " <password-encoder ref='passwordEncoder'/>" + " <user-service>" + " <user name='bob' password='12b141f35d58b8b3a46eea65e6ac179e' authorities='ROLE_A' />" + " </user-service>" + " </authentication-provider>" + " </authentication-manager>" + " <b:bean id='passwordEncoder' class='" + MessageDigestPasswordEncoder.class.getName() + "'>" + " <b:constructor-arg value='MD5'/>" + " </b:bean>");
// @formatter:on
getProvider().authenticate(this.bob);
}
use of org.springframework.security.config.util.InMemoryXmlApplicationContext in project spring-security by spring-projects.
the class AuthenticationProviderBeanDefinitionParserTests method providerWithShaPasswordEncoderWorks.
@Test
public void providerWithShaPasswordEncoderWorks() {
// @formatter:off
this.appContext = new InMemoryXmlApplicationContext(" <authentication-manager>" + " <authentication-provider>" + " <password-encoder ref='passwordEncoder'/>" + " <user-service>" + " <user name='bob' password='{SSHA}PpuEwfdj7M1rs0C2W4ssSM2XEN/Y6S5U' authorities='ROLE_A' />" + " </user-service>" + " </authentication-provider>" + " </authentication-manager>" + " <b:bean id='passwordEncoder' class='" + LdapShaPasswordEncoder.class.getName() + "'/>");
// @formatter:on
getProvider().authenticate(this.bob);
}
Aggregations