Search in sources :

Example 6 with ProxyGrantingTicketIssuerTicket

use of org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket 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)6 ProxyGrantingTicketIssuerTicket (org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket)6 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)5 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)4 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 Clock (java.time.Clock)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 UUID (java.util.UUID)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 Slf4j (lombok.extern.slf4j.Slf4j)1