use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.
the class AuthenticationViaFormActionTests method verifyRenewWithServiceAndBadCredentials.
@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
final Service service = RegisteredServiceTestUtils.getService(TEST);
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), service, c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
final Credential c2 = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c2);
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.
the class CentralAuthenticationServiceImplTests method disallowNullCredentialsArrayWhenCreatingTicketGrantingTicket.
@Test
public void disallowNullCredentialsArrayWhenCreatingTicketGrantingTicket() throws Exception {
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), new Credential[] { null, null });
this.thrown.expect(RuntimeException.class);
getCentralAuthenticationService().createTicketGrantingTicket(ctx);
}
use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.
the class TicketsResource method createServiceTicket.
/**
* Create new service ticket.
*
* @param requestBody service application/x-www-form-urlencoded value
* @param tgtId ticket granting ticket id URI path param
* @return {@link ResponseEntity} representing RESTful response
*/
@PostMapping(value = "/v1/tickets/{tgtId:.+}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> createServiceTicket(@RequestBody final MultiValueMap<String, String> requestBody, @PathVariable("tgtId") final String tgtId) {
try {
final String serviceId = requestBody.getFirst(CasProtocolConstants.PARAMETER_SERVICE);
final AuthenticationResultBuilder builder = new DefaultAuthenticationResultBuilder(this.authenticationSystemSupport.getPrincipalElectionStrategy());
final Service service = this.webApplicationServiceFactory.createService(serviceId);
final AuthenticationResult authenticationResult = builder.collect(this.ticketRegistrySupport.getAuthenticationFrom(tgtId)).build(service);
final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(tgtId, service, authenticationResult);
return new ResponseEntity<>(serviceTicketId.getId(), HttpStatus.OK);
} catch (final InvalidTicketException e) {
return new ResponseEntity<>("TicketGrantingTicket could not be found", HttpStatus.NOT_FOUND);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.
the class CentralAuthenticationServiceImplTests method verifyGrantServiceTicketWithValidTicketGrantingTicket.
@Test
public void verifyGrantServiceTicketWithValidTicketGrantingTicket() {
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport());
final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), getService(), ctx);
}
use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.
the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketWithValidService.
@Test
public void verifyValidateServiceTicketWithValidService() {
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport());
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), getService(), ctx);
getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), getService());
}
Aggregations