use of org.pac4j.core.context.MockWebContext 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