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