use of org.gluu.oxtrust.model.oxchooser.IdentityResponse in project oxTrust by GluuFederation.
the class OxChooserWebService method responseHandler.
@Path("/Response")
@GET
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response responseHandler(@Context HttpServletRequest httpReq, @Context HttpServletResponse httpRes, ForwardedRequest frequest) throws ConsumerException {
try {
log.debug("instantiating a ParameterList ");
ParameterList response = new ParameterList(frequest.getParameterMap());
log.debug("getting DiscoveryInformation ");
DiscoveryInformation discovered = (DiscoveryInformation) httpReq.getSession().getAttribute("openid-disc");
log.debug("getting StringBuffer ");
StringBuffer receivingURL = frequest.getRequestURL();
log.debug("getting QueryString ");
String queryString = frequest.getQueryString();
if (queryString != null && queryString.length() > 0)
log.debug("getting receivingURL ");
receivingURL.append("?").append(frequest.getQueryString());
log.debug("getting VerificationResult ");
VerificationResult verification = manager.verify(receivingURL.toString(), response, discovered);
log.debug("getting VerificationResult ");
Identifier verified = verification.getVerifiedId();
log.debug(" VerificationResult retrieved ");
if (verified != null) {
log.debug("verified != null");
AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
log.debug("getting FetchResponse");
FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
log.debug("getting emails");
List emails = fetchResp.getAttributeValues("email");
log.debug("getting FirstName");
String firstName = fetchResp.getAttributeValue("firstname");
log.debug("getting LastName");
String lastName = fetchResp.getAttributeValue("lastname");
log.debug("getting one Email");
String email = (String) emails.get(0);
log.debug("email : ", email);
String nickName = fetchResp.getAttributeValue("nickname");
String Image = fetchResp.getAttributeValue("image");
String Language = fetchResp.getAttributeValue("language");
String Country = fetchResp.getAttributeValue("country");
String Timezone = fetchResp.getAttributeValue("timezone");
String Gender = fetchResp.getAttributeValue("gender");
String Fullname = fetchResp.getAttributeValue("fullname");
IdentityResponse idResponse = new IdentityResponse();
idResponse.setFirstname(firstName);
idResponse.setLastname(lastName);
idResponse.setEmail(email);
idResponse.setNickname(nickName);
idResponse.setImage(Image);
idResponse.setLanguage(Language);
idResponse.setCountry(Country);
idResponse.setTimezone(Timezone);
idResponse.setGender(Gender);
idResponse.setFullname(Fullname);
return Response.ok(idResponse).build();
}
return errorResponse("Could not get fetched attributes");
}
} catch (AssociationException e) {
return errorResponse("An AssociationException occured , please check your request.");
} catch (MessageException e) {
return errorResponse("An MessageException occured , please check your request.");
} catch (DiscoveryException e) {
return errorResponse("An DiscoveryException occured , please check your request.");
} finally {
identity.logout();
}
return errorResponse("An Error occured , please check your request.");
}
Aggregations