Java Code Examples for org.jasig.cas.web.support.WebUtils#putLoginTicket()

The following examples show how to use org.jasig.cas.web.support.WebUtils#putLoginTicket() . 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: AuthenticationViaFormActionTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifySuccessfulAuthenticationWithNoService() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    WebUtils.putLoginTicket(context, "LOGIN");
    request.addParameter("lt", "LOGIN");
    request.addParameter("username", "test");
    request.addParameter("password", "test");

    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
    putCredentialInRequestScope(context, c);

    final MessageContext messageContext = mock(MessageContext.class);
    assertEquals("success", this.action.submit(context, c, messageContext).getId());
}
 
Example 2
Source File: AuthenticationViaFormActionTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifySuccessfulAuthenticationWithNoServiceAndWarn()
    throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockRequestContext context = new MockRequestContext();

    WebUtils.putLoginTicket(context, "LOGIN");
    request.addParameter("lt", "LOGIN");

    request.addParameter("username", "test");
    request.addParameter("password", "test");
    request.addParameter("warn", "true");

    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, response));
    final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
    putCredentialInRequestScope(context, c);

    final MessageContext messageContext = mock(MessageContext.class);
    assertEquals("success", this.action.submit(context, c, messageContext).getId());
    assertNotNull(WebUtils.getTicketGrantingTicketId(context));
    assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
 
Example 3
Source File: AuthenticationViaFormActionTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifySuccessfulAuthenticationWithServiceAndWarn()
    throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockRequestContext context = new MockRequestContext();

    WebUtils.putLoginTicket(context, "LOGIN");
    request.addParameter("lt", "LOGIN");
    request.addParameter("username", "test");
    request.addParameter("password", "test");
    request.addParameter("warn", "true");
    request.addParameter("service", "test");

    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request,  response));
    final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
    putCredentialInRequestScope(context, c);

    final MessageContext messageContext = mock(MessageContext.class);
    assertEquals("success", this.action.submit(context, c, messageContext).getId());
    assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
 
Example 4
Source File: AuthenticationViaFormActionTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyRenewWithServiceAndSameCredentials() throws Exception {
    final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(c);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
    WebUtils.putLoginTicket(context, "LOGIN");
    request.addParameter("lt", "LOGIN");

    request.addParameter("renew", "true");
    request.addParameter("service", "test");
    request.addParameter("username", "test");
    request.addParameter("password", "test");

    context.setExternalContext(new ServletExternalContext(
        new MockServletContext(), request, new MockHttpServletResponse()));
    context.getFlowScope().put("service", TestUtils.getService());

    final MessageContext messageContext = mock(MessageContext.class);
    assertEquals("warn", this.action.submit(context, c, messageContext).getId());
}
 
Example 5
Source File: AuthenticationViaFormActionTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyRenewWithServiceAndDifferentCredentials() throws Exception {
    final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(c);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    WebUtils.putLoginTicket(context, "LOGIN");
    request.addParameter("lt", "LOGIN");

    WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
    request.addParameter("renew", "true");
    request.addParameter("service", "test");
    request.addParameter("username", "test2");
    request.addParameter("password", "test2");

    context.setExternalContext(new ServletExternalContext(
        new MockServletContext(), request, new MockHttpServletResponse()));

    final MessageContext messageContext = mock(MessageContext.class);
    assertEquals("success", this.action.submit(context, c, messageContext).getId());
}
 
Example 6
Source File: GenerateLoginTicketAction.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Generate the login ticket.
 *
 * @param context the context
 * @return <code>"generated"</code>
 */
public final String generate(final RequestContext context) {
    final String loginTicket = this.ticketIdGenerator.getNewTicketId(PREFIX);
    logger.debug("Generated login ticket {}", loginTicket);
    WebUtils.putLoginTicket(context, loginTicket);
    return "generated";
}
 
Example 7
Source File: GenerateLoginTicketAction.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
public final String generate(final RequestContext context) {
    final String loginTicket = this.ticketIdGenerator.getNewTicketId(PREFIX);
    logger.debug("Generated login ticket {}", loginTicket);
    WebUtils.putLoginTicket(context, loginTicket);
    if (context.getRequestParameters().contains("aaa")) {
        return "generated1";
    } else if (context.getRequestParameters().contains("wechat")) {
        return "generatedWeChat";
    }
    return "generated";
}