Java Code Examples for org.jasig.cas.web.support.WebUtils#putTicketGrantingTicketInRequestScope()
The following examples show how to use
org.jasig.cas.web.support.WebUtils#putTicketGrantingTicketInRequestScope() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateServiceTicketActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testTicketGrantingTicketFromRequest() throws Exception { MockRequestContext context = new MockRequestContext(); context.getFlowScope().put("service", TestUtils.getService()); MockHttpServletRequest request = new MockHttpServletRequest(); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); request.addParameter("service", "service"); WebUtils.putTicketGrantingTicketInRequestScope(context, this.ticketGrantingTicket); this.action.execute(context); assertNotNull(WebUtils.getServiceTicketFromRequestScope(context)); }
Example 2
Source File: GenerateServiceTicketActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testTicketGrantingTicketNoTgt() throws Exception { MockRequestContext context = new MockRequestContext(); context.getFlowScope().put("service", TestUtils.getService()); MockHttpServletRequest request = new MockHttpServletRequest(); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); request.addParameter("service", "service"); WebUtils.putTicketGrantingTicketInRequestScope(context, "bleh"); assertEquals("error", this.action.execute(context).getId()); }
Example 3
Source File: GenerateServiceTicketActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testTicketGrantingTicketNotTgtButGateway() throws Exception { MockRequestContext context = new MockRequestContext(); context.getFlowScope().put("service", TestUtils.getService()); MockHttpServletRequest request = new MockHttpServletRequest(); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); request.addParameter("service", "service"); request.addParameter("gateway", "true"); WebUtils.putTicketGrantingTicketInRequestScope(context, "bleh"); assertEquals("gateway", this.action.execute(context).getId()); }
Example 4
Source File: SendTicketGrantingTicketActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testTgtToSet() throws Exception { final MockHttpServletResponse response = new MockHttpServletResponse(); final String TICKET_VALUE = "test"; WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE); this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), response)); assertEquals("success", this.action.execute(this.context).getId()); assertEquals(TICKET_VALUE, response.getCookies()[0].getValue()); }
Example 5
Source File: SendTicketGrantingTicketActionTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void testTgtToSetRemovingOldTgt() throws Exception { final MockHttpServletResponse response = new MockHttpServletResponse(); final MockHttpServletRequest request = new MockHttpServletRequest(); final String TICKET_VALUE = "test"; request.setCookies(new Cookie[] {new Cookie("TGT", "test5")}); WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE); this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response)); assertEquals("success", this.action.execute(this.context).getId()); assertEquals(TICKET_VALUE, response.getCookies()[0].getValue()); }
Example 6
Source File: ClientAction.java From oxTrust with MIT License | 5 votes |
/** * {@InheritDoc} */ @Override protected Event doExecute(final RequestContext context) throws Exception { final HttpServletRequest request = WebUtils.getHttpServletRequest(context); final HttpServletResponse response = WebUtils.getHttpServletResponse(context); // Web context final WebContext webContext = new J2EContext(request, response); // It's an authentication if (client.isAuthorizationResponse(webContext)) { logger.info("Procession authentication request"); // Check if oxAuth request state is correct if (!client.isValidRequestState(webContext)) { logger.warn("The state in session and in request are not equals"); // Reinit login page prepareForLoginPage(context, webContext); return new Event(this, "stop"); } // Try to authenticate final ClientCredential credentials = getClientCrendentials(context, webContext); if (credentials != null) { WebUtils.putTicketGrantingTicketInRequestScope(context, this.centralAuthenticationService.createTicketGrantingTicket(credentials)); return success(); } } // Go to login page prepareForLoginPage(context, webContext); return error(); }
Example 7
Source File: ClientAction.java From cas4.0.x-server-wechat with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override protected Event doExecute(final RequestContext context) throws Exception { final HttpServletRequest request = WebUtils.getHttpServletRequest(context); final HttpServletResponse response = WebUtils.getHttpServletResponse(context); final HttpSession session = request.getSession(); // web context final WebContext webContext = new J2EContext(request, response); // get client //final String clientName = request.getParameter(this.clients.getClientNameParameter()); final String clientName = request.getParameter("state"); //logger.debug("clientName : {}", clientName); logger.info("clientName : {}", clientName); // it's an authentication if (StringUtils.isNotBlank(clientName)) { // get client final BaseClient<Credentials, CommonProfile> client = (BaseClient<Credentials, CommonProfile>) this.clients .findClient(clientName); logger.info("client : {}", client); // Only supported protocols final Mechanism mechanism = client.getMechanism(); logger.info("mechanism == " + mechanism.name()); if (!SUPPORTED_PROTOCOLS.contains(mechanism)) { throw new TechnicalException("Only CAS, OAuth, OpenID and SAML protocols are supported: " + client); } // get credentials final Credentials credentials; try { credentials = client.getCredentials(webContext); logger.info("credentials : {}", credentials); } catch (final RequiresHttpAction e) { logger.info("requires http action : {}", e); response.flushBuffer(); ExternalContext externalContext = ExternalContextHolder.getExternalContext(); externalContext.recordResponseComplete(); return new Event(this, "stop"); } // retrieve parameters from web session final Service service = (Service) session.getAttribute(SERVICE); context.getFlowScope().put(SERVICE, service); logger.info("retrieve service: {}", service); if (service != null) { request.setAttribute(SERVICE, service.getId()); } restoreRequestAttribute(request, session, THEME); restoreRequestAttribute(request, session, LOCALE); restoreRequestAttribute(request, session, METHOD); // credentials not null -> try to authenticate if (credentials != null) { logger.info("credentials is not null : {}", credentials); WebUtils.putTicketGrantingTicketInRequestScope(context, this.centralAuthenticationService.createTicketGrantingTicket(new ClientCredential(credentials))); return success(); } } // no or aborted authentication : go to login page prepareForLoginPage(context); return error(); }