use of org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource in project spring-security by spring-projects.
the class SpringSecurityAuthenticationSourceTests method expectedPrincipalIsReturned.
@Test
public void expectedPrincipalIsReturned() {
LdapUserDetailsImpl.Essence user = new LdapUserDetailsImpl.Essence();
user.setUsername("joe");
user.setDn(new DistinguishedName("uid=joe,ou=users"));
AuthenticationSource source = new SpringSecurityAuthenticationSource();
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(user.createUserDetails(), null));
assertThat(source.getPrincipal()).isEqualTo("uid=joe,ou=users");
}
use of org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource in project spring-security by spring-projects.
the class SpringSecurityAuthenticationSourceTests method expectedCredentialsAreReturned.
@Test
public void expectedCredentialsAreReturned() {
AuthenticationSource source = new SpringSecurityAuthenticationSource();
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new Object(), "password"));
assertThat(source.getCredentials()).isEqualTo("password");
}
use of org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource in project spring-security by spring-projects.
the class SpringSecurityAuthenticationSourceTests method principalAndCredentialsAreEmptyWithNoAuthentication.
@Test
public void principalAndCredentialsAreEmptyWithNoAuthentication() {
AuthenticationSource source = new SpringSecurityAuthenticationSource();
assertThat(source.getPrincipal()).isEqualTo("");
assertThat(source.getCredentials()).isEqualTo("");
}
use of org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource in project spring-security by spring-projects.
the class SpringSecurityAuthenticationSourceTests method principalIsEmptyForAnonymousUser.
@Test
public void principalIsEmptyForAnonymousUser() {
AuthenticationSource source = new SpringSecurityAuthenticationSource();
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("key", "anonUser", AuthorityUtils.createAuthorityList("ignored")));
assertThat(source.getPrincipal()).isEqualTo("");
}
use of org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource in project spring-security by spring-projects.
the class SpringSecurityAuthenticationSourceTests method getPrincipalRejectsNonLdapUserDetailsObject.
@Test(expected = IllegalArgumentException.class)
public void getPrincipalRejectsNonLdapUserDetailsObject() {
AuthenticationSource source = new SpringSecurityAuthenticationSource();
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new Object(), "password"));
source.getPrincipal();
}
Aggregations