use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class OAuth20RefreshTokenGrantTypeTokenRequestValidatorTests method registerTicket.
private void registerTicket(final String name, final String clientId) throws Exception {
val tgt = new MockTicketGrantingTicket("casuser");
val token = mock(OAuth20RefreshToken.class);
when(token.getId()).thenReturn(name);
when(token.getService()).thenReturn(RegisteredServiceTestUtils.getService(name));
when(token.isExpired()).thenReturn(false);
when(token.getAuthentication()).thenReturn(tgt.getAuthentication());
when(token.getTicketGrantingTicket()).thenReturn(tgt);
when(token.getClientId()).thenReturn(clientId);
ticketRegistry.addTicket(token);
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class OAuth20ProofKeyCodeExchangeAuthenticatorTests method verifyAuthenticationPlainWithoutSecret.
@Test
public void verifyAuthenticationPlainWithoutSecret() throws Exception {
val credentials = new UsernamePasswordCredentials("clientWithoutSecret", "ABCD123");
val request = new MockHttpServletRequest();
ticketRegistry.addTicket(new OAuth20DefaultCode("CODE-1234567890", RegisteredServiceTestUtils.getService(), RegisteredServiceTestUtils.getAuthentication(), new HardTimeoutExpirationPolicy(10), new MockTicketGrantingTicket("casuser"), new ArrayList<>(), "ABCD123", "plain", "clientid12345", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE));
request.addParameter(OAuth20Constants.CLIENT_ID, "clientWithoutSecret");
request.addParameter(OAuth20Constants.CODE_VERIFIER, "ABCD123");
request.addParameter(OAuth20Constants.CODE, "CODE-1234567890");
val ctx = new JEEContext(request, new MockHttpServletResponse());
authenticator.validate(credentials, ctx, JEESessionStore.INSTANCE);
assertNotNull(credentials.getUserProfile());
assertEquals("clientWithoutSecret", credentials.getUserProfile().getId());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class OAuth20TicketGrantingTicketAwareSecurityLogicTests method verifyLoadWithValidTicket.
@Test
public void verifyLoadWithValidTicket() {
when(centralAuthenticationService.getTicket(anyString(), any())).thenReturn(new MockTicketGrantingTicket("casuser"));
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
val profileManager = new ProfileManager(context, JEESessionStore.INSTANCE);
profileManager.save(true, new BasicUserProfile(), false);
JEESessionStore.INSTANCE.set(context, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, UUID.randomUUID().toString());
val logic = new OAuth20TicketGrantingTicketAwareSecurityLogic(ticketGrantingTicketCookieGenerator, ticketRegistry, centralAuthenticationService);
assertFalse(logic.loadProfiles(profileManager, context, JEESessionStore.INSTANCE, List.of()).isEmpty());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class AbstractCasEventRepositoryTests method getCasEvent.
private CasEvent getCasEvent(final String user) {
val ticket = new MockTicketGrantingTicket(user);
val event = new CasTicketGrantingTicketCreatedEvent(this, ticket);
val dto = new CasEvent();
dto.setType(event.getClass().getCanonicalName());
dto.putTimestamp(event.getTimestamp());
dto.setCreationTime(event.getTicketGrantingTicket().getCreationTime().format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
dto.putEventId(event.getTicketGrantingTicket().getId());
dto.putClientIpAddress("1.2.3.4");
dto.putServerIpAddress("1.2.3.4");
val location = new GeoLocationRequest(1234, 1234);
location.setAccuracy("80");
location.setTimestamp(String.valueOf(event.getTimestamp()));
dto.putGeoLocation(location);
dto.setPrincipalId(event.getTicketGrantingTicket().getAuthentication().getPrincipal().getId());
return dto;
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class CasAuthenticationEventListenerTests method verifyTicketGrantingTicketCreated.
@Test
public void verifyTicketGrantingTicketCreated() {
val tgt = new MockTicketGrantingTicket("casuser");
val event = new CasTicketGrantingTicketCreatedEvent(this, tgt);
applicationContext.publishEvent(event);
assertFalse(casEventRepository.load().findAny().isEmpty());
}
Aggregations