use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectCasClientTests method testTicketExistsValidationOccurs.
@Test
public void testTicketExistsValidationOccurs() {
final var configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
configuration.setDefaultTicketValidator((ticket, service) -> {
if (TICKET.equals(ticket) && CALLBACK_URL.equals(service)) {
return new AssertionImpl(TICKET);
}
throw new TechnicalException("Bad ticket or service");
});
final var client = new DirectCasClient(configuration);
final var context = MockWebContext.create();
context.setFullRequestURL(CALLBACK_URL + "?" + CasConfiguration.TICKET_PARAMETER + "=" + TICKET);
context.addRequestParameter(CasConfiguration.TICKET_PARAMETER, TICKET);
final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
assertEquals(TICKET, credentials.getToken());
final var profile = credentials.getUserProfile();
assertTrue(profile instanceof CasProfile);
assertEquals(TICKET, profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CasRestClientIT method internalTestRestForm.
private void internalTestRestForm(final Authenticator authenticator) {
final var client = new CasRestFormClient();
client.setConfiguration(getConfig());
client.setAuthenticator(authenticator);
final var context = MockWebContext.create();
context.addRequestParameter(client.getUsernameParameter(), USER);
context.addRequestParameter(client.getPasswordParameter(), USER);
final var credentials = (UsernamePasswordCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CasRestProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals(USER, profile.getId());
assertNotNull(profile.getTicketGrantingTicketId());
final var casCreds = client.requestServiceTicket(PAC4J_BASE_URL, profile, context);
final var casProfile = client.validateServiceTicket(PAC4J_BASE_URL, casCreds, context);
assertNotNull(casProfile);
assertEquals(USER, casProfile.getId());
assertTrue(casProfile.getAttributes().size() > 0);
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CasRedirectionActionBuilderTest method testRedirectRenewAttribute.
@Test
public void testRedirectRenewAttribute() {
final var builder = newBuilder(new CasConfiguration());
final var context = MockWebContext.create();
context.setRequestAttribute(RedirectionActionBuilder.ATTRIBUTE_FORCE_AUTHN, true);
final var action = builder.getRedirectionAction(context, new MockSessionStore()).get();
assertTrue(action instanceof FoundAction);
assertTrue(((FoundAction) action).getLocation().contains("renew=true"));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultCasAuthorizationGeneratorTests method testIsRemembered.
@Test
public void testIsRemembered() {
final AuthorizationGenerator generator = new DefaultCasAuthorizationGenerator();
final Map<String, Object> attributes = new HashMap<>();
attributes.put(DefaultCasAuthorizationGenerator.DEFAULT_REMEMBER_ME_ATTRIBUTE_NAME, "true");
final var profile = new CasProfile();
profile.build(ID, attributes);
generator.generate(null, new MockSessionStore(), profile);
assertEquals(true, profile.isRemembered());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultCasAuthorizationGeneratorTests method testBadAttributeValue.
@Test
public void testBadAttributeValue() {
final AuthorizationGenerator generator = new DefaultCasAuthorizationGenerator();
final Map<String, Object> attributes = new HashMap<>();
attributes.put(DefaultCasAuthorizationGenerator.DEFAULT_REMEMBER_ME_ATTRIBUTE_NAME, "yes");
final var profile = new CasProfile();
profile.build(ID, attributes);
generator.generate(null, new MockSessionStore(), profile);
assertEquals(false, profile.isRemembered());
}
Aggregations