Search in sources :

Example 1 with JavaSerializationHelper

use of org.pac4j.core.util.JavaSerializationHelper in project pac4j by pac4j.

the class CommonProfileTests method serializeProfile.

@Test
public void serializeProfile() {
    final JavaSerializationHelper helper = new JavaSerializationHelper();
    final CommonProfile profile = new CommonProfile();
    final String s = helper.serializeToBase64(profile);
    final CommonProfile profile2 = (CommonProfile) helper.unserializeFromBase64(s);
    assertNotNull(profile2);
}
Also used : JavaSerializationHelper(org.pac4j.core.util.JavaSerializationHelper) Test(org.junit.Test)

Example 2 with JavaSerializationHelper

use of org.pac4j.core.util.JavaSerializationHelper in project pac4j by pac4j.

the class OAuthCredentialsTests method testOAuth10Credentials.

@Test
public void testOAuth10Credentials() {
    final OAuth10Credentials credentials = new OAuth10Credentials(REQUEST_TOKEN, TOKEN, VERIFIER);
    assertEquals(TOKEN, credentials.getToken());
    assertEquals(VERIFIER, credentials.getVerifier());
    final OAuth1RequestToken requestToken = credentials.getRequestToken();
    assertEquals(TOKEN, requestToken.getToken());
    assertEquals(SECRET, requestToken.getTokenSecret());
    // test serialization
    final JavaSerializationHelper javaSerializationHelper = new JavaSerializationHelper();
    final byte[] bytes = javaSerializationHelper.serializeToBytes(credentials);
    final OAuth10Credentials credentials2 = (OAuth10Credentials) javaSerializationHelper.unserializeFromBytes(bytes);
    assertEquals(credentials.getRequestToken().toString(), credentials2.getRequestToken().toString());
    assertEquals(credentials.getToken(), credentials2.getToken());
    assertEquals(credentials.getVerifier(), credentials2.getVerifier());
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) JavaSerializationHelper(org.pac4j.core.util.JavaSerializationHelper) Test(org.junit.Test)

Example 3 with JavaSerializationHelper

use of org.pac4j.core.util.JavaSerializationHelper in project pac4j by pac4j.

the class RunClient method run.

public void run() {
    final IndirectClient client = getClient();
    final MockWebContext context = MockWebContext.create();
    final String url = client.getRedirectAction(context).getLocation();
    logger.warn("Redirect to: \n{}", url);
    logger.warn("Use credentials: {} / {}", getLogin(), getPassword());
    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 Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8.name());
    final String returnedUrl = scanner.nextLine().trim();
    populateContextWithUrl(context, returnedUrl);
    final Credentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    logger.debug("userProfile: {}", profile);
    if (profile != null || !canCancel()) {
        verifyProfile(profile);
        logger.warn("## Java serialization");
        final JavaSerializationHelper javaSerializationHelper = new JavaSerializationHelper();
        byte[] bytes = javaSerializationHelper.serializeToBytes(profile);
        final CommonProfile profile2 = (CommonProfile) javaSerializationHelper.unserializeFromBytes(bytes);
        verifyProfile(profile2);
    }
    logger.warn("################");
    logger.warn("Test successful!");
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) JavaSerializationHelper(org.pac4j.core.util.JavaSerializationHelper) IndirectClient(org.pac4j.core.client.IndirectClient) Credentials(org.pac4j.core.credentials.Credentials)

Aggregations

JavaSerializationHelper (org.pac4j.core.util.JavaSerializationHelper)3 Test (org.junit.Test)2 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)1 IndirectClient (org.pac4j.core.client.IndirectClient)1 MockWebContext (org.pac4j.core.context.MockWebContext)1 Credentials (org.pac4j.core.credentials.Credentials)1