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;
}
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);
}
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);
}
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));
}
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);
}
Aggregations