Search in sources :

Example 31 with MockTicketGrantingTicket

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));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) CachedData(net.spy.memcached.CachedData) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ArrayList(java.util.ArrayList) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 32 with MockTicketGrantingTicket

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));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) CachedData(net.spy.memcached.CachedData) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 33 with MockTicketGrantingTicket

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;
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) RefreshToken(org.apereo.cas.ticket.refreshtoken.RefreshToken) Authentication(org.apereo.cas.authentication.Authentication) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) RegisteredService(org.apereo.cas.services.RegisteredService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 34 with MockTicketGrantingTicket

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());
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) 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)

Example 35 with MockTicketGrantingTicket

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());
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)35 Test (org.junit.Test)30 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)21 Credential (org.apereo.cas.authentication.Credential)16 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)16 HashMap (java.util.HashMap)10 CachedData (net.spy.memcached.CachedData)10 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)9 Authentication (org.apereo.cas.authentication.Authentication)8 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)8 LinkedHashMap (java.util.LinkedHashMap)6 Principal (org.apereo.cas.authentication.principal.Principal)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)5 AlwaysExpiresExpirationPolicy (org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy)5 Service (org.apereo.cas.authentication.principal.Service)4 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)4 RegisteredService (org.apereo.cas.services.RegisteredService)4 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)4