Search in sources :

Example 71 with ClientInfo

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

the class LdapAcceptableUsagePolicyRepositoryTests method bootstrap.

@BeforeAll
public static void bootstrap() throws Exception {
    ClientInfoHolder.setClientInfo(new ClientInfo(new MockHttpServletRequest()));
    @Cleanup val localhost = new LDAPConnection("localhost", LDAP_PORT, "cn=Directory Manager", "password");
    val ldif = IOUtils.toString(new ClassPathResource("ldif/ldap-aup.ldif").getInputStream(), StandardCharsets.UTF_8).replace("$user", USER);
    LdapIntegrationTestsOperations.populateEntries(localhost, new ByteArrayInputStream(ldif.getBytes(StandardCharsets.UTF_8)), "ou=people,dc=example,dc=org");
}
Also used : lombok.val(lombok.val) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Cleanup(lombok.Cleanup) ClassPathResource(org.springframework.core.io.ClassPathResource) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 72 with ClientInfo

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

the class BaseDuoSecurityTests method getMockRequestContext.

public static RequestContext getMockRequestContext(final ConfigurableApplicationContext applicationContext) {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("195.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "MSIE");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val provider = getDuoSecurityMultifactorAuthenticationProvider();
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider);
    val targetResolver = new DefaultTargetStateResolver(provider.getId());
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(provider.getId())), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    val authentication = CoreAuthenticationTestUtils.getAuthentication();
    WebUtils.putAuthentication(authentication, context);
    val builder = mock(AuthenticationResultBuilder.class);
    when(builder.getInitialAuthentication()).thenReturn(Optional.of(authentication));
    when(builder.collect(any(Authentication.class))).thenReturn(builder);
    WebUtils.putAuthenticationResultBuilder(builder, context);
    return context;
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Authentication(org.apereo.cas.authentication.Authentication) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) 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)

Example 73 with ClientInfo

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

the class OpenLdapPasswordManagementServiceTests method bootstrap.

@BeforeAll
public static void bootstrap() throws Exception {
    ClientInfoHolder.setClientInfo(new ClientInfo(new MockHttpServletRequest()));
    val localhost = new LDAPConnection("localhost", LDAP_PORT, "cn=admin,dc=example,dc=org", "P@ssw0rd");
    LdapIntegrationTestsOperations.populateEntries(localhost, new ClassPathResource("ldif/openldap-pm.ldif").getInputStream(), "ou=people,dc=example,dc=org", new BindConnectionInitializer("cn=admin,dc=example,dc=org", new Credential("P@ssw0rd")));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Credential(org.ldaptive.Credential) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) BindConnectionInitializer(org.ldaptive.BindConnectionInitializer) ClassPathResource(org.springframework.core.io.ClassPathResource) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 74 with ClientInfo

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

the class BaseThrottledSubmissionHandlerInterceptorAdapterTests method initialize.

@BeforeEach
public void initialize() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr(IP_ADDRESS);
    request.setLocalAddr(IP_ADDRESS);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 75 with ClientInfo

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

the class RestfulSmsSenderTests method initialize.

@BeforeEach
public void initialize() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    webServer = new MockWebServer(8132, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE);
    this.webServer.start();
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockWebServer(org.apereo.cas.util.MockWebServer) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) ByteArrayResource(org.springframework.core.io.ByteArrayResource) BeforeEach(org.junit.jupiter.api.BeforeEach)

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