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;
}
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;
}
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();
}
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;
});
}
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));
}
Aggregations