Search in sources :

Example 21 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class BaseLdapSpnegoKnownClientSystemsFilterActionTests method ensureLdapAttributeShouldDoSpnego.

@Test
public void ensureLdapAttributeShouldDoSpnego() throws Exception {
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("localhost");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.execute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class SpnegoKnownClientSystemsFilterActionTests method ensureHostnameAndIpShouldDoSpnego.

@Test
public void ensureHostnameAndIpShouldDoSpnego() {
    final HostNameSpnegoKnownClientSystemsFilterAction action = new HostNameSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("74\\..+"), "", 0, "\\w+\\.\\w+\\.\\w+");
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr(ALTERNATE_REMOTE_IP);
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 23 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class SpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldNotBeChecked.

@Test
public void ensureRemoteIpShouldNotBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^192\\.158\\..+"), "", 0);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("193.158.5.781");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertNotEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 24 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class SpnegoKnownClientSystemsFilterActionTests method ensureAltRemoteIpHeaderShouldBeChecked.

@Test
public void ensureAltRemoteIpHeaderShouldBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^74\\.125\\..+"), "alternateRemoteIp", 120);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("555.555.555.555");
    req.addHeader("alternateRemoteIp", ALTERNATE_REMOTE_IP);
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 25 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class SpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldBeChecked.

@Test
public void ensureRemoteIpShouldBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^192\\.158\\..+"), "", 0);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("192.158.5.781");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Aggregations

ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)61 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)60 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)60 Test (org.junit.Test)55 MockServletContext (org.springframework.mock.web.MockServletContext)54 MockRequestContext (org.springframework.webflow.test.MockRequestContext)50 Event (org.springframework.webflow.execution.Event)22 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)15 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)14 Credential (org.apereo.cas.authentication.Credential)7 Cookie (javax.servlet.http.Cookie)6 Service (org.apereo.cas.authentication.principal.Service)5 Clients (org.pac4j.core.client.Clients)5 FacebookClient (org.pac4j.oauth.client.FacebookClient)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)4 MutableAttributeMap (org.springframework.webflow.core.collection.MutableAttributeMap)4 Authentication (org.apereo.cas.authentication.Authentication)3 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)3 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)3