Search in sources :

Example 1 with OxChooserError

use of org.gluu.oxtrust.model.oxchooser.OxChooserError in project oxTrust by GluuFederation.

the class OxChooserWebService method requestHandler.

@Path("/Request")
@GET
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response requestHandler(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("idRequest") String idReq) throws Exception {
    try {
        byte[] decodedIdreq = Base64.decodeBase64(idReq);
        IdentityRequest idRequest = (IdentityRequest) jsonToObject(decodedIdreq, IdentityRequest.class);
        log.debug("openid_identifier_operation : ", idRequest.getIdentifier());
        log.debug("instantiating manager");
        log.debug("manager instantiated ");
        String returnToUrl = idRequest.getReturnToUrl();
        log.debug("getting list of discoveries");
        List discoveries = manager.discover(idRequest.getIdentifier());
        log.debug("retrieving descovered");
        DiscoveryInformation discovered = manager.associate(discoveries);
        log.debug("saving request");
        request.getSession().setAttribute("openid-disc", discovered);
        log.debug("instantiating AuthRequest");
        AuthRequest authReq = manager.authenticate(discovered, returnToUrl, idRequest.getRealm());
        FetchRequest fetch = FetchRequest.createFetchRequest();
        if (idRequest.getAxschema().contains("axschema")) {
            fetch.addAttribute("nickname", "http://axschema.org/namePerson/friendly", true);
            fetch.addAttribute("fullname", "http://axschema.org/namePerson", true);
            fetch.addAttribute("email", "http://axschema.org/contact/email", true);
            fetch.addAttribute("gender", "http://axschema.org/person/gender", true);
            fetch.addAttribute("language", "http://axschema.org/pref/language", true);
            fetch.addAttribute("timezone", "http://axschema.org/pref/timezone", true);
            fetch.addAttribute("image", "http://axschema.org/media/image/default", true);
        } else {
            fetch.addAttribute("firstname", "http://schema.openid.net/namePerson/first", true);
            fetch.addAttribute("lastname", "http://schema.openid.net/namePerson/last", true);
            fetch.addAttribute("email", "http://schema.openid.net/contact/email", true);
            fetch.addAttribute("country", "http://axschema.org/contact/country/home", true);
            fetch.addAttribute("language", "http://axschema.org/pref/language", true);
        }
        log.debug("adding fetch data");
        authReq.addExtension(fetch);
        log.debug("redirecting");
        response.sendRedirect(authReq.getDestinationUrl(true));
        log.debug("reterning build");
        return Response.ok().build();
    } catch (ConsumerException e) {
        log.debug("Error occured : ", e.getMessage(), " ", e.getCause());
        OxChooserError error = new OxChooserError();
        error.setDescription("An Error occured , request didnt go through.");
        return Response.status(400).entity(error).build();
    } finally {
        identity.logout();
    }
}
Also used : AuthRequest(org.openid4java.message.AuthRequest) IdentityRequest(org.gluu.oxtrust.model.oxchooser.IdentityRequest) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) FetchRequest(org.openid4java.message.ax.FetchRequest) OxChooserError(org.gluu.oxtrust.model.oxchooser.OxChooserError) List(java.util.List) ParameterList(org.openid4java.message.ParameterList) ConsumerException(org.openid4java.consumer.ConsumerException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 IdentityRequest (org.gluu.oxtrust.model.oxchooser.IdentityRequest)1 OxChooserError (org.gluu.oxtrust.model.oxchooser.OxChooserError)1 ConsumerException (org.openid4java.consumer.ConsumerException)1 DiscoveryInformation (org.openid4java.discovery.DiscoveryInformation)1 AuthRequest (org.openid4java.message.AuthRequest)1 ParameterList (org.openid4java.message.ParameterList)1 FetchRequest (org.openid4java.message.ax.FetchRequest)1