Search in sources :

Example 11 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.

private static AuthenticationBuilder newBuilder(final Credential credential, final RememberMeAuthenticationProperties properties) {
    val populator = new RememberMeAuthenticationMetaDataPopulator(properties);
    val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
    if (populator.supports(credential)) {
        populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credential));
    }
    return builder;
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) RememberMeAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Example 12 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class AbstractOAuth20Tests method getAuthentication.

protected static Authentication getAuthentication(final Principal principal) {
    val metadata = new BasicCredentialMetaData(new BasicIdentifiableCredential(principal.getId()));
    val handlerResult = new DefaultAuthenticationHandlerExecutionResult(principal.getClass().getCanonicalName(), metadata, principal, new ArrayList<>());
    return DefaultAuthenticationBuilder.newInstance().setPrincipal(principal).setAuthenticationDate(ZonedDateTime.now(ZoneOffset.UTC)).addCredential(metadata).addSuccess(principal.getClass().getCanonicalName(), handlerResult).build();
}
Also used : lombok.val(lombok.val) BasicIdentifiableCredential(org.apereo.cas.authentication.credential.BasicIdentifiableCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Example 13 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData 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 14 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class OpenIdCredentialsAuthenticationHandler method authenticate.

@Override
public AuthenticationHandlerExecutionResult authenticate(final Credential credential) throws GeneralSecurityException {
    val c = (OpenIdCredential) credential;
    val t = this.ticketRegistry.getTicket(c.getTicketGrantingTicketId(), TicketGrantingTicket.class);
    if (t == null || t.isExpired()) {
        throw new FailedLoginException("Ticket-granting ticket is null or expired.");
    }
    val principal = t.getAuthentication().getPrincipal();
    if (!principal.getId().equals(c.getUsername())) {
        throw new FailedLoginException("Principal ID mismatch");
    }
    return new DefaultAuthenticationHandlerExecutionResult(this, new BasicCredentialMetaData(c), principal);
}
Also used : lombok.val(lombok.val) FailedLoginException(javax.security.auth.login.FailedLoginException) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) OpenIdCredential(org.apereo.cas.support.openid.authentication.principal.OpenIdCredential)

Example 15 with BasicCredentialMetaData

use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTImpl.

@Test
public void verifyEncodeDecodeTGTImpl() {
    val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    val bldr = new DefaultAuthenticationBuilder(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
    bldr.setAttributes(new HashMap<>(this.principalAttributes));
    bldr.setAuthenticationDate(ZonedDateTime.now(ZoneId.systemDefault()));
    bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
    bldr.addFailure("error", new AccountNotFoundException());
    bldr.addSuccess("authn", new DefaultAuthenticationHandlerExecutionResult(new AcceptUsersAuthenticationHandler(StringUtils.EMPTY), new BasicCredentialMetaData(userPassCredential)));
    val authentication = bldr.build();
    val expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, authentication, NeverExpiresExpirationPolicy.INSTANCE);
    val serviceTicket = (ProxyGrantingTicketIssuerTicket) expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), NeverExpiresExpirationPolicy.INSTANCE, false, true);
    var encoded = transcoder.encode(expectedTGT);
    var decoded = transcoder.decode(encoded);
    assertEquals(expectedTGT, decoded);
    encoded = transcoder.encode(serviceTicket);
    decoded = transcoder.decode(encoded);
    assertEquals(serviceTicket, decoded);
    decoded = transcoder.decode(encoded);
    assertEquals(serviceTicket, decoded);
    val pgt = serviceTicket.grantProxyGrantingTicket(PGT_ID, authentication, new HardTimeoutExpirationPolicy(100));
    encoded = transcoder.encode(pgt);
    decoded = transcoder.decode(encoded);
    assertEquals(pgt, decoded);
    val pt = pgt.grantProxyTicket(PT_ID, RegisteredServiceTestUtils.getService(), new HardTimeoutExpirationPolicy(100), true);
    encoded = transcoder.encode(pt);
    decoded = transcoder.decode(encoded);
    assertEquals(pt, decoded);
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) ProxyGrantingTicketIssuerTicket(org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)21 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)21 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)12 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)8 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)7 FailedLoginException (javax.security.auth.login.FailedLoginException)6 Test (org.junit.jupiter.api.Test)6 GeneralSecurityException (java.security.GeneralSecurityException)3 HashMap (java.util.HashMap)3 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)3 BasicIdentifiableCredential (org.apereo.cas.authentication.credential.BasicIdentifiableCredential)3 DefaultMessageDescriptor (org.apereo.cas.DefaultMessageDescriptor)2 SpnegoCredential (org.apereo.cas.support.spnego.authentication.principal.SpnegoCredential)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 Type1Message (jcifs.ntlmssp.Type1Message)1 Type2Message (jcifs.ntlmssp.Type2Message)1 Type3Message (jcifs.ntlmssp.Type3Message)1 NtlmPasswordAuthentication (jcifs.smb.NtlmPasswordAuthentication)1