Search in sources :

Example 1 with AuthenticationSource

use of org.springframework.ldap.core.AuthenticationSource 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");
}
Also used : SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AuthenticationSource(org.springframework.ldap.core.AuthenticationSource) Test(org.junit.jupiter.api.Test)

Example 2 with AuthenticationSource

use of org.springframework.ldap.core.AuthenticationSource 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");
}
Also used : DistinguishedName(org.springframework.ldap.core.DistinguishedName) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) LdapUserDetailsImpl(org.springframework.security.ldap.userdetails.LdapUserDetailsImpl) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AuthenticationSource(org.springframework.ldap.core.AuthenticationSource) Test(org.junit.jupiter.api.Test)

Example 3 with AuthenticationSource

use of org.springframework.ldap.core.AuthenticationSource 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("");
}
Also used : SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AuthenticationSource(org.springframework.ldap.core.AuthenticationSource) Test(org.junit.jupiter.api.Test)

Example 4 with AuthenticationSource

use of org.springframework.ldap.core.AuthenticationSource 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("");
}
Also used : SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AuthenticationSource(org.springframework.ldap.core.AuthenticationSource) Test(org.junit.jupiter.api.Test)

Example 5 with AuthenticationSource

use of org.springframework.ldap.core.AuthenticationSource in project spring-security by spring-projects.

the class SpringSecurityAuthenticationSourceTests method getPrincipalRejectsNonLdapUserDetailsObject.

@Test
public void getPrincipalRejectsNonLdapUserDetailsObject() {
    AuthenticationSource source = new SpringSecurityAuthenticationSource();
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new Object(), "password"));
    assertThatIllegalArgumentException().isThrownBy(source::getPrincipal);
}
Also used : SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AuthenticationSource(org.springframework.ldap.core.AuthenticationSource) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 AuthenticationSource (org.springframework.ldap.core.AuthenticationSource)5 SpringSecurityAuthenticationSource (org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource)5 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3 DistinguishedName (org.springframework.ldap.core.DistinguishedName)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 LdapUserDetailsImpl (org.springframework.security.ldap.userdetails.LdapUserDetailsImpl)1