Search in sources :

Example 6 with SecurityProperties

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

the class EndpointLdapAuthenticationProviderDefaultRolesTests 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);
    assertThrows(InsufficientAuthenticationException.class, () -> provider.authenticate(new UsernamePasswordAuthenticationToken("authzcas", null)));
    val token = provider.authenticate(new UsernamePasswordAuthenticationToken("authzcas", "123456"));
    assertNotNull(token);
}
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 7 with SecurityProperties

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

the class EndpointLdapAuthenticationProviderRolesBasedTests method verifyUserNotFound.

@Test
public void verifyUserNotFound() {
    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(InsufficientAuthenticationException.class, () -> provider.authenticate(new UsernamePasswordAuthenticationToken("UNKNOWN_USER", "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 8 with SecurityProperties

use of org.springframework.boot.autoconfigure.security.SecurityProperties in project spring-boot by spring-projects.

the class ReactiveUserDetailsServiceAutoConfiguration method reactiveUserDetailsService.

@Bean
public MapReactiveUserDetailsService reactiveUserDetailsService(SecurityProperties properties, ObjectProvider<PasswordEncoder> passwordEncoder) {
    SecurityProperties.User user = properties.getUser();
    UserDetails userDetails = getUserDetails(user, getOrDeducePassword(user, passwordEncoder.getIfAvailable()));
    return new MapReactiveUserDetailsService(userDetails);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) SecurityProperties(org.springframework.boot.autoconfigure.security.SecurityProperties) MapReactiveUserDetailsService(org.springframework.security.core.userdetails.MapReactiveUserDetailsService) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

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