Search in sources :

Example 41 with ClientInfo

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

the class CasEventsReportEndpointTests method initialize.

@BeforeEach
public void initialize() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("223.456.789.100");
    request.setLocalAddr("223.456.789.100");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    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 42 with ClientInfo

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

the class CasAuthenticationEventListenerTests method initialize.

@BeforeEach
public void initialize() {
    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));
}
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 43 with ClientInfo

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

the class HttpRequestRegisteredServiceAccessStrategyTests method setup.

@BeforeEach
public void setup() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("192.861.151.163");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Chrome/Mozilla");
    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 44 with ClientInfo

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

the class NoOpPasswordManagementServiceTests method verifyTokenParsing.

@Test
public void verifyTokenParsing() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    val clientInfo = new ClientInfo(request);
    ClientInfoHolder.setClientInfo(clientInfo);
    val properties = new PasswordManagementProperties();
    val service = new NoOpPasswordManagementService(CipherExecutor.noOpOfSerializableToString(), "CAS", properties);
    val token = UUID.randomUUID().toString();
    val claims = new JwtClaims();
    claims.setJwtId(token);
    claims.setIssuer("bad-issuer");
    assertNull(service.parseToken(claims.toJson()));
    claims.setIssuer("CAS");
    claims.setAudience("other-audience");
    assertNull(service.parseToken(claims.toJson()));
    claims.setAudience("CAS");
    claims.setSubject(StringUtils.EMPTY);
    assertNull(service.parseToken(claims.toJson()));
    claims.setClaim("origin", "whatever");
    claims.setSubject("casuser");
    assertNull(service.parseToken(claims.toJson()));
    claims.setClaim("origin", clientInfo.getServerIpAddress());
    claims.setClaim("client", "whatever");
    assertNull(service.parseToken(claims.toJson()));
    claims.setClaim("client", clientInfo.getClientIpAddress());
    val milli = Instant.now(Clock.systemUTC()).minusSeconds(500).toEpochMilli();
    claims.setExpirationTime(NumericDate.fromMilliseconds(milli));
    assertNull(service.parseToken(claims.toJson()));
    claims.setExpirationTime(NumericDate.now());
    assertNotNull(service.parseToken(claims.toJson()));
}
Also used : lombok.val(lombok.val) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) JwtClaims(org.jose4j.jwt.JwtClaims) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.jupiter.api.Test)

Example 45 with ClientInfo

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

the class LdapPasswordManagementServiceTests method bootstrap.

@BeforeAll
public static void bootstrap() throws Exception {
    ClientInfoHolder.setClientInfo(new ClientInfo(new MockHttpServletRequest()));
    val localhost = new LDAPConnection("localhost", LDAP_PORT, "cn=Directory Manager", "password");
    LdapIntegrationTestsOperations.populateEntries(localhost, new ClassPathResource("ldif/ldap-pm.ldif").getInputStream(), "ou=people,dc=example,dc=org", new BindConnectionInitializer("cn=Directory Manager", new Credential("password")));
}
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)

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