Search in sources :

Example 76 with Service

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);
    }
}
Also used : Credential(org.apereo.cas.authentication.Credential) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Service(org.apereo.cas.authentication.principal.Service) BadRestRequestException(org.apereo.cas.rest.BadRestRequestException) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) BadRestRequestException(org.apereo.cas.rest.BadRestRequestException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 77 with Service

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);
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) HashMap(java.util.HashMap) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) URL(java.net.URL) SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) UrlValidator(org.apereo.cas.web.UrlValidator) HttpMessage(org.apereo.cas.util.http.HttpMessage) Before(org.junit.Before)

Example 78 with Service

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;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 79 with Service

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;
}
Also used : Service(org.apereo.cas.authentication.principal.Service) RegisteredService(org.apereo.cas.services.RegisteredService)

Example 80 with Service

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;
}
Also used : CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service)

Aggregations

Service (org.apereo.cas.authentication.principal.Service)173 RegisteredService (org.apereo.cas.services.RegisteredService)67 Test (org.junit.Test)61 Authentication (org.apereo.cas.authentication.Authentication)47 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)44 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)42 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)35 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)32 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)29 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)21 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)15 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)15 Credential (org.apereo.cas.authentication.Credential)13 Principal (org.apereo.cas.authentication.principal.Principal)13 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)12 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)12 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)12