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);
}
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());
}
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());
}
Aggregations