Search in sources :

Example 1 with OAuth20DefaultOAuthCodeFactory

use of org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory in project cas by apereo.

the class OAuth20AuthorizationCodeGrantTypeTokenRequestValidatorTests method registerTicket.

private OAuth20Code registerTicket(final OAuthRegisteredService service) throws Exception {
    val builder = new OAuth20DefaultCasAuthenticationBuilder(PrincipalFactoryUtils.newPrincipalFactory(), new WebApplicationServiceFactory(), new DefaultOAuth20ProfileScopeToAttributesFilter(), new CasConfigurationProperties());
    val oauthCasAuthenticationBuilderService = builder.buildService(service, null, false);
    val expirationPolicy = new ExpirationPolicyBuilder() {

        private static final long serialVersionUID = 3911344031977989503L;

        @Override
        public ExpirationPolicy buildTicketExpirationPolicy() {
            return new OAuth20CodeExpirationPolicy(1, 60);
        }

        @Override
        public Class getTicketType() {
            return OAuth20Code.class;
        }
    };
    val oauthCode = new OAuth20DefaultOAuthCodeFactory(expirationPolicy, mock(ServicesManager.class)).create(oauthCasAuthenticationBuilderService, RegisteredServiceTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), new HashSet<>(), null, null, "clientid12345", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
    this.ticketRegistry.addTicket(oauthCode);
    return oauthCode;
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) OAuth20Code(org.apereo.cas.ticket.code.OAuth20Code) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) OAuth20DefaultCasAuthenticationBuilder(org.apereo.cas.support.oauth.authenticator.OAuth20DefaultCasAuthenticationBuilder) OAuth20DefaultOAuthCodeFactory(org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory) ExpirationPolicyBuilder(org.apereo.cas.ticket.ExpirationPolicyBuilder) OAuth20CodeExpirationPolicy(org.apereo.cas.ticket.code.OAuth20CodeExpirationPolicy) DefaultOAuth20ProfileScopeToAttributesFilter(org.apereo.cas.support.oauth.profile.DefaultOAuth20ProfileScopeToAttributesFilter)

Example 2 with OAuth20DefaultOAuthCodeFactory

use of org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory in project cas by apereo.

the class MemcachedTicketRegistryTests method verifyOAuthCodeIsAddedToMemcached.

@RepeatedTest(2)
public void verifyOAuthCodeIsAddedToMemcached() throws Exception {
    val factory = new OAuth20DefaultOAuthCodeFactory(neverExpiresExpirationPolicyBuilder(), servicesManager);
    val code = factory.create(RegisteredServiceTestUtils.getService(), CoreAuthenticationTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), CollectionUtils.wrapList("openid"), "code-challenge", "plain", "clientId123456", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
    this.newTicketRegistry.addTicket(code);
    val ticket = this.newTicketRegistry.getTicket(code.getId(), OAuth20Code.class);
    assertNotNull(ticket);
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) OAuth20DefaultOAuthCodeFactory(org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 3 with OAuth20DefaultOAuthCodeFactory

use of org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory in project cas by apereo.

the class BaseOAuth20ExpirationPolicyTests method createOAuthCode.

protected OAuth20Code createOAuthCode() {
    val builder = mock(ExpirationPolicyBuilder.class);
    when(builder.buildTicketExpirationPolicy()).thenReturn(NeverExpiresExpirationPolicy.INSTANCE);
    return new OAuth20DefaultOAuthCodeFactory(builder, servicesManager).create(RegisteredServiceTestUtils.getService(), RegisteredServiceTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), CollectionUtils.wrapSet("1", "2"), "code-challenge", "code-challenge-method", "clientId1234567", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) OAuth20DefaultOAuthCodeFactory(org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory)

Example 4 with OAuth20DefaultOAuthCodeFactory

use of org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory in project cas by apereo.

the class OAuth20AccessTokenEndpointControllerTests method verifyClientExpiredCode.

@ParameterizedTest
@MethodSource("getParameters")
public void verifyClientExpiredCode(final OAuthRegisteredService registeredService) throws Exception {
    servicesManager.save(registeredService);
    val map = new HashMap<String, List<Object>>();
    map.put(NAME, List.of(VALUE));
    val list = List.of(VALUE, VALUE);
    map.put(NAME2, (List) list);
    val principal = CoreAuthenticationTestUtils.getPrincipal(ID, map);
    val authentication = getAuthentication(principal);
    val expiringOAuthCodeFactory = new OAuth20DefaultOAuthCodeFactory(alwaysExpiresExpirationPolicyBuilder(), servicesManager);
    val factory = new WebApplicationServiceFactory();
    val service = factory.createService(registeredService.getServiceId());
    val code = expiringOAuthCodeFactory.create(service, authentication, new MockTicketGrantingTicket("casuser"), new ArrayList<>(), null, null, CLIENT_ID, new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
    this.ticketRegistry.addTicket(code);
    val mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuth20Constants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuth20Constants.CODE, code.getId());
    mockRequest.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.AUTHORIZATION_CODE.name().toLowerCase());
    val mockResponse = new MockHttpServletResponse();
    requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
    val mv = accessTokenController.handleRequest(mockRequest, mockResponse);
    assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus());
    assertEquals(OAuth20Constants.INVALID_GRANT, mv.getModel().get(OAuth20Constants.ERROR));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) OAuth20DefaultOAuthCodeFactory(org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with OAuth20DefaultOAuthCodeFactory

use of org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory in project cas by apereo.

the class JpaTicketRegistryCleanerTests method createOAuthCode.

private OAuth20Code createOAuthCode() {
    val builder = mock(ExpirationPolicyBuilder.class);
    when(builder.buildTicketExpirationPolicy()).thenReturn(NeverExpiresExpirationPolicy.INSTANCE);
    return new OAuth20DefaultOAuthCodeFactory(builder, servicesManager).create(RegisteredServiceTestUtils.getService(), RegisteredServiceTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), CollectionUtils.wrapSet("1", "2"), "code-challenge", "code-challenge-method", "clientId1234567", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) OAuth20DefaultOAuthCodeFactory(org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory)

Aggregations

lombok.val (lombok.val)5 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)5 OAuth20DefaultOAuthCodeFactory (org.apereo.cas.ticket.code.OAuth20DefaultOAuthCodeFactory)5 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)2 HashMap (java.util.HashMap)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 OAuth20DefaultCasAuthenticationBuilder (org.apereo.cas.support.oauth.authenticator.OAuth20DefaultCasAuthenticationBuilder)1 DefaultOAuth20ProfileScopeToAttributesFilter (org.apereo.cas.support.oauth.profile.DefaultOAuth20ProfileScopeToAttributesFilter)1 ExpirationPolicyBuilder (org.apereo.cas.ticket.ExpirationPolicyBuilder)1 OAuth20Code (org.apereo.cas.ticket.code.OAuth20Code)1 OAuth20CodeExpirationPolicy (org.apereo.cas.ticket.code.OAuth20CodeExpirationPolicy)1 RepeatedTest (org.junit.jupiter.api.RepeatedTest)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1