Search in sources :

Example 1 with OpenIdCredential

use of org.apereo.cas.support.openid.authentication.principal.OpenIdCredential in project cas by apereo.

the class OpenIdSingleSignOnAction method constructCredentialsFromRequest.

@Override
protected Credential constructCredentialsFromRequest(final RequestContext context) {
    final String ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(context);
    final String openidIdentityParameter = context.getRequestParameters().get(OpenIdProtocolConstants.OPENID_IDENTITY);
    final String userName = getOpenIdSelectedIdentifier(context, ticketGrantingTicketId, openidIdentityParameter);
    final Service service = WebUtils.getService(context);
    // clear the service because otherwise we can fake the username
    if (service instanceof OpenIdService && StringUtils.isBlank(userName)) {
        context.getFlowScope().remove(CasProtocolConstants.PARAMETER_SERVICE);
    }
    if (StringUtils.isBlank(ticketGrantingTicketId) || StringUtils.isBlank(userName)) {
        return null;
    }
    return new OpenIdCredential(ticketGrantingTicketId, userName);
}
Also used : OpenIdService(org.apereo.cas.support.openid.authentication.principal.OpenIdService) OpenIdService(org.apereo.cas.support.openid.authentication.principal.OpenIdService) Service(org.apereo.cas.authentication.principal.Service) OpenIdCredential(org.apereo.cas.support.openid.authentication.principal.OpenIdCredential)

Example 2 with OpenIdCredential

use of org.apereo.cas.support.openid.authentication.principal.OpenIdCredential in project cas by apereo.

the class OpenIdCredentialsAuthenticationHandlerTests method verifyTGTThatIsExpired.

@Test
public void verifyTGTThatIsExpired() throws Exception {
    final OpenIdCredential c = new OpenIdCredential(TGT_ID, USERNAME);
    final TicketGrantingTicket t = getTicketGrantingTicket();
    this.ticketRegistry.addTicket(t);
    t.markTicketExpired();
    this.thrown.expect(FailedLoginException.class);
    this.thrown.expectMessage("TGT is null or expired.");
    this.openIdCredentialsAuthenticationHandler.authenticate(c);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) OpenIdCredential(org.apereo.cas.support.openid.authentication.principal.OpenIdCredential) Test(org.junit.Test)

Example 3 with OpenIdCredential

use of org.apereo.cas.support.openid.authentication.principal.OpenIdCredential in project cas by apereo.

the class OpenIdCredentialsAuthenticationHandler method authenticate.

@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException {
    final OpenIdCredential c = (OpenIdCredential) credential;
    final TicketGrantingTicket t = this.ticketRegistry.getTicket(c.getTicketGrantingTicketId(), TicketGrantingTicket.class);
    if (t == null || t.isExpired()) {
        throw new FailedLoginException("TGT is null or expired.");
    }
    final Principal principal = t.getAuthentication().getPrincipal();
    if (!principal.getId().equals(c.getUsername())) {
        throw new FailedLoginException("Principal ID mismatch");
    }
    return new DefaultHandlerResult(this, new BasicCredentialMetaData(c), principal);
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) Principal(org.apereo.cas.authentication.principal.Principal) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) OpenIdCredential(org.apereo.cas.support.openid.authentication.principal.OpenIdCredential)

Example 4 with OpenIdCredential

use of org.apereo.cas.support.openid.authentication.principal.OpenIdCredential in project cas by apereo.

the class OpenIdCredentialsAuthenticationHandlerTests method verifyTGTWithSameId.

@Test
public void verifyTGTWithSameId() throws Exception {
    final OpenIdCredential c = new OpenIdCredential(TGT_ID, USERNAME);
    final TicketGrantingTicket t = getTicketGrantingTicket();
    this.ticketRegistry.addTicket(t);
    assertEquals(TGT_ID, this.openIdCredentialsAuthenticationHandler.authenticate(c).getPrincipal().getId());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) OpenIdCredential(org.apereo.cas.support.openid.authentication.principal.OpenIdCredential) Test(org.junit.Test)

Example 5 with OpenIdCredential

use of org.apereo.cas.support.openid.authentication.principal.OpenIdCredential in project cas by apereo.

the class OpenIdCredentialsAuthenticationHandlerTests method verifyTGTWithDifferentId.

@Test
public void verifyTGTWithDifferentId() throws Exception {
    final OpenIdCredential c = new OpenIdCredential(TGT_ID, "test1");
    final TicketGrantingTicket t = getTicketGrantingTicket();
    this.ticketRegistry.addTicket(t);
    this.thrown.expect(FailedLoginException.class);
    this.thrown.expectMessage("Principal ID mismatch");
    this.openIdCredentialsAuthenticationHandler.authenticate(c);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) OpenIdCredential(org.apereo.cas.support.openid.authentication.principal.OpenIdCredential) Test(org.junit.Test)

Aggregations

OpenIdCredential (org.apereo.cas.support.openid.authentication.principal.OpenIdCredential)5 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)4 Test (org.junit.Test)3 FailedLoginException (javax.security.auth.login.FailedLoginException)1 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)1 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)1 Principal (org.apereo.cas.authentication.principal.Principal)1 Service (org.apereo.cas.authentication.principal.Service)1 OpenIdService (org.apereo.cas.support.openid.authentication.principal.OpenIdService)1