Search in sources :

Example 56 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class InitPasswordResetActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("1.2.3.4");
    request.setLocalAddr("1.2.3.4");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val token = passwordManagementService.createToken(PasswordManagementQuery.builder().username("casuser").build());
    val context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, initPasswordResetAction.execute(context).getId());
    context.getFlowScope().put("token", token);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, initPasswordResetAction.execute(context).getId());
    val c = WebUtils.getCredential(context, UsernamePasswordCredential.class);
    assertNotNull(c);
    assertEquals("casuser", c.getUsername());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 57 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyRememberMeUserAgent.

@Test
public void verifyRememberMeUserAgent() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Chrome");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val c = new RememberMeUsernamePasswordCredential();
    c.setRememberMe(true);
    val builder = newBuilder(c, new RememberMeAuthenticationProperties().setSupportedUserAgents("Chrome"));
    val auth = builder.build();
    assertEquals(true, auth.getAttributes().get(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME).get(0));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 58 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class MultifactorAuthenticationSetTrustActionTests method beforeEach.

@BeforeEach
public void beforeEach() {
    this.context = new MockRequestContext();
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    val registeredService = RegisteredServiceTestUtils.getRegisteredService("sample-service", Collections.EMPTY_MAP);
    WebUtils.putRegisteredService(context, registeredService);
    request = new MockHttpServletRequest();
    request.setRemoteAddr("123.456.789.000");
    request.setLocalAddr("123.456.789.000");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val authn = RegisteredServiceTestUtils.getAuthentication("casuser-setdevice");
    WebUtils.putAuthentication(authn, context);
    ApplicationContextProvider.holdApplicationContext(applicationContext);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 59 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class ClientIpDeviceFingerprintComponentManagerTests method verifyClientIpFingerprintFound.

@Test
public void verifyClientIpFingerprintFound() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    request.setRemoteAddr("1.2.3.4");
    val clientInfo = new ClientInfo(request);
    ClientInfoHolder.setClientInfo(clientInfo);
    val ex = new ClientIpDeviceFingerprintComponentManager();
    assertTrue(ex.extractComponent("casuser", request, response).isPresent());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) ClientIpDeviceFingerprintComponentManager(org.apereo.cas.trusted.web.flow.fingerprint.ClientIpDeviceFingerprintComponentManager) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 60 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class DefaultDeviceFingerprintStrategyTests method verifyAction.

@Test
public void verifyAction() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("123.456.789.000");
    request.setLocalAddr("123.456.789.000");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val f1 = deviceFingerprintStrategy.determineFingerprintComponent("casuser", request, response);
    request.setCookies(response.getCookies());
    val f2 = deviceFingerprintStrategy.determineFingerprintComponent("casuser", request, response);
    request.setCookies(response.getCookies());
    assertEquals(f1, f2);
    val f3 = deviceFingerprintStrategy.determineFingerprintComponent("casuser", request, response);
    assertNotNull(response.getCookies());
    assertEquals(response.getCookies().length, 1);
    request.setCookies(response.getCookies());
    val f4 = deviceFingerprintStrategy.determineFingerprintComponent("casuser", request, response);
    assertEquals(f3, f4);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ClientInfo (org.apereo.inspektr.common.web.ClientInfo)82 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)69 lombok.val (lombok.val)65 Test (org.junit.jupiter.api.Test)42 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)36 MockRequestContext (org.springframework.webflow.test.MockRequestContext)35 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)31 MockServletContext (org.springframework.mock.web.MockServletContext)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 MockWebServer (org.apereo.cas.util.MockWebServer)13 ByteArrayResource (org.springframework.core.io.ByteArrayResource)13 BeforeEach (org.junit.jupiter.api.BeforeEach)12 BeforeAll (org.junit.jupiter.api.BeforeAll)6 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)5 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)4 Cookie (javax.servlet.http.Cookie)4 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)4 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)4