Search in sources :

Example 31 with ClientInfo

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

the class CasGoogleAnalyticsCookieGeneratorTests method setup.

@BeforeAll
public static void setup() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("107.181.69.221");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 32 with ClientInfo

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

the class BaseMultifactorAuthenticationTriggerTests method setup.

@BeforeEach
public void setup(final TestInfo info) {
    this.applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    if (!info.getTags().contains("DisableProviderRegistration")) {
        this.multifactorAuthenticationProvider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    }
    this.authentication = mock(Authentication.class);
    val principal = mock(Principal.class);
    when(principal.getId()).thenReturn("casuser");
    when(principal.getAttributes()).thenReturn(Map.of("email", List.of("casuser@example.org")));
    when(authentication.getAttributes()).thenReturn(Map.of("category", List.of("user-object"), "mfa-mode", List.of("mfa-other")));
    when(authentication.getPrincipal()).thenReturn(principal);
    this.registeredService = mock(RegisteredService.class);
    when(registeredService.getName()).thenReturn("Service");
    when(registeredService.getServiceId()).thenReturn("http://app.org");
    when(registeredService.getId()).thenReturn(1000L);
    this.geoLocationService = mock(GeoLocationService.class);
    this.httpRequest = new MockHttpServletRequest();
    this.httpRequest.setRemoteAddr("185.86.151.11");
    this.httpRequest.setLocalAddr("185.88.151.12");
    this.httpRequest.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Mozilla/5.0 (Windows NT 10.0; WOW64)");
    var clientInfo = new ClientInfo(this.httpRequest);
    ClientInfoHolder.setClientInfo(clientInfo);
    this.httpResponse = new MockHttpServletResponse();
}
Also used : lombok.val(lombok.val) RegisteredService(org.apereo.cas.services.RegisteredService) GeoLocationService(org.apereo.cas.authentication.adaptive.geo.GeoLocationService) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 33 with ClientInfo

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

the class WsFederationResponseValidatorTests method prepareContext.

private RequestContext prepareContext() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Mozilla/5.0 (Windows NT 10.0; WOW64)");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val registeredService = RegisteredServiceTestUtils.getRegisteredService("https://wsfedservice-validate");
    servicesManager.save(registeredService);
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val service = RegisteredServiceTestUtils.getService(registeredService.getServiceId());
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
    val wsConfig = wsFederationConfigurations.toList().get(0);
    val id = wsConfig.getId();
    request.addParameter(WsFederationNavigationController.PARAMETER_NAME, id);
    wsFederationNavigationController.redirectToProvider(request, response);
    request.setCookies(response.getCookies());
    val wresult = IOUtils.toString(new ClassPathResource("goodTokenResponse.txt").getInputStream(), StandardCharsets.UTF_8);
    request.addParameter(WsFederationResponseValidator.WRESULT, wresult);
    request.addParameter(WsFederationCookieManager.WCTX, id);
    return context;
}
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) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 34 with ClientInfo

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

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyRememberMeIp.

@Test
public void verifyRememberMeIp() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val c = new RememberMeUsernamePasswordCredential();
    c.setRememberMe(true);
    val builder = newBuilder(c, new RememberMeAuthenticationProperties().setSupportedIpAddresses("192.+"));
    val auth = builder.build();
    assertFalse(auth.getAttributes().containsKey(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME));
}
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 35 with ClientInfo

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

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyRememberMeUserAgentAndIp.

@Test
public void verifyRememberMeUserAgentAndIp() {
    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").setSupportedIpAddresses("123.+"));
    val auth = builder.build();
    assertFalse(auth.getAttributes().containsKey(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME));
}
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)

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