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