Search in sources :

Example 1 with AuthRequest

use of org.openid4java.message.AuthRequest in project hale by halestudio.

the class ProxyOpenIDConsumer method beginConsumption.

@Override
public String beginConsumption(HttpServletRequest req, String identityUrl, String returnToUrl, String realm) throws OpenIDConsumerException {
    List<?> discoveries;
    try {
        discoveries = this.consumerManager.discover(identityUrl);
    } catch (DiscoveryException e) {
        throw new OpenIDConsumerException("Error during discovery", e);
    }
    DiscoveryInformation information = this.consumerManager.associate(discoveries);
    req.getSession().setAttribute(DISCOVERY_INFO_KEY, information);
    AuthRequest authReq;
    try {
        authReq = this.consumerManager.authenticate(information, returnToUrl, realm);
        log.debug("Looking up attribute fetch list for identifier: " + identityUrl);
        List<OpenIDAttribute> attributesToFetch = this.attributesToFetchFactory.createAttributeList(identityUrl);
        if (!(attributesToFetch.isEmpty())) {
            req.getSession().setAttribute("SPRING_SECURITY_OPEN_ID_ATTRIBUTES_FETCH_LIST", attributesToFetch);
            FetchRequest fetchRequest = FetchRequest.createFetchRequest();
            for (OpenIDAttribute attr : attributesToFetch) {
                if (log.isDebugEnabled()) {
                    log.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 : OpenIDAttribute(org.springframework.security.openid.OpenIDAttribute) AuthRequest(org.openid4java.message.AuthRequest) MessageException(org.openid4java.message.MessageException) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) OpenIDConsumerException(org.springframework.security.openid.OpenIDConsumerException) FetchRequest(org.openid4java.message.ax.FetchRequest) ConsumerException(org.openid4java.consumer.ConsumerException) OpenIDConsumerException(org.springframework.security.openid.OpenIDConsumerException) DiscoveryException(org.openid4java.discovery.DiscoveryException)

Example 2 with AuthRequest

use of org.openid4java.message.AuthRequest 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)

Example 3 with AuthRequest

use of org.openid4java.message.AuthRequest in project gerrit by GerritCodeReview.

the class OpenIdServiceImpl method discover.

@SuppressWarnings("unchecked")
DiscoveryResult discover(HttpServletRequest req, String openidIdentifier, SignInMode mode, boolean remember, String returnToken) {
    final State state;
    state = init(req, openidIdentifier, mode, remember, returnToken);
    if (state == null) {
        return new DiscoveryResult(DiscoveryResult.Status.NO_PROVIDER);
    }
    final AuthRequest aReq;
    try {
        aReq = manager.authenticate(state.discovered, state.retTo.toString());
        logger.atFine().log("OpenID: openid-realm=%s", state.contextUrl);
        aReq.setRealm(state.contextUrl);
        if (requestRegistration(aReq)) {
            final SRegRequest sregReq = SRegRequest.createFetchRequest();
            sregReq.addAttribute("fullname", true);
            sregReq.addAttribute("email", true);
            aReq.addExtension(sregReq);
            final FetchRequest fetch = FetchRequest.createFetchRequest();
            fetch.addAttribute("FirstName", SCHEMA_FIRSTNAME, true);
            fetch.addAttribute("LastName", SCHEMA_LASTNAME, true);
            fetch.addAttribute("Email", SCHEMA_EMAIL, true);
            aReq.addExtension(fetch);
        }
        if (0 <= papeMaxAuthAge) {
            final PapeRequest pape = PapeRequest.createPapeRequest();
            pape.setMaxAuthAge(papeMaxAuthAge);
            aReq.addExtension(pape);
        }
    } catch (MessageException | ConsumerException e) {
        logger.atSevere().withCause(e).log("Cannot create OpenID redirect for %s", openidIdentifier);
        return new DiscoveryResult(DiscoveryResult.Status.ERROR);
    }
    return new DiscoveryResult(aReq.getDestinationUrl(false), aReq.getParameterMap());
}
Also used : AuthRequest(org.openid4java.message.AuthRequest) SRegRequest(org.openid4java.message.sreg.SRegRequest) PapeRequest(org.openid4java.message.pape.PapeRequest) MessageException(org.openid4java.message.MessageException) FetchRequest(org.openid4java.message.ax.FetchRequest) ConsumerException(org.openid4java.consumer.ConsumerException)

Example 4 with AuthRequest

use of org.openid4java.message.AuthRequest in project spring-security by spring-projects.

the class OpenID4JavaConsumerTests method beginConsumptionCreatesExpectedSessionData.

@SuppressWarnings("deprecation")
@Test
public void beginConsumptionCreatesExpectedSessionData() throws Exception {
    ConsumerManager mgr = mock(ConsumerManager.class);
    AuthRequest authReq = mock(AuthRequest.class);
    DiscoveryInformation di = mock(DiscoveryInformation.class);
    when(mgr.authenticate(any(DiscoveryInformation.class), anyString(), anyString())).thenReturn(authReq);
    when(mgr.associate(anyList())).thenReturn(di);
    OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr, new MockAttributesFactory());
    MockHttpServletRequest request = new MockHttpServletRequest();
    consumer.beginConsumption(request, "", "", "");
    assertThat(request.getSession().getAttribute("SPRING_SECURITY_OPEN_ID_ATTRIBUTES_FETCH_LIST")).isEqualTo(attributes);
    assertThat(request.getSession().getAttribute(DiscoveryInformation.class.getName())).isEqualTo(di);
    // Check with empty attribute fetch list
    consumer = new OpenID4JavaConsumer(mgr, new NullAxFetchListFactory());
    request = new MockHttpServletRequest();
    consumer.beginConsumption(request, "", "", "");
}
Also used : AuthRequest(org.openid4java.message.AuthRequest) ConsumerManager(org.openid4java.consumer.ConsumerManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation)

Example 5 with AuthRequest

use of org.openid4java.message.AuthRequest 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)

Aggregations

AuthRequest (org.openid4java.message.AuthRequest)7 DiscoveryInformation (org.openid4java.discovery.DiscoveryInformation)5 FetchRequest (org.openid4java.message.ax.FetchRequest)5 ConsumerException (org.openid4java.consumer.ConsumerException)4 MessageException (org.openid4java.message.MessageException)4 List (java.util.List)2 DiscoveryException (org.openid4java.discovery.DiscoveryException)2 ParameterList (org.openid4java.message.ParameterList)2 AccountException (com.google.gerrit.server.account.AccountException)1 Cookie (javax.servlet.http.Cookie)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 OpenIDException (org.openid4java.OpenIDException)1 ConsumerManager (org.openid4java.consumer.ConsumerManager)1 VerificationResult (org.openid4java.consumer.VerificationResult)1