Search in sources :

Example 96 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class CasOAuthConfiguration method initializeServletApplicationContext.

@PostConstruct
public void initializeServletApplicationContext() {
    final String oAuthCallbackUrl = casProperties.getServer().getPrefix() + BASE_OAUTH20_URL + '/' + CALLBACK_AUTHORIZE_URL_DEFINITION;
    final Service callbackService = this.webApplicationServiceFactory.createService(oAuthCallbackUrl);
    final RegisteredService svc = servicesManager.findServiceBy(callbackService);
    if (svc == null || !svc.getServiceId().equals(oAuthCallbackUrl)) {
        final RegexRegisteredService service = new RegexRegisteredService();
        service.setId(Math.abs(new SecureRandom().nextLong()));
        service.setEvaluationOrder(0);
        service.setName(service.getClass().getSimpleName());
        service.setDescription("OAuth Authentication Callback Request URL");
        service.setServiceId(oAuthCallbackUrl);
        service.setAttributeReleasePolicy(new DenyAllAttributeReleasePolicy());
        servicesManager.save(service);
        servicesManager.load();
    }
}
Also used : DenyAllAttributeReleasePolicy(org.apereo.cas.services.DenyAllAttributeReleasePolicy) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) SecureRandom(java.security.SecureRandom) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) PostConstruct(javax.annotation.PostConstruct)

Example 97 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class OAuth20AccessTokenControllerTests method addCode.

private OAuthCode addCode(final Principal principal, final RegisteredService registeredService) {
    final Authentication authentication = getAuthentication(principal);
    final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
    final Service service = factory.createService(registeredService.getServiceId());
    final OAuthCode code = oAuthCodeFactory.create(service, authentication);
    oAuth20AccessTokenController.getTicketRegistry().addTicket(code);
    return code;
}
Also used : Authentication(org.apereo.cas.authentication.Authentication) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) OAuthCode(org.apereo.cas.ticket.code.OAuthCode)

Example 98 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class OAuth20AccessTokenControllerTests method verifyClientNoAuthorizationCode.

@Test
public void verifyClientNoAuthorizationCode() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    final Principal principal = createPrincipal();
    final RegisteredService service = addRegisteredService();
    final OAuthCode code = addCode(principal, service);
    mockRequest.setParameter(OAuthConstants.CODE, code.getId());
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
    oAuth20AccessTokenController.handleRequestInternal(mockRequest, mockResponse);
    assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus());
    assertEquals(ERROR_EQUALS + OAuthConstants.INVALID_REQUEST, mockResponse.getContentAsString());
}
Also used : OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuthCode(org.apereo.cas.ticket.code.OAuthCode) Principal(org.apereo.cas.authentication.principal.Principal) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 99 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class OAuth20AccessTokenControllerTests method verifyClientRedirectUriDoesNotStartWithServiceId.

@Test
public void verifyClientRedirectUriDoesNotStartWithServiceId() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, OTHER_REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.GRANT_TYPE, OAuth20GrantTypes.AUTHORIZATION_CODE.name().toLowerCase());
    final Principal principal = createPrincipal();
    final RegisteredService service = addRegisteredService();
    final OAuthCode code = addCode(principal, service);
    mockRequest.setParameter(OAuthConstants.CODE, code.getId());
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
    oAuth20AccessTokenController.handleRequestInternal(mockRequest, mockResponse);
    assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus());
    assertEquals(ERROR_EQUALS + OAuthConstants.INVALID_REQUEST, mockResponse.getContentAsString());
}
Also used : OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuthCode(org.apereo.cas.ticket.code.OAuthCode) Principal(org.apereo.cas.authentication.principal.Principal) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 100 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class LdapServiceRegistryDaoTests method verifyOAuthServices.

@Test
public void verifyOAuthServices() {
    final OAuthRegisteredService r = new OAuthRegisteredService();
    r.setName("test1456");
    r.setServiceId("testId");
    r.setTheme("theme");
    r.setDescription("description");
    r.setAttributeReleasePolicy(new ReturnAllAttributeReleasePolicy());
    r.setClientId("testoauthservice");
    r.setClientSecret("anothertest");
    r.setBypassApprovalPrompt(true);
    final RegisteredService r2 = this.dao.save(r);
    assertEquals(r, r2);
}
Also used : ReturnAllAttributeReleasePolicy(org.apereo.cas.services.ReturnAllAttributeReleasePolicy) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

RegisteredService (org.apereo.cas.services.RegisteredService)109 Test (org.junit.Test)39 Authentication (org.apereo.cas.authentication.Authentication)35 Service (org.apereo.cas.authentication.principal.Service)30 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)27 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)22 Principal (org.apereo.cas.authentication.principal.Principal)21 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)18 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)17 AbstractRegisteredService (org.apereo.cas.services.AbstractRegisteredService)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 Event (org.springframework.webflow.execution.Event)12 ServicesManager (org.apereo.cas.services.ServicesManager)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)10 OAuthCode (org.apereo.cas.ticket.code.OAuthCode)10 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 Collection (java.util.Collection)8