Search in sources :

Example 1 with OpenIdService

use of org.apereo.cas.support.openid.authentication.principal.OpenIdService 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 OpenIdService

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

the class OpenIdSingleSignOnActionTests method verifySuccessfulServiceTicket.

@Test
public void verifySuccessfulServiceTicket() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("scootman28");
    final TicketGrantingTicket t = new TicketGrantingTicketImpl("TGT-11", authentication, new NeverExpiresExpirationPolicy());
    this.ticketRegistry.addTicket(t);
    request.setParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "http://openid.aol.com/scootman28");
    request.setParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "http://www.cnn.com");
    final OpenIdService service = new OpenIdServiceFactory("").createService(request);
    context.getFlowScope().put("service", service);
    context.getFlowScope().put(WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, t.getId());
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertEquals("success", this.action.execute(context).getId());
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) OpenIdService(org.apereo.cas.support.openid.authentication.principal.OpenIdService) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) MockRequestContext(org.springframework.webflow.test.MockRequestContext) OpenIdServiceFactory(org.apereo.cas.support.openid.authentication.principal.OpenIdServiceFactory) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with OpenIdService

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

the class OpenIdSingleSignOnActionTests method verifyBadUsername.

@Test
public void verifyBadUsername() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "fablah");
    request.setParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "http://www.cnn.com");
    final OpenIdServiceFactory factory = new OpenIdServiceFactory("");
    final OpenIdService service = factory.createService(request);
    context.getFlowScope().put("service", service);
    context.getFlowScope().put(WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, "tgtId");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertEquals("error", this.action.execute(context).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OpenIdService(org.apereo.cas.support.openid.authentication.principal.OpenIdService) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) OpenIdServiceFactory(org.apereo.cas.support.openid.authentication.principal.OpenIdServiceFactory) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

OpenIdService (org.apereo.cas.support.openid.authentication.principal.OpenIdService)3 OpenIdServiceFactory (org.apereo.cas.support.openid.authentication.principal.OpenIdServiceFactory)2 Test (org.junit.Test)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)2 MockRequestContext (org.springframework.webflow.test.MockRequestContext)2 Authentication (org.apereo.cas.authentication.Authentication)1 Service (org.apereo.cas.authentication.principal.Service)1 OpenIdCredential (org.apereo.cas.support.openid.authentication.principal.OpenIdCredential)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)1 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)1