Search in sources :

Example 26 with ClientInfo

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

the class OidcAuthenticationContextWebflowEventResolverTests method initialize.

@BeforeEach
@Override
public void initialize() throws Exception {
    super.initialize();
    this.context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("385.86.151.11");
    request.setLocalAddr("295.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "MSIE");
    request.addParameter(OAuth20Constants.ACR_VALUES, TestMultifactorAuthenticationProvider.ID);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) 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) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with ClientInfo

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

the class PrincipalFromRequestHeaderNonInteractiveCredentialsActionTests method verifyAdaptiveError.

@Test
public void verifyAdaptiveError() throws Exception {
    val context = new MockRequestContext();
    val messageContext = (DefaultMessageContext) context.getMessageContext();
    messageContext.setMessageSource(mock(MessageSource.class));
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    request.setRemoteUser("xyz");
    request.setRemoteAddr("1.2.3.4");
    request.setLocalAddr("1.2.3.4");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "FIREFOX");
    request.addParameter("geolocation", "1000,1000,1000,1000");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    request.addParameter(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestParameter(), "mfa-whatever");
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) MessageSource(org.springframework.context.MessageSource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 28 with ClientInfo

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

the class BaseEndpointLdapAuthenticationProviderTests method bootstrap.

@BeforeAll
@SneakyThrows
public static void bootstrap() {
    ClientInfoHolder.setClientInfo(new ClientInfo(new MockHttpServletRequest()));
    val localhost = new LDAPConnection("localhost", LDAP_PORT, "cn=Directory Manager", "password");
    localhost.connect("localhost", LDAP_PORT);
    localhost.bind("cn=Directory Manager", "password");
    LdapIntegrationTestsOperations.populateEntries(localhost, new ClassPathResource("ldif/ldap-authz.ldif").getInputStream(), "ou=people,dc=example,dc=org");
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ClassPathResource(org.springframework.core.io.ClassPathResource) BeforeAll(org.junit.jupiter.api.BeforeAll) SneakyThrows(lombok.SneakyThrows)

Example 29 with ClientInfo

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

the class DefaultAccountRegistrationServiceTests method setup.

@BeforeEach
public void setup() {
    this.accountRegistrationService = new DefaultAccountRegistrationService(mock(AccountRegistrationPropertyLoader.class), casProperties, CipherExecutor.noOpOfSerializableToString(), AccountRegistrationUsernameBuilder.asDefault(), mock(AccountRegistrationProvisioner.class));
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("1.2.3.4");
    request.setLocalAddr("1.2.3.4");
    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 30 with ClientInfo

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

the class ValidateAccountRegistrationTokenActionTests method verifyPassRegistrationRequest.

@Test
public void verifyPassRegistrationRequest() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    request.setRemoteAddr("127.0.0.1");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    request.addParameter("username", "casuser");
    request.addParameter("email", "cas@example.org");
    request.addParameter("phone", "3477465432");
    val results = submitAccountRegistrationAction.execute(context);
    val token = new URIBuilder(results.getAttributes().get("result", String.class)).getQueryParams().get(0).getValue();
    request.addParameter(AccountRegistrationUtils.REQUEST_PARAMETER_ACCOUNT_REGISTRATION_ACTIVATION_TOKEN, token);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, validateAction.execute(context).getId());
}
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) URIBuilder(org.apache.http.client.utils.URIBuilder) 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