use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class CentralAuthenticationServiceImplTests method verifyGrantingOfServiceTicketUsingDefaultTicketIdGen.
@Test
public void verifyGrantingOfServiceTicketUsingDefaultTicketIdGen() {
final Service mockService = RegisteredServiceTestUtils.getService("testDefault");
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), mockService);
final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket serviceTicketId = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), mockService, ctx);
assertNotNull(serviceTicketId);
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class CentralAuthenticationServiceImplWithMockitoTests method verifyChainedAuthenticationsOnValidation.
@Test
public void verifyChainedAuthenticationsOnValidation() {
final Service svc = RegisteredServiceTestUtils.getService(SVC2_ID);
final ServiceTicket st = this.cas.grantServiceTicket(TGT2_ID, svc, getAuthenticationContext());
assertNotNull(st);
final Assertion assertion = this.cas.validateServiceTicket(st.getId(), svc);
assertNotNull(assertion);
assertEquals(assertion.getService(), svc);
assertEquals(PRINCIPAL, assertion.getPrimaryAuthentication().getPrincipal().getId());
assertSame(2, assertion.getChainedAuthentications().size());
IntStream.range(0, assertion.getChainedAuthentications().size()).forEach(i -> assertEquals(assertion.getChainedAuthentications().get(i), authentication));
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class GatewayServicesManagementCheck method doExecute.
@Override
protected Event doExecute(final RequestContext context) {
final Service service = WebUtils.getService(context);
final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
if (registeredService == null) {
final String msg = String.format("Service Management: Unauthorized Service Access. " + "Service [%s] does not match entries in service registry.", service.getId());
LOGGER.warn(msg);
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, msg);
}
if (!registeredService.getAccessStrategy().isServiceAccessAllowed()) {
final String msg = String.format("Service Management: Access to service [%s] " + "is disabled by the service registry.", service.getId());
LOGGER.warn(msg);
WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(context, registeredService.getAccessStrategy().getUnauthorizedRedirectUrl());
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, msg);
}
return success();
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class RestConsentRepositoryTests method verifyConsentDecisionIsFound.
@Test
public void verifyConsentDecisionIsFound() throws Exception {
final ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
final DefaultConsentDecisionBuilder builder = new DefaultConsentDecisionBuilder(CipherExecutor.noOpOfSerializableToString());
final AbstractRegisteredService regSvc = RegisteredServiceTestUtils.getRegisteredService("test");
final Service svc = RegisteredServiceTestUtils.getService();
final ConsentDecision decision = builder.build(svc, regSvc, "casuser", CollectionUtils.wrap("attribute", "value"));
final String body = mapper.writeValueAsString(decision);
server.expect(manyTimes(), requestTo("/consent")).andExpect(method(HttpMethod.GET)).andRespond(withSuccess(body, MediaType.APPLICATION_JSON));
final RestConsentRepository repo = new RestConsentRepository(this.restTemplate, "/consent");
final ConsentDecision d = repo.findConsentDecision(svc, regSvc, CoreAuthenticationTestUtils.getAuthentication());
assertNotNull(d);
assertEquals("casuser", d.getPrincipal());
server.verify();
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class AbstractTicketRegistryTests method verifyDeleteTicketWithChildren.
@Test
public void verifyDeleteTicketWithChildren() {
try {
this.ticketRegistry.addTicket(new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX + "1", CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
final TicketGrantingTicket tgt = this.ticketRegistry.getTicket(TicketGrantingTicket.PREFIX + "1", TicketGrantingTicket.class);
final Service service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
final ServiceTicket st1 = tgt.grantServiceTicket("ST11", service, new NeverExpiresExpirationPolicy(), false, false);
final ServiceTicket st2 = tgt.grantServiceTicket("ST21", service, new NeverExpiresExpirationPolicy(), false, false);
final ServiceTicket st3 = tgt.grantServiceTicket("ST31", service, new NeverExpiresExpirationPolicy(), false, false);
this.ticketRegistry.addTicket(st1);
this.ticketRegistry.addTicket(st2);
this.ticketRegistry.addTicket(st3);
assertNotNull(this.ticketRegistry.getTicket(TicketGrantingTicket.PREFIX + "1", TicketGrantingTicket.class));
assertNotNull(this.ticketRegistry.getTicket("ST11", ServiceTicket.class));
assertNotNull(this.ticketRegistry.getTicket("ST21", ServiceTicket.class));
assertNotNull(this.ticketRegistry.getTicket("ST31", ServiceTicket.class));
this.ticketRegistry.updateTicket(tgt);
assertSame(4, this.ticketRegistry.deleteTicket(tgt.getId()));
assertNull(this.ticketRegistry.getTicket(TicketGrantingTicket.PREFIX + "1", TicketGrantingTicket.class));
assertNull(this.ticketRegistry.getTicket("ST11", ServiceTicket.class));
assertNull(this.ticketRegistry.getTicket("ST21", ServiceTicket.class));
assertNull(this.ticketRegistry.getTicket("ST31", ServiceTicket.class));
} catch (final Exception e) {
throw new AssertionError(CAUGHT_AN_EXCEPTION_BUT_WAS_NOT_EXPECTED + e.getMessage(), e);
}
}
Aggregations