Search in sources :

Example 11 with Credentials

use of org.pac4j.core.credentials.Credentials in project pac4j by pac4j.

the class LocalCachingAuthenticatorTests method testDoubleCalls.

@Test
public void testDoubleCalls() {
    final OnlyOneCallAuthenticator authenticator = new OnlyOneCallAuthenticator();
    final LocalCachingAuthenticator localCachingAuthenticator = new LocalCachingAuthenticator(authenticator, 10, 10, TimeUnit.SECONDS);
    localCachingAuthenticator.init();
    final Credentials credentials1 = new UsernamePasswordCredentials("a", "a");
    localCachingAuthenticator.validate(credentials1, null);
    final Credentials credentials2 = new UsernamePasswordCredentials("a", "a");
    localCachingAuthenticator.validate(credentials2, null);
}
Also used : UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Credentials(org.pac4j.core.credentials.Credentials) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 12 with Credentials

use of org.pac4j.core.credentials.Credentials 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

Credentials (org.pac4j.core.credentials.Credentials)12 CommonProfile (org.pac4j.core.profile.CommonProfile)7 Client (org.pac4j.core.client.Client)4 Clients (org.pac4j.core.client.Clients)4 WebContext (org.pac4j.core.context.WebContext)4 ClientCredential (org.apereo.cas.authentication.principal.ClientCredential)3 Test (org.junit.Test)3 BaseClient (org.pac4j.core.client.BaseClient)3 HttpAction (org.pac4j.core.exception.HttpAction)3 Optional (java.util.Optional)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)2 Service (org.apereo.cas.authentication.principal.Service)2 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)2 IndirectClient (org.pac4j.core.client.IndirectClient)2 MockWebContext (org.pac4j.core.context.MockWebContext)2 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)2 UserProfile (org.pac4j.core.profile.UserProfile)2 ImmutableList (com.google.common.collect.ImmutableList)1