Search in sources :

Example 1 with SecurityProperties

use of org.springframework.boot.autoconfigure.security.SecurityProperties in project cas by apereo.

the class EndpointLdapAuthenticationProviderGroupsBasedTests method verifyAuthorizedByGroup.

@Test
public void verifyAuthorizedByGroup() {
    val securityProperties = new SecurityProperties();
    securityProperties.getUser().setRoles(List.of("ROLE_888"));
    val ldap = casProperties.getMonitor().getEndpoints().getLdap();
    val connectionFactory = LdapUtils.newLdaptiveConnectionFactory(ldap);
    val authenticator = LdapUtils.newLdaptiveAuthenticator(ldap);
    val provider = new EndpointLdapAuthenticationProvider(ldap, securityProperties, connectionFactory, authenticator);
    assertNotNull(provider.authenticate(new UsernamePasswordAuthenticationToken("authzcas", "123456")));
    assertAll(provider::destroy);
}
Also used : lombok.val(lombok.val) SecurityProperties(org.springframework.boot.autoconfigure.security.SecurityProperties) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SecurityProperties

use of org.springframework.boot.autoconfigure.security.SecurityProperties in project cas by apereo.

the class EndpointLdapAuthenticationProviderDefaultRolesTests method verifyEmptyRoles.

@Test
public void verifyEmptyRoles() {
    val securityProperties = new SecurityProperties();
    securityProperties.getUser().setRoles(List.of());
    val ldap = casProperties.getMonitor().getEndpoints().getLdap();
    val connectionFactory = LdapUtils.newLdaptiveConnectionFactory(ldap);
    val authenticator = LdapUtils.newLdaptiveAuthenticator(ldap);
    val provider = new EndpointLdapAuthenticationProvider(ldap, securityProperties, connectionFactory, authenticator);
    val token = provider.authenticate(new UsernamePasswordAuthenticationToken("authzcas", "123456"));
    assertNotNull(token);
    assertTrue(token.getAuthorities().isEmpty());
}
Also used : lombok.val(lombok.val) SecurityProperties(org.springframework.boot.autoconfigure.security.SecurityProperties) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 3 with SecurityProperties

use of org.springframework.boot.autoconfigure.security.SecurityProperties in project cas by apereo.

the class EndpointLdapAuthenticationProviderRolesBasedTests method verifyAuthorizedByRole.

@Test
public void verifyAuthorizedByRole() {
    val securityProperties = new SecurityProperties();
    securityProperties.getUser().setRoles(List.of("ROLE_888"));
    val ldap = casProperties.getMonitor().getEndpoints().getLdap();
    val connectionFactory = LdapUtils.newLdaptiveConnectionFactory(ldap);
    val authenticator = LdapUtils.newLdaptiveAuthenticator(ldap);
    val provider = new EndpointLdapAuthenticationProvider(ldap, securityProperties, connectionFactory, authenticator);
    assertTrue(provider.supports(UsernamePasswordAuthenticationToken.class));
    val token = provider.authenticate(new UsernamePasswordAuthenticationToken("authzcas", "123456"));
    assertNotNull(token);
    assertAll(provider::destroy);
}
Also used : lombok.val(lombok.val) SecurityProperties(org.springframework.boot.autoconfigure.security.SecurityProperties) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 4 with SecurityProperties

use of org.springframework.boot.autoconfigure.security.SecurityProperties in project cas by apereo.

the class EndpointLdapAuthenticationProviderRolesBasedTests method verifyUnauthorizedByRole.

@Test
public void verifyUnauthorizedByRole() {
    val securityProperties = new SecurityProperties();
    securityProperties.getUser().setRoles(List.of("SOME_BAD_ROLE"));
    val ldap = casProperties.getMonitor().getEndpoints().getLdap();
    val connectionFactory = LdapUtils.newLdaptiveConnectionFactory(ldap);
    val authenticator = LdapUtils.newLdaptiveAuthenticator(ldap);
    val provider = new EndpointLdapAuthenticationProvider(ldap, securityProperties, connectionFactory, authenticator);
    assertThrows(BadCredentialsException.class, () -> provider.authenticate(new UsernamePasswordAuthenticationToken("authzcas", "123456")));
    assertAll(provider::destroy);
}
Also used : lombok.val(lombok.val) SecurityProperties(org.springframework.boot.autoconfigure.security.SecurityProperties) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 5 with SecurityProperties

use of org.springframework.boot.autoconfigure.security.SecurityProperties in project cas by apereo.

the class EndpointLdapAuthenticationProviderRolesBasedTests method verifyUserBadPassword.

@Test
public void verifyUserBadPassword() {
    val securityProperties = new SecurityProperties();
    securityProperties.getUser().setRoles(List.of("SOME_BAD_ROLE"));
    val ldap = casProperties.getMonitor().getEndpoints().getLdap();
    val connectionFactory = LdapUtils.newLdaptiveConnectionFactory(ldap);
    val authenticator = LdapUtils.newLdaptiveAuthenticator(ldap);
    val provider = new EndpointLdapAuthenticationProvider(ldap, securityProperties, connectionFactory, authenticator);
    assertThrows(BadCredentialsException.class, () -> provider.authenticate(new UsernamePasswordAuthenticationToken("authzcas", "BAD_PASSWORD")));
    assertAll(provider::destroy);
}
Also used : lombok.val(lombok.val) SecurityProperties(org.springframework.boot.autoconfigure.security.SecurityProperties) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityProperties (org.springframework.boot.autoconfigure.security.SecurityProperties)8 lombok.val (lombok.val)7 Test (org.junit.jupiter.api.Test)7 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)7 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Bean (org.springframework.context.annotation.Bean)1 MapReactiveUserDetailsService (org.springframework.security.core.userdetails.MapReactiveUserDetailsService)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1