Search in sources :

Example 1 with WebApplicationServiceFactory

use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.

the class CentralAuthenticationServiceImplWithMockitoTests method getService.

private static Service getService(final String name) {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, name);
    return new WebApplicationServiceFactory().createService(request);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory)

Example 2 with WebApplicationServiceFactory

use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.

the class TicketsResourceTests method setUp.

@Before
public void setUp() throws Exception {
    final AuthenticationManager mgmr = mock(AuthenticationManager.class);
    when(mgmr.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
    when(ticketSupport.getAuthenticationFrom(anyString())).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
    this.ticketsResourceUnderTest = new TicketsResource(new DefaultAuthenticationSystemSupport(new DefaultAuthenticationTransactionManager(mgmr), new DefaultPrincipalElectionStrategy()), new DefaultCredentialFactory(), ticketSupport, new WebApplicationServiceFactory(), casMock);
    this.mockMvc = MockMvcBuilders.standaloneSetup(this.ticketsResourceUnderTest).defaultRequest(get("/").contextPath("/cas").contentType(MediaType.APPLICATION_FORM_URLENCODED)).build();
}
Also used : AuthenticationManager(org.apereo.cas.authentication.AuthenticationManager) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.DefaultPrincipalElectionStrategy) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager) Before(org.junit.Before)

Example 3 with WebApplicationServiceFactory

use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.

the class ManageRegisteredServicesMultiActionControllerTests method verifyCustomComponents.

@Test
public void verifyCustomComponents() throws Exception {
    // override the RegisteredServiceMapper
    this.registeredServiceFactory = new DefaultRegisteredServiceFactory(new DefaultAccessStrategyMapper(), policyMapper, new DefaultProxyPolicyMapper(), new CustomRegisteredServiceMapper(), new DefaultUsernameAttributeProviderMapper(), Collections.emptyList());
    this.controller = new ManageRegisteredServicesMultiActionController(this.servicesManager, this.registeredServiceFactory, new WebApplicationServiceFactory(), "https://cas.example.org");
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setId(1200);
    r.setName(NAME);
    r.setDescription(UNIQUE_DESCRIPTION);
    r.setServiceId("test");
    r.setEvaluationOrder(2);
    this.servicesManager.save(r);
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final ModelAndView mv = this.controller.manage(response);
    assertTrue(mv.getModel().containsKey("defaultServiceUrl"));
    assertTrue(mv.getModel().containsKey("status"));
    this.controller.getServices(response);
    final String content = response.getContentAsString();
    assertTrue(content.contains(SERVICES));
    assertTrue(content.contains(UNIQUE_DESCRIPTION));
    assertTrue(content.contains("customComponent1"));
    assertTrue(content.contains("key2"));
}
Also used : WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) ModelAndView(org.springframework.web.servlet.ModelAndView) DefaultAccessStrategyMapper(org.apereo.cas.mgmt.services.web.factory.DefaultAccessStrategyMapper) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) DefaultRegisteredServiceFactory(org.apereo.cas.mgmt.services.web.factory.DefaultRegisteredServiceFactory) DefaultProxyPolicyMapper(org.apereo.cas.mgmt.services.web.factory.DefaultProxyPolicyMapper) DefaultUsernameAttributeProviderMapper(org.apereo.cas.mgmt.services.web.factory.DefaultUsernameAttributeProviderMapper) ManageRegisteredServicesMultiActionController(org.apereo.cas.mgmt.services.web.ManageRegisteredServicesMultiActionController) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 4 with WebApplicationServiceFactory

use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.

the class OAuthWebApplicationServiceTests method verifySerializeACompletePrincipalToJson.

@Test
public void verifySerializeACompletePrincipalToJson() throws IOException {
    final AbstractRegisteredService service = new OAuthRegisteredService();
    service.setName("checkCloning");
    service.setServiceId("testId");
    service.setTheme("theme");
    service.setDescription("description");
    final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
    final WebApplicationService serviceWritten = factory.createService(service.getServiceId());
    MAPPER.writeValue(JSON_FILE, serviceWritten);
    final WebApplicationService serviceRead = MAPPER.readValue(JSON_FILE, WebApplicationService.class);
    assertEquals(serviceWritten, serviceRead);
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Test(org.junit.Test)

Example 5 with WebApplicationServiceFactory

use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory in project cas by apereo.

the class OAuth20AccessTokenControllerTests method verifyClientExpiredCode.

@Test
public void verifyClientExpiredCode() throws Exception {
    final RegisteredService registeredService = getRegisteredService(REDIRECT_URI, CLIENT_SECRET);
    servicesManager.save(registeredService);
    final Map<String, Object> map = new HashMap<>();
    map.put(NAME, VALUE);
    final List<String> list = Arrays.asList(VALUE, VALUE);
    map.put(NAME2, list);
    final Principal principal = CoreAuthenticationTestUtils.getPrincipal(ID, map);
    final Authentication authentication = getAuthentication(principal);
    final DefaultOAuthCodeFactory expiringOAuthCodeFactory = new DefaultOAuthCodeFactory(new AlwaysExpiresExpirationPolicy());
    final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
    final Service service = factory.createService(registeredService.getServiceId());
    final OAuthCode code = expiringOAuthCodeFactory.create(service, authentication);
    oAuth20AccessTokenController.getTicketRegistry().addTicket(code);
    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);
    mockRequest.setParameter(OAuthConstants.CODE, code.getId());
    mockRequest.setParameter(OAuthConstants.GRANT_TYPE, OAuth20GrantTypes.AUTHORIZATION_CODE.name().toLowerCase());
    servicesManager.save(getRegisteredService(REDIRECT_URI, CLIENT_SECRET));
    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_GRANT, mockResponse.getContentAsString());
}
Also used : OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy) OAuthCode(org.apereo.cas.ticket.code.OAuthCode) Authentication(org.apereo.cas.authentication.Authentication) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) DefaultOAuthCodeFactory(org.apereo.cas.ticket.code.DefaultOAuthCodeFactory) Principal(org.apereo.cas.authentication.principal.Principal) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)14 Service (org.apereo.cas.authentication.principal.Service)6 Test (org.junit.Test)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 RegisteredService (org.apereo.cas.services.RegisteredService)5 Authentication (org.apereo.cas.authentication.Authentication)4 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)4 Before (org.junit.Before)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 Principal (org.apereo.cas.authentication.principal.Principal)2 ManageRegisteredServicesMultiActionController (org.apereo.cas.mgmt.services.web.ManageRegisteredServicesMultiActionController)2 DefaultAccessStrategyMapper (org.apereo.cas.mgmt.services.web.factory.DefaultAccessStrategyMapper)2 DefaultProxyPolicyMapper (org.apereo.cas.mgmt.services.web.factory.DefaultProxyPolicyMapper)2 DefaultRegisteredServiceFactory (org.apereo.cas.mgmt.services.web.factory.DefaultRegisteredServiceFactory)2 DefaultUsernameAttributeProviderMapper (org.apereo.cas.mgmt.services.web.factory.DefaultUsernameAttributeProviderMapper)2 DefaultServicesManager (org.apereo.cas.services.DefaultServicesManager)2 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)2 OAuthCode (org.apereo.cas.ticket.code.OAuthCode)2 RefreshToken (org.apereo.cas.ticket.refreshtoken.RefreshToken)2 AlwaysExpiresExpirationPolicy (org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy)2