Search in sources :

Example 1 with ClientInfoAuthenticationMetaDataPopulator

use of org.apereo.cas.authentication.metadata.ClientInfoAuthenticationMetaDataPopulator in project cas by apereo.

the class ClientInfoAuthenticationMetaDataPopulatorTests method verifyOperation.

@Test
public void verifyOperation() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("223.456.789.000");
    request.setLocalAddr("123.456.789.000");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val populator = new ClientInfoAuthenticationMetaDataPopulator();
    val c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    val builder = DefaultAuthenticationBuilder.newInstance(CoreAuthenticationTestUtils.getAuthentication());
    assertTrue(populator.supports(c));
    populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(c));
    val authn = builder.build();
    val attributes = authn.getAttributes();
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_CLIENT_IP_ADDRESS));
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_SERVER_IP_ADDRESS));
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_USER_AGENT));
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_GEO_LOCATION));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) ClientInfoAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.ClientInfoAuthenticationMetaDataPopulator) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)1 ClientInfoAuthenticationMetaDataPopulator (org.apereo.cas.authentication.metadata.ClientInfoAuthenticationMetaDataPopulator)1 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)1 Test (org.junit.jupiter.api.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1