Search in sources :

Example 1 with JavaSerializer

use of org.pac4j.core.util.serializer.JavaSerializer in project pac4j by pac4j.

the class RunClient method run.

public void run() {
    final var client = getClient();
    final var context = MockWebContext.create();
    final SessionStore sessionStore = new MockSessionStore();
    final var url = ((FoundAction) client.getRedirectionAction(context, sessionStore).get()).getLocation();
    logger.warn("Redirect to: \n{}", url);
    if (CommonHelper.isNotBlank(getLogin()) && CommonHelper.isNotBlank(getPassword())) {
        logger.warn("Use credentials: {} / {}", getLogin(), getPassword());
    } else {
        logger.warn("Use your own personal credentials");
    }
    if (canCancel()) {
        logger.warn("You can CANCEL the authentication.");
    }
    logger.warn("Returned url (copy/paste the fragment starting before the question mark of the query string):");
    final var scanner = new Scanner(System.in, StandardCharsets.UTF_8.name());
    final var returnedUrl = scanner.nextLine().trim();
    populateContextWithUrl(context, returnedUrl);
    final var credentials = client.getCredentials(context, sessionStore);
    if (credentials.isPresent()) {
        final var profile = client.getUserProfile(credentials.get(), context, sessionStore);
        logger.debug("userProfile: {}", profile);
        if (profile.isPresent() || !canCancel()) {
            verifyProfile((CommonProfile) profile.get());
            logger.warn("## Java serialization");
            final var javaSerializer = new JavaSerializer();
            var bytes = javaSerializer.serializeToBytes(profile.get());
            final var profile2 = (CommonProfile) javaSerializer.deserializeFromBytes(bytes);
            verifyProfile(profile2);
        }
    }
    logger.warn("################");
    logger.warn("Test successful!");
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SessionStore(org.pac4j.core.context.session.SessionStore) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) JavaSerializer(org.pac4j.core.util.serializer.JavaSerializer)

Aggregations

MockSessionStore (org.pac4j.core.context.session.MockSessionStore)1 SessionStore (org.pac4j.core.context.session.SessionStore)1 FoundAction (org.pac4j.core.exception.http.FoundAction)1 JavaSerializer (org.pac4j.core.util.serializer.JavaSerializer)1