Search in sources :

Example 11 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class OAuth20PasswordGrantTypeTokenRequestValidatorTests method before.

@BeforeEach
public void before() {
    val serviceManager = mock(ServicesManager.class);
    supportingService = RequestValidatorTestUtils.getService(RegisteredServiceTestUtils.CONST_TEST_URL, RequestValidatorTestUtils.SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.SHARED_SECRET, CollectionUtils.wrapSet(getGrantType()));
    nonSupportingService = RequestValidatorTestUtils.getService(RegisteredServiceTestUtils.CONST_TEST_URL2, RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.SHARED_SECRET, CollectionUtils.wrapSet(getWrongGrantType()));
    promiscuousService = RequestValidatorTestUtils.getPromiscuousService(RegisteredServiceTestUtils.CONST_TEST_URL3, RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID, RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID, RequestValidatorTestUtils.SHARED_SECRET);
    when(serviceManager.getAllServices()).thenReturn(CollectionUtils.wrapList(supportingService, nonSupportingService, promiscuousService));
    when(serviceManager.getAllServicesOfType(any())).thenReturn(CollectionUtils.wrapList(supportingService, nonSupportingService, promiscuousService));
    val context = OAuth20ConfigurationContext.builder().servicesManager(serviceManager).webApplicationServiceServiceFactory(new WebApplicationServiceFactory()).registeredServiceAccessStrategyEnforcer(new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties())).sessionStore(JEESessionStore.INSTANCE).build();
    this.validator = new OAuth20PasswordGrantTypeTokenRequestValidator(context);
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class OAuth20ProofKeyCodeExchangeResponseTypeAuthorizationRequestValidatorTests method verifySupports.

@Test
public void verifySupports() throws Exception {
    val serviceManager = mock(ServicesManager.class);
    val service = new OAuthRegisteredService();
    service.setName("OAuth");
    service.setClientId("client");
    service.setClientSecret("secret");
    service.setServiceId("https://callback.example.org");
    when(serviceManager.getAllServices()).thenReturn((Collection) CollectionUtils.toCollection(service));
    when(serviceManager.getAllServicesOfType(any())).thenReturn((Collection) CollectionUtils.toCollection(service));
    val v = new OAuth20ProofKeyCodeExchangeResponseTypeAuthorizationRequestValidator(serviceManager, new WebApplicationServiceFactory(), new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()));
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    assertFalse(v.supports(context));
    request.setParameter(OAuth20Constants.CLIENT_ID, "client");
    request.setParameter(OAuth20Constants.REDIRECT_URI, service.getServiceId());
    request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.TOKEN.getType());
    request.setParameter(OAuth20Constants.CODE_VERIFIER, "abcd");
    assertFalse(v.supports(context));
    request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.getType());
    assertTrue(v.supports(context));
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 13 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class OAuth20AuthorizationCodeGrantTypeTokenRequestValidatorTests method before.

@BeforeEach
public void before() throws Exception {
    val supportingService = RequestValidatorTestUtils.getService(RegisteredServiceTestUtils.CONST_TEST_URL, RequestValidatorTestUtils.SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.SHARED_SECRET, CollectionUtils.wrapSet(OAuth20GrantTypes.AUTHORIZATION_CODE));
    val nonSupportingService = RequestValidatorTestUtils.getService(RegisteredServiceTestUtils.CONST_TEST_URL2, RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.NON_SUPPORTING_CLIENT_ID, RequestValidatorTestUtils.SHARED_SECRET, CollectionUtils.wrapSet(OAuth20GrantTypes.PASSWORD));
    val promiscuousService = RequestValidatorTestUtils.getPromiscuousService(RegisteredServiceTestUtils.CONST_TEST_URL3, RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID, RequestValidatorTestUtils.PROMISCUOUS_CLIENT_ID, RequestValidatorTestUtils.SHARED_SECRET);
    this.supportingServiceTicket = registerTicket(supportingService);
    this.nonSupportingServiceTicket = registerTicket(nonSupportingService);
    this.promiscuousServiceTicket = registerTicket(promiscuousService);
    this.servicesManager.deleteAll();
    this.servicesManager.save(supportingService, nonSupportingService, promiscuousService);
    val context = OAuth20ConfigurationContext.builder().servicesManager(this.servicesManager).sessionStore(JEESessionStore.INSTANCE).ticketRegistry(this.ticketRegistry).webApplicationServiceServiceFactory(serviceFactory).registeredServiceAccessStrategyEnforcer(new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties())).build();
    this.validator = new OAuth20AuthorizationCodeGrantTypeTokenRequestValidator(context);
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class OAuth20IdTokenResponseTypeAuthorizationRequestValidatorTests method verifySupports.

@Test
public void verifySupports() throws Exception {
    val serviceManager = mock(ServicesManager.class);
    val service = new OAuthRegisteredService();
    service.setName("OAuth");
    service.setClientId("client");
    service.setClientSecret("secret");
    service.setServiceId("https://callback.example.org");
    when(serviceManager.getAllServices()).thenReturn((Collection) CollectionUtils.toCollection(service));
    when(serviceManager.getAllServicesOfType(any())).thenReturn((Collection) CollectionUtils.toCollection(service));
    val v = new OAuth20IdTokenResponseTypeAuthorizationRequestValidator(serviceManager, new WebApplicationServiceFactory(), new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()));
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.getType());
    request.setParameter(OAuth20Constants.CLIENT_ID, "client");
    request.setParameter(OAuth20Constants.REDIRECT_URI, service.getServiceId());
    assertFalse(v.supports(context));
    request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.ID_TOKEN.getType());
    assertTrue(v.supports(context));
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 15 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class OAuth20TokenResponseTypeAuthorizationRequestValidatorTests method verifySupports.

@Test
public void verifySupports() throws Exception {
    val serviceManager = mock(ServicesManager.class);
    val service = new OAuthRegisteredService();
    service.setName("OAuth");
    service.setClientId("client");
    service.setClientSecret("secret");
    service.setServiceId("https://callback.example.org");
    when(serviceManager.getAllServices()).thenReturn((Collection) CollectionUtils.toCollection(service));
    when(serviceManager.getAllServicesOfType(any())).thenReturn((Collection) CollectionUtils.toCollection(service));
    val v = new OAuth20TokenResponseTypeAuthorizationRequestValidator(serviceManager, new WebApplicationServiceFactory(), new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()));
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.getType());
    request.setParameter(OAuth20Constants.CLIENT_ID, "client");
    request.setParameter(OAuth20Constants.REDIRECT_URI, service.getServiceId());
    assertFalse(v.supports(context));
    request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.TOKEN.getType());
    assertTrue(v.supports(context));
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)25 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)25 RegisteredServiceAccessStrategyAuditableEnforcer (org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer)25 Test (org.junit.jupiter.api.Test)22 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)6 DefaultRegisteredServiceAccessStrategy (org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)6 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)4 JEEContext (org.pac4j.core.context.JEEContext)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)1 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)1 DefaultRegisteredServiceProperty (org.apereo.cas.services.DefaultRegisteredServiceProperty)1 DefaultServicesManager (org.apereo.cas.services.DefaultServicesManager)1 DefaultServicesManagerRegisteredServiceLocator (org.apereo.cas.services.DefaultServicesManagerRegisteredServiceLocator)1 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)1 RegisteredServiceResponseHeadersEnforcementFilter (org.apereo.cas.services.web.support.RegisteredServiceResponseHeadersEnforcementFilter)1