Search in sources :

Example 6 with DiscoveryInformation

use of org.openid4java.discovery.DiscoveryInformation in project spring-security by spring-projects.

the class OpenID4JavaConsumer method beginConsumption.

// ~ Methods
// ========================================================================================================
public String beginConsumption(HttpServletRequest req, String identityUrl, String returnToUrl, String realm) throws OpenIDConsumerException {
    List<DiscoveryInformation> discoveries;
    try {
        discoveries = consumerManager.discover(identityUrl);
    } catch (DiscoveryException e) {
        throw new OpenIDConsumerException("Error during discovery", e);
    }
    DiscoveryInformation information = consumerManager.associate(discoveries);
    req.getSession().setAttribute(DISCOVERY_INFO_KEY, information);
    AuthRequest authReq;
    try {
        authReq = consumerManager.authenticate(information, returnToUrl, realm);
        logger.debug("Looking up attribute fetch list for identifier: " + identityUrl);
        List<OpenIDAttribute> attributesToFetch = attributesToFetchFactory.createAttributeList(identityUrl);
        if (!attributesToFetch.isEmpty()) {
            req.getSession().setAttribute(ATTRIBUTE_LIST_KEY, attributesToFetch);
            FetchRequest fetchRequest = FetchRequest.createFetchRequest();
            for (OpenIDAttribute attr : attributesToFetch) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Adding attribute " + attr.getType() + " to fetch request");
                }
                fetchRequest.addAttribute(attr.getName(), attr.getType(), attr.isRequired(), attr.getCount());
            }
            authReq.addExtension(fetchRequest);
        }
    } catch (MessageException e) {
        throw new OpenIDConsumerException("Error processing ConsumerManager authentication", e);
    } catch (ConsumerException e) {
        throw new OpenIDConsumerException("Error processing ConsumerManager authentication", e);
    }
    return authReq.getDestinationUrl(true);
}
Also used : AuthRequest(org.openid4java.message.AuthRequest) MessageException(org.openid4java.message.MessageException) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) FetchRequest(org.openid4java.message.ax.FetchRequest) ConsumerException(org.openid4java.consumer.ConsumerException) DiscoveryException(org.openid4java.discovery.DiscoveryException)

Example 7 with DiscoveryInformation

use of org.openid4java.discovery.DiscoveryInformation in project gerrit by GerritCodeReview.

the class OpenIdServiceImpl method init.

private State init(HttpServletRequest req, final String openidIdentifier, final SignInMode mode, final boolean remember, final String returnToken) {
    final List<?> list;
    try {
        list = manager.discover(openidIdentifier);
    } catch (DiscoveryException e) {
        log.error("Cannot discover OpenID " + openidIdentifier, e);
        return null;
    }
    if (list == null || list.isEmpty()) {
        return null;
    }
    final String contextUrl = urlProvider.get(req);
    final DiscoveryInformation discovered = manager.associate(list);
    final UrlEncoded retTo = new UrlEncoded(contextUrl + RETURN_URL);
    retTo.put(P_MODE, mode.name());
    if (returnToken != null && returnToken.length() > 0) {
        retTo.put(P_TOKEN, returnToken);
    }
    if (remember) {
        retTo.put(P_REMEMBER, "1");
    }
    if (discovered.hasClaimedIdentifier()) {
        retTo.put(P_CLAIMED, discovered.getClaimedIdentifier().getIdentifier());
    }
    return new State(discovered, retTo, contextUrl);
}
Also used : DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) UrlEncoded(com.google.gerrit.server.UrlEncoded) DiscoveryException(org.openid4java.discovery.DiscoveryException)

Example 8 with DiscoveryInformation

use of org.openid4java.discovery.DiscoveryInformation 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.");
}
Also used : IdentityResponse(org.gluu.oxtrust.model.oxchooser.IdentityResponse) FetchResponse(org.openid4java.message.ax.FetchResponse) Identifier(org.openid4java.discovery.Identifier) VerificationResult(org.openid4java.consumer.VerificationResult) MessageException(org.openid4java.message.MessageException) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) AuthSuccess(org.openid4java.message.AuthSuccess) ParameterList(org.openid4java.message.ParameterList) AssociationException(org.openid4java.association.AssociationException) List(java.util.List) ParameterList(org.openid4java.message.ParameterList) DiscoveryException(org.openid4java.discovery.DiscoveryException) 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

DiscoveryInformation (org.openid4java.discovery.DiscoveryInformation)8 ParameterList (org.openid4java.message.ParameterList)5 VerificationResult (org.openid4java.consumer.VerificationResult)4 DiscoveryException (org.openid4java.discovery.DiscoveryException)4 List (java.util.List)3 ConsumerManager (org.openid4java.consumer.ConsumerManager)3 Identifier (org.openid4java.discovery.Identifier)3 AuthRequest (org.openid4java.message.AuthRequest)3 MessageException (org.openid4java.message.MessageException)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AssociationException (org.openid4java.association.AssociationException)2 ConsumerException (org.openid4java.consumer.ConsumerException)2 FetchRequest (org.openid4java.message.ax.FetchRequest)2 UrlEncoded (com.google.gerrit.server.UrlEncoded)1 ArrayList (java.util.ArrayList)1