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);
}
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());
}
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!");
}
Aggregations