use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class TicketGrantingTicketResource method createTicketGrantingTicketForRequest.
/**
* Create ticket granting ticket for request ticket granting ticket.
*
* @param requestBody the request body
* @param request the request
* @return the ticket granting ticket
*/
protected TicketGrantingTicket createTicketGrantingTicketForRequest(final MultiValueMap<String, String> requestBody, final HttpServletRequest request) {
final Collection<Credential> credential = this.credentialFactory.fromRequestBody(requestBody);
if (credential == null || credential.isEmpty()) {
throw new BadRestRequestException("No credentials are provided or extracted to authenticate the REST request");
}
final Service service = this.serviceFactory.createService(request);
final AuthenticationResult authenticationResult = authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);
return centralAuthenticationService.createTicketGrantingTicket(authenticationResult);
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class UserAuthenticationResource method createTicketGrantingTicket.
/**
* Create new ticket granting ticket.
*
* @param requestBody username and password application/x-www-form-urlencoded values
* @param request raw HttpServletRequest used to call this method
* @return ResponseEntity representing RESTful response
*/
@PostMapping(value = "/v1/users", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> createTicketGrantingTicket(@RequestBody final MultiValueMap<String, String> requestBody, final HttpServletRequest request) {
try {
final Collection<Credential> credential = this.credentialFactory.fromRequestBody(requestBody);
if (credential == null || credential.isEmpty()) {
throw new BadRestRequestException("No credentials are provided or extracted to authenticate the REST request");
}
final Service service = this.serviceFactory.createService(request);
final AuthenticationResult authenticationResult = authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);
return this.userAuthenticationResourceEntityResponseFactory.build(authenticationResult, request);
} catch (final AuthenticationException e) {
return RestResourceUtils.createResponseEntityForAuthnFailure(e);
} catch (final BadRestRequestException e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class DefaultLogoutManagerTests method setUp.
@Before
public void setUp() {
when(client.isValidEndPoint(any(String.class))).thenReturn(true);
when(client.isValidEndPoint(any(URL.class))).thenReturn(true);
when(client.sendMessageToEndPoint(any(HttpMessage.class))).thenReturn(true);
final UrlValidator validator = new SimpleUrlValidatorFactoryBean(true).getObject();
singleLogoutServiceMessageHandler = new DefaultSingleLogoutServiceMessageHandler(client, new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(validator), true, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
final Map<String, Service> services = new HashMap<>();
this.simpleWebApplicationServiceImpl = getService(URL);
services.put(ID, this.simpleWebApplicationServiceImpl);
when(this.tgt.getServices()).thenReturn(services);
this.logoutManager = new DefaultLogoutManager(new SamlCompliantLogoutMessageCreator(), singleLogoutServiceMessageHandler, false, mock(LogoutExecutionPlan.class));
this.registeredService = getRegisteredService(URL);
when(servicesManager.findServiceBy(this.simpleWebApplicationServiceImpl)).thenReturn(this.registeredService);
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class ProxyController method canHandle.
@Override
public boolean canHandle(final HttpServletRequest request, final HttpServletResponse response) {
final String proxyGrantingTicket = request.getParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET);
final Service targetService = getTargetService(request);
return StringUtils.hasText(proxyGrantingTicket) && targetService != null;
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class WSFederationAuthenticationServiceSelectionStrategy method getRealmAsParameter.
private static Optional<NameValuePair> getRealmAsParameter(final Service service) {
try {
final URIBuilder builder = new URIBuilder(service.getId());
final Optional param = builder.getQueryParams().stream().filter(p -> p.getName().equals(WSFederationConstants.WTREALM)).findFirst();
return param;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return Optional.empty();
}
Aggregations