Search in sources :

Example 11 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class TicketOrCredentialPrincipalResolverTests method verifyResolverTicketGrantingTicket.

@Test
public void verifyResolverTicketGrantingTicket() throws Exception {
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), c);
    final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), CoreAuthenticationTestUtils.getService(), ctx);
    final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);
    when(jp.getArgs()).thenReturn(new Object[] { ticketId.getId() });
    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, c.getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

Example 12 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class TicketOrCredentialPrincipalResolverTests method verifyResolverCredential.

@Test
public void verifyResolverCredential() {
    final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    when(jp.getArgs()).thenReturn(new Object[] { c });
    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, c.toString());
}
Also used : Credential(org.apereo.cas.authentication.Credential) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

Example 13 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class AbstractNonInteractiveCredentialsAction method doPreExecute.

@Override
protected Event doPreExecute(final RequestContext context) throws Exception {
    final Credential credential = constructCredentialsFromRequest(context);
    if (credential == null) {
        LOGGER.warn("No credentials detected. Navigating to error...");
        return error();
    }
    WebUtils.putCredential(context, credential);
    return super.doPreExecute(context);
}
Also used : Credential(org.apereo.cas.authentication.Credential)

Example 14 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class ServiceWarningAction method doExecute.

@Override
protected Event doExecute(final RequestContext context) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
    final Service service = WebUtils.getService(context);
    final String ticketGrantingTicket = WebUtils.getTicketGrantingTicketId(context);
    final Authentication authentication = this.ticketRegistrySupport.getAuthenticationFrom(ticketGrantingTicket);
    if (authentication == null) {
        throw new InvalidTicketException(new AuthenticationException("No authentication found for ticket " + ticketGrantingTicket), ticketGrantingTicket);
    }
    final Credential credential = WebUtils.getCredential(context);
    final AuthenticationResultBuilder authenticationResultBuilder = authenticationSystemSupport.establishAuthenticationContextFromInitial(authentication, credential);
    final AuthenticationResult authenticationResult = authenticationResultBuilder.build(service);
    final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(ticketGrantingTicket, service, authenticationResult);
    WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
    if (request.getParameterMap().containsKey("ignorewarn")) {
        if (Boolean.valueOf(request.getParameter("ignorewarn").toString())) {
            this.warnCookieGenerator.removeCookie(response);
        }
    }
    return new Event(this, CasWebflowConstants.STATE_ID_REDIRECT);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Credential(org.apereo.cas.authentication.Credential) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Authentication(org.apereo.cas.authentication.Authentication) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) HttpServletResponse(javax.servlet.http.HttpServletResponse) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) Event(org.springframework.webflow.execution.Event) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 15 with Credential

use of org.apereo.cas.authentication.Credential in project cas by apereo.

the class AuthenticationViaFormActionTests method verifySuccessfulAuthenticationWithServiceAndWarn.

@Test
public void verifySuccessfulAuthenticationWithServiceAndWarn() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockRequestContext context = new MockRequestContext();
    request.addParameter(USERNAME_PARAM, TEST);
    request.addParameter(PASSWORD_PARAM, TEST);
    request.addParameter("warn", "true");
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, TEST);
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    putCredentialInRequestScope(context, c);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
    assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
Also used : Credential(org.apereo.cas.authentication.Credential) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Aggregations

Credential (org.apereo.cas.authentication.Credential)67 Test (org.junit.Test)39 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)29 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)26 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)18 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)13 Service (org.apereo.cas.authentication.principal.Service)13 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)11 HashMap (java.util.HashMap)10 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)10 CachedData (net.spy.memcached.CachedData)9 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)9 LinkedHashMap (java.util.LinkedHashMap)8 RegisteredService (org.apereo.cas.services.RegisteredService)8 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 MockServletContext (org.springframework.mock.web.MockServletContext)7 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)7 MockRequestContext (org.springframework.webflow.test.MockRequestContext)7