Search in sources :

Example 96 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class BaseLdapAuthenticationHandlerTests method verifyAuthenticateSuccess.

@Test
public void verifyAuthenticateSuccess() {
    assertNotEquals(ldapAuthenticationHandlers.size(), 0);
    ldapAuthenticationHandlers.toList().forEach(Unchecked.consumer(h -> {
        val credential = new UsernamePasswordCredential(getUsername(), getSuccessPassword());
        val result = h.authenticate(credential);
        assertNotNull(result.getPrincipal());
        assertEquals(credential.getUsername(), result.getPrincipal().getId());
        val attributes = result.getPrincipal().getAttributes();
        Arrays.stream(getPrincipalAttributes()).forEach(s -> assertTrue(attributes.containsKey(s)));
    }));
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Arrays(java.util.Arrays) CasCoreAuthenticationConfiguration(org.apereo.cas.config.CasCoreAuthenticationConfiguration) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Autowired(org.springframework.beans.factory.annotation.Autowired) Assertions(org.apereo.cas.util.junit.Assertions) CasCoreConfiguration(org.apereo.cas.config.CasCoreConfiguration) UncheckedException(org.jooq.lambda.UncheckedException) CasWebApplicationServiceFactoryConfiguration(org.apereo.cas.config.support.CasWebApplicationServiceFactoryConfiguration) RefreshAutoConfiguration(org.springframework.cloud.autoconfigure.RefreshAutoConfiguration) BeanContainer(org.apereo.cas.util.spring.beans.BeanContainer) CasCoreNotificationsConfiguration(org.apereo.cas.config.CasCoreNotificationsConfiguration) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) FailedLoginException(javax.security.auth.login.FailedLoginException) CasCoreAuthenticationServiceSelectionStrategyConfiguration(org.apereo.cas.config.CasCoreAuthenticationServiceSelectionStrategyConfiguration) LdapAuthenticationConfiguration(org.apereo.cas.config.LdapAuthenticationConfiguration) CasCoreAuthenticationMetadataConfiguration(org.apereo.cas.config.CasCoreAuthenticationMetadataConfiguration) CasCoreAuthenticationHandlersConfiguration(org.apereo.cas.config.CasCoreAuthenticationHandlersConfiguration) CasCoreWebConfiguration(org.apereo.cas.config.CasCoreWebConfiguration) CasCoreHttpConfiguration(org.apereo.cas.config.CasCoreHttpConfiguration) CasCoreServicesConfiguration(org.apereo.cas.config.CasCoreServicesConfiguration) Unchecked(org.jooq.lambda.Unchecked) CasCoreServicesAuthenticationConfiguration(org.apereo.cas.config.CasCoreServicesAuthenticationConfiguration) CasCoreAuthenticationPrincipalConfiguration(org.apereo.cas.config.CasCoreAuthenticationPrincipalConfiguration) CasCoreTicketIdGeneratorsConfiguration(org.apereo.cas.config.CasCoreTicketIdGeneratorsConfiguration) CasCoreLogoutConfiguration(org.apereo.cas.logout.config.CasCoreLogoutConfiguration) lombok.val(lombok.val) CasCoreAuthenticationPolicyConfiguration(org.apereo.cas.config.CasCoreAuthenticationPolicyConfiguration) Test(org.junit.jupiter.api.Test) CasCoreTicketCatalogConfiguration(org.apereo.cas.config.CasCoreTicketCatalogConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions(org.junit.jupiter.api.Assertions) CasCoreTicketsConfiguration(org.apereo.cas.config.CasCoreTicketsConfiguration) CasCoreUtilConfiguration(org.apereo.cas.config.CasCoreUtilConfiguration) CasPersonDirectoryConfiguration(org.apereo.cas.config.CasPersonDirectoryConfiguration) CasCoreAuthenticationSupportConfiguration(org.apereo.cas.config.CasCoreAuthenticationSupportConfiguration) lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 97 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class JdbcPasswordManagementService method changeInternal.

@Override
public boolean changeInternal(final Credential credential, final PasswordChangeRequest bean) {
    var result = this.transactionTemplate.execute(action -> {
        val c = (UsernamePasswordCredential) credential;
        val password = passwordEncoder.encode(bean.getPassword());
        val count = this.jdbcTemplate.update(properties.getJdbc().getSqlChangePassword(), password, c.getId());
        return count > 0;
    });
    return BooleanUtils.toBoolean(result);
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

Example 98 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class SurrogateInitialAuthenticationActionTests method verifyUsernamePasswordCredentialsFound.

@Test
public void verifyUsernamePasswordCredentialsFound() {
    try {
        val context = new MockRequestContext();
        val c = new UsernamePasswordCredential();
        c.setUsername("cassurrogate+casuser");
        c.setPassword("Mellon");
        WebUtils.putCredential(context, c);
        context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
        assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, authenticationViaFormAction.execute(context).getId());
        assertTrue(WebUtils.getCredential(context) instanceof UsernamePasswordCredential);
    } catch (final Exception e) {
        throw new AssertionError(e);
    }
}
Also used : lombok.val(lombok.val) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 99 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class SurrogateInitialAuthenticationActionTests method verifyUsernamePasswordCredentialsBadPasswordAndCancelled.

@Test
public void verifyUsernamePasswordCredentialsBadPasswordAndCancelled() {
    try {
        val context = new MockRequestContext();
        var credential = new UsernamePasswordCredential();
        credential.setUsername("cassurrogate+casuser");
        credential.setPassword("badpassword");
        WebUtils.putCredential(context, credential);
        context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
        assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, authenticationViaFormAction.execute(context).getId());
        assertTrue(WebUtils.getCredential(context) instanceof SurrogateUsernamePasswordCredential);
        val sc = WebUtils.getCredential(context, SurrogateUsernamePasswordCredential.class);
        sc.setUsername("casuser");
        sc.setPassword("Mellon");
        WebUtils.putCredential(context, sc);
        assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, authenticationViaFormAction.execute(context).getId());
        assertTrue(WebUtils.getCredential(context) instanceof UsernamePasswordCredential);
    } catch (final Exception e) {
        throw new AssertionError(e);
    }
}
Also used : lombok.val(lombok.val) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 100 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class AbstractUsernamePasswordAuthenticationHandler method doAuthentication.

@SneakyThrows
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) {
    val originalUserPass = (UsernamePasswordCredential) credential;
    val userPass = (UsernamePasswordCredential) credential.getClass().getDeclaredConstructor().newInstance();
    BeanUtils.copyProperties(userPass, originalUserPass);
    transformUsername(userPass);
    transformPassword(userPass);
    LOGGER.debug("Attempting authentication internally for transformed credential [{}]", userPass);
    return authenticateUsernamePasswordInternal(userPass, originalUserPass.getPassword());
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) SneakyThrows(lombok.SneakyThrows)

Aggregations

lombok.val (lombok.val)111 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)111 Test (org.junit.jupiter.api.Test)74 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)12 HashMap (java.util.HashMap)8 Map (java.util.Map)8 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)8 LinkedHashMap (java.util.LinkedHashMap)7 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 Executable (org.junit.jupiter.api.function.Executable)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)6 MockRequestContext (org.springframework.webflow.test.MockRequestContext)6 ArrayList (java.util.ArrayList)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 MockServletContext (org.springframework.mock.web.MockServletContext)5 FailedLoginException (javax.security.auth.login.FailedLoginException)4 SurrogateUsernamePasswordCredential (org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)4