use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableList.
@Test
public void verifyEncodeDecodeTGTWithUnmodifiableList() {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final List<String> values = new ArrayList<>();
values.add(NICKNAME_VALUE);
final Map<String, Object> newAttributes = new HashMap<>();
newAttributes.put(NICKNAME_KEY, new ArrayList<>(values));
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
final CachedData result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithSingletonMap.
@Test
public void verifyEncodeDecodeTGTWithSingletonMap() {
final Map<String, Object> newAttributes = Collections.singletonMap(NICKNAME_KEY, NICKNAME_VALUE);
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
final CachedData result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class AbstractOAuth20Tests method addRefreshToken.
protected RefreshToken addRefreshToken(final Principal principal, final RegisteredService registeredService) {
final Authentication authentication = getAuthentication(principal);
final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
final Service service = factory.createService(registeredService.getServiceId());
final RefreshToken refreshToken = oAuthRefreshTokenFactory.create(service, authentication, new MockTicketGrantingTicket("casuser"), new ArrayList<>());
this.ticketRegistry.addTicket(refreshToken);
return refreshToken;
}
use of org.apereo.cas.mock.MockTicketGrantingTicket 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, new MockTicketGrantingTicket("casuser"), new ArrayList<>());
this.ticketRegistry.addTicket(refreshToken);
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.REFRESH_TOKEN.name().toLowerCase());
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.CLIENT_SECRET, CLIENT_SECRET);
mockRequest.setParameter(OAuth20Constants.REFRESH_TOKEN, refreshToken.getId());
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
oAuth20AccessTokenController.handleRequest(mockRequest, mockResponse);
assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus());
assertEquals(ERROR_EQUALS + OAuth20Constants.INVALID_REQUEST, mockResponse.getContentAsString());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class JWTTokenTicketBuilderTests method verifyJwtForTicketGrantingTicket.
@Test
public void verifyJwtForTicketGrantingTicket() throws Exception {
final MockTicketGrantingTicket tgt = new MockTicketGrantingTicket("casuser");
final String jwt = tokenTicketBuilder.build(tgt);
assertNotNull(jwt);
final Object result = tokenCipherExecutor.decode(jwt);
final JWTClaimsSet claims = JWTClaimsSet.parse(result.toString());
assertEquals(claims.getSubject(), tgt.getAuthentication().getPrincipal().getId());
}
Aggregations