Search in sources :

Example 1 with ProxyTicket

use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.

the class DefaultCentralAuthenticationService method grantProxyTicket.

@Audit(action = "PROXY_TICKET", actionResolverName = "GRANT_PROXY_TICKET_RESOLVER", resourceResolverName = "GRANT_PROXY_TICKET_RESOURCE_RESOLVER")
@Timed(name = "GRANT_PROXY_TICKET_TIMER")
@Metered(name = "GRANT_PROXY_TICKET_METER")
@Counted(name = "GRANT_PROXY_TICKET_COUNTER", monotonic = true)
@Override
public ProxyTicket grantProxyTicket(final String proxyGrantingTicket, final Service service) throws AbstractTicketException {
    final ProxyGrantingTicket proxyGrantingTicketObject = getTicket(proxyGrantingTicket, ProxyGrantingTicket.class);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
    try {
        final AuditableContext audit = AuditableContext.builder().service(service).ticketGrantingTicket(proxyGrantingTicketObject).registeredService(registeredService).retrievePrincipalAttributesFromReleasePolicy(Boolean.FALSE).build();
        final AuditableExecutionResult accessResult = this.registeredServiceAccessStrategyEnforcer.execute(audit);
        accessResult.throwExceptionIfNeeded();
        RegisteredServiceAccessStrategyUtils.ensureServiceSsoAccessIsAllowed(registeredService, service, proxyGrantingTicketObject);
    } catch (final PrincipalException e) {
        throw new UnauthorizedSsoServiceException();
    }
    evaluateProxiedServiceIfNeeded(service, proxyGrantingTicketObject, registeredService);
    // Perform security policy check by getting the authentication that satisfies the configured policy
    // This throws if no suitable policy is found
    getAuthenticationSatisfiedByPolicy(proxyGrantingTicketObject.getRoot().getAuthentication(), new ServiceContext(service, registeredService));
    final Authentication authentication = proxyGrantingTicketObject.getRoot().getAuthentication();
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(authentication);
    final Principal principal = authentication.getPrincipal();
    final ProxyTicketFactory factory = (ProxyTicketFactory) this.ticketFactory.get(ProxyTicket.class);
    final ProxyTicket proxyTicket = factory.create(proxyGrantingTicketObject, service, ProxyTicket.class);
    this.ticketRegistry.updateTicket(proxyGrantingTicketObject);
    this.ticketRegistry.addTicket(proxyTicket);
    LOGGER.info("Granted ticket [{}] for service [{}] for user [{}]", proxyTicket.getId(), service.getId(), principal.getId());
    doPublishEvent(new CasProxyTicketGrantedEvent(this, proxyGrantingTicketObject, proxyTicket));
    return proxyTicket;
}
Also used : AuditableContext(org.apereo.cas.audit.AuditableContext) RegisteredService(org.apereo.cas.services.RegisteredService) ProxyTicketFactory(org.apereo.cas.ticket.proxy.ProxyTicketFactory) UnauthorizedSsoServiceException(org.apereo.cas.services.UnauthorizedSsoServiceException) PrincipalException(org.apereo.cas.authentication.PrincipalException) MixedPrincipalException(org.apereo.cas.authentication.exceptions.MixedPrincipalException) ServiceContext(org.apereo.cas.services.ServiceContext) Authentication(org.apereo.cas.authentication.Authentication) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) AuditableExecutionResult(org.apereo.cas.audit.AuditableExecutionResult) Principal(org.apereo.cas.authentication.principal.Principal) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) CasProxyTicketGrantedEvent(org.apereo.cas.support.events.ticket.CasProxyTicketGrantedEvent) Audit(org.apereo.inspektr.audit.annotation.Audit) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with ProxyTicket

use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.

the class ProxyGrantingTicketImpl method grantProxyTicket.

@Override
public ProxyTicket grantProxyTicket(final String id, final Service service, final ExpirationPolicy expirationPolicy, final boolean onlyTrackMostRecentSession) {
    final ProxyTicket serviceTicket = new ProxyTicketImpl(id, this, service, false, expirationPolicy);
    trackServiceSession(serviceTicket.getId(), service, onlyTrackMostRecentSession);
    return serviceTicket;
}
Also used : ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket)

Example 3 with ProxyTicket

use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.

the class JpaTicketRegistryTests method verifyTicketDeletionInBulk.

@Test
public void verifyTicketDeletionInBulk() {
    final TicketGrantingTicket newTgt = newTGT();
    addTicketInTransaction(newTgt);
    final TicketGrantingTicket tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    final ServiceTicket newSt = grantServiceTicketInTransaction(tgtFromDb);
    final ServiceTicket stFromDb = (ServiceTicket) getTicketInTransaction(newSt.getId());
    final ProxyGrantingTicket newPgt = grantProxyGrantingTicketInTransaction(stFromDb);
    final ProxyGrantingTicket pgtFromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt.getId());
    final ProxyTicket newPt = grantProxyTicketInTransaction(pgtFromDb);
    getTicketInTransaction(newPt.getId());
    deleteTicketsInTransaction();
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with ProxyTicket

use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.

the class JpaTicketRegistryTests method grantProxyTicketInTransaction.

private ProxyTicket grantProxyTicketInTransaction(final ProxyGrantingTicket parent) {
    return new TransactionTemplate(txManager).execute(status -> {
        final ProxyTicket st = newPT(parent);
        ticketRegistry.addTicket(st);
        return st;
    });
}
Also used : TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket)

Example 5 with ProxyTicket

use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyGrantProxyTicketWithValidTicketGrantingTicket.

@Test
public void verifyGrantProxyTicketWithValidTicketGrantingTicket() {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport());
    final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicketId = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), getService(), ctx);
    final AuthenticationResult ctx2 = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), RegisteredServiceTestUtils.getHttpBasedServiceCredentials());
    final TicketGrantingTicket pgt = getCentralAuthenticationService().createProxyGrantingTicket(serviceTicketId.getId(), ctx2);
    final ProxyTicket pt = getCentralAuthenticationService().grantProxyTicket(pgt.getId(), getService());
    assertTrue(pt.getId().startsWith(ProxyTicket.PROXY_TICKET_PREFIX));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Aggregations

ProxyTicket (org.apereo.cas.ticket.proxy.ProxyTicket)7 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)3 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Counted (com.codahale.metrics.annotation.Counted)1 Metered (com.codahale.metrics.annotation.Metered)1 Timed (com.codahale.metrics.annotation.Timed)1 Map (java.util.Map)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 AuditableContext (org.apereo.cas.audit.AuditableContext)1 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)1 PrincipalException (org.apereo.cas.authentication.PrincipalException)1 MixedPrincipalException (org.apereo.cas.authentication.exceptions.MixedPrincipalException)1 Principal (org.apereo.cas.authentication.principal.Principal)1 Service (org.apereo.cas.authentication.principal.Service)1 RegisteredService (org.apereo.cas.services.RegisteredService)1