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 CoreAuthenticationTestUtils method getService.
public static Service getService(final String id) {
final Service svc = mock(Service.class);
when(svc.getId()).thenReturn(id);
when(svc.matches(any(Service.class))).thenReturn(true);
return svc;
}
use of org.apereo.cas.authentication.principal.Service in project cas by apereo.
the class CoreAttributesTestUtils method getService.
public static Service getService() {
final Service svc = mock(Service.class);
when(svc.getId()).thenReturn(CONST_TEST_URL);
when(svc.matches(any(Service.class))).thenReturn(true);
return svc;
}
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;
}
Aggregations