Search in sources :

Example 71 with UsernamePasswordCredential

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

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketAnonymous.

@Test
public void verifyValidateServiceTicketAnonymous() {
    final Service service = getService("testAnonymous");
    final UsernamePasswordCredential cred = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), service);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), service, ctx);
    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), service);
    final Authentication auth = assertion.getPrimaryAuthentication();
    assertNotEquals(cred.getUsername(), auth.getPrincipal().getId());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Authentication(org.apereo.cas.authentication.Authentication) Assertion(org.apereo.cas.validation.Assertion) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 72 with UsernamePasswordCredential

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

the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.

private AuthenticationBuilder newBuilder(final Credential credential) {
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    final AuthenticationBuilder builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
    if (this.p.supports(credential)) {
        this.p.populateAttributes(builder, AuthenticationTransaction.of(credential));
    }
    return builder;
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.RememberMeUsernamePasswordCredential) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 73 with UsernamePasswordCredential

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

the class UsernamePasswordRestHttpRequestCredentialFactory method fromRequestBody.

@Override
public List<Credential> fromRequestBody(final MultiValueMap<String, String> requestBody) {
    final String username = requestBody.getFirst(USERNAME);
    final String password = requestBody.getFirst(PASSWORD);
    if (username == null || password == null) {
        LOGGER.debug("Invalid payload. 'username' and 'password' form fields are required.");
        return new ArrayList<>(0);
    }
    final Credential c = new UsernamePasswordCredential(username, password);
    return CollectionUtils.wrap(c);
}
Also used : UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) ArrayList(java.util.ArrayList) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential)

Example 74 with UsernamePasswordCredential

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

the class RegisteredServiceTestUtils method getAuthentication.

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

Example 75 with UsernamePasswordCredential

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

the class PersonDirectoryPrincipalResolverLdaptiveTests method verifyResolver.

@Test
public void verifyResolver() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(this.attributeRepository);
    final Principal p = resolver.resolve(new UsernamePasswordCredential("castest1", "castest1"), CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler());
    assertNotNull(p);
    assertTrue(p.getAttributes().containsKey("givenName"));
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)96 Test (org.junit.Test)58 Credential (org.apereo.cas.authentication.Credential)25 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)22 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)17 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)9 CachedData (net.spy.memcached.CachedData)9 Authentication (org.apereo.cas.authentication.Authentication)9 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)9 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Service (org.apereo.cas.authentication.principal.Service)8 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)8 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)6 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)6 Assertion (org.apereo.cas.validation.Assertion)6 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)5 PasswordChangeBean (org.apereo.cas.pm.PasswordChangeBean)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5