Search in sources :

Example 1 with IpProfile

use of org.pac4j.http.profile.IpProfile in project pac4j by pac4j.

the class IpRegexpAuthenticatorTests method testValidateGoodIP.

@Test
public void testValidateGoodIP() {
    final TokenCredentials credentials = new TokenCredentials(GOOD_IP);
    authenticator.validate(credentials, null);
    final IpProfile profile = (IpProfile) credentials.getUserProfile();
    assertEquals(GOOD_IP, profile.getId());
}
Also used : IpProfile(org.pac4j.http.profile.IpProfile) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 2 with IpProfile

use of org.pac4j.http.profile.IpProfile in project pac4j by pac4j.

the class IpRegexpAuthenticator method validate.

@Override
public void validate(final TokenCredentials credentials, final WebContext context) {
    init();
    final String ip = credentials.getToken();
    if (!this.pattern.matcher(ip).matches()) {
        throw new CredentialsException("Unauthorized IP address: " + ip);
    }
    final IpProfile profile = getProfileDefinition().newProfile();
    profile.setId(ip);
    logger.debug("profile: {}", profile);
    credentials.setUserProfile(profile);
}
Also used : CredentialsException(org.pac4j.core.exception.CredentialsException) IpProfile(org.pac4j.http.profile.IpProfile)

Aggregations

IpProfile (org.pac4j.http.profile.IpProfile)2 Test (org.junit.Test)1 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)1 CredentialsException (org.pac4j.core.exception.CredentialsException)1