Search in sources :

Example 71 with UsernamePasswordCredential

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

the class SSOSamlIdPPostProfileHandlerEndpoint method getAssertion.

private AuthenticatedAssertionContext getAssertion(final String username, final String password, final String entityId) {
    val selectedService = serviceFactory.createService(entityId);
    val registeredService = servicesManager.findServiceBy(selectedService, SamlRegisteredService.class);
    val credential = new UsernamePasswordCredential(username, password);
    val result = this.authenticationSystemSupport.finalizeAuthenticationTransaction(selectedService, credential);
    val authentication = result.getAuthentication();
    val principal = authentication.getPrincipal();
    val context = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(selectedService).principal(principal).build();
    val attributesToRelease = registeredService.getAttributeReleasePolicy().getAttributes(context);
    val builder = DefaultAuthenticationBuilder.of(principal, this.principalFactory, attributesToRelease, selectedService, registeredService, authentication);
    val finalAuthentication = builder.build();
    val authnPrincipal = finalAuthentication.getPrincipal();
    return AuthenticatedAssertionContext.builder().name(authnPrincipal.getId()).attributes(CollectionUtils.merge(authnPrincipal.getAttributes(), finalAuthentication.getAttributes())).build();
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

Example 72 with UsernamePasswordCredential

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

the class RegisteredServiceTestUtils method getCredentialsWithSameUsernameAndPassword.

public static UsernamePasswordCredential getCredentialsWithSameUsernameAndPassword(final String username) {
    val usernamePasswordCredentials = new UsernamePasswordCredential();
    usernamePasswordCredentials.setUsername(username);
    usernamePasswordCredentials.setPassword(username);
    return usernamePasswordCredentials;
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

Example 73 with UsernamePasswordCredential

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

the class RegisteredServiceTestUtils method getCredentialsWithDifferentUsernameAndPassword.

public static UsernamePasswordCredential getCredentialsWithDifferentUsernameAndPassword(final String username, final String password) {
    val usernamePasswordCredentials = new UsernamePasswordCredential();
    usernamePasswordCredentials.setUsername(username);
    usernamePasswordCredentials.setPassword(password);
    return usernamePasswordCredentials;
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

Example 74 with UsernamePasswordCredential

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

the class RegisteredServiceTestUtils method getAuthentication.

public static Authentication getAuthentication(final Principal principal, final Map<String, List<Object>> attributes) {
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess("testHandler", new DefaultAuthenticationHandlerExecutionResult(handler, meta)).setAttributes(attributes).build();
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Example 75 with UsernamePasswordCredential

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

the class MultifactorAuthenticationTests method newUserPassCredentials.

private static UsernamePasswordCredential newUserPassCredentials(final String user, final String pass) {
    val userpass = new UsernamePasswordCredential();
    userpass.setUsername(user);
    userpass.setPassword(pass);
    return userpass;
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

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