Search in sources :

Example 11 with WebApplicationServiceFactory

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

the class CentralAuthenticationServiceImplTests 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 12 with WebApplicationServiceFactory

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

the class InitialFlowSetupActionCookieTests method setUp.

@Before
public void setUp() throws Exception {
    this.warnCookieGenerator = new CookieRetrievingCookieGenerator("warn", "", 2, false, null);
    this.warnCookieGenerator.setCookiePath(StringUtils.EMPTY);
    this.tgtCookieGenerator = new CookieRetrievingCookieGenerator("tgt", "", 2, false, null);
    this.tgtCookieGenerator.setCookiePath(StringUtils.EMPTY);
    final List<ArgumentExtractor> argExtractors = Collections.singletonList(new DefaultArgumentExtractor(new WebApplicationServiceFactory()));
    final ServicesManager servicesManager = mock(ServicesManager.class);
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(RegisteredServiceTestUtils.getRegisteredService("test"));
    this.action = new InitialFlowSetupAction(argExtractors, servicesManager, tgtCookieGenerator, warnCookieGenerator, casProperties);
    this.action.afterPropertiesSet();
}
Also used : ArgumentExtractor(org.apereo.cas.web.support.ArgumentExtractor) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) ServicesManager(org.apereo.cas.services.ServicesManager) CookieRetrievingCookieGenerator(org.apereo.cas.web.support.CookieRetrievingCookieGenerator) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) Service(org.apereo.cas.authentication.principal.Service) Before(org.junit.Before)

Example 13 with WebApplicationServiceFactory

use of org.apereo.cas.authentication.principal.WebApplicationServiceFactory 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 14 with WebApplicationServiceFactory

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

the class OAuth20AccessTokenControllerTests method verifyRefreshTokenExpiredToken.

@Test
public void verifyRefreshTokenExpiredToken() throws Exception {
    final Principal principal = createPrincipal();
    final RegisteredService registeredService = addRegisteredService();
    final Authentication authentication = getAuthentication(principal);
    final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
    final Service service = factory.createService(registeredService.getServiceId());
    final DefaultRefreshTokenFactory expiringRefreshTokenFactory = new DefaultRefreshTokenFactory(new AlwaysExpiresExpirationPolicy());
    final RefreshToken refreshToken = expiringRefreshTokenFactory.create(service, authentication);
    oAuth20AccessTokenController.getTicketRegistry().addTicket(refreshToken);
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.GRANT_TYPE, OAuth20GrantTypes.REFRESH_TOKEN.name().toLowerCase());
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.REFRESH_TOKEN, refreshToken.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_GRANT, mockResponse.getContentAsString());
}
Also used : DefaultRefreshTokenFactory(org.apereo.cas.ticket.refreshtoken.DefaultRefreshTokenFactory) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) RefreshToken(org.apereo.cas.ticket.refreshtoken.RefreshToken) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) 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) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy) 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