Example usage for org.springframework.security.openid OpenIDAttribute isRequired

List of usage examples for org.springframework.security.openid OpenIDAttribute isRequired

Introduction

In this page you can find the example usage for org.springframework.security.openid OpenIDAttribute isRequired.

Prototype

public boolean isRequired() 

Source Link

Document

The "required" flag for the attribute when used with an authentication request.

Usage

From source file:org.mitre.provenance.openid.OpenId4JavaProxyConsumer.java

public String beginConsumption(HttpServletRequest req, String identityUrl, String returnToUrl, String realm)
        throws OpenIDConsumerException {
    List<DiscoveryInformation> discoveries;

    try {//  www  .  ja v  a2 s .  co  m
        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);
}

From source file:org.mitre.provenance.openid.OpenId4JavaProxyConsumer.java

List<OpenIDAttribute> fetchAxAttributes(Message authSuccess, List<OpenIDAttribute> attributesToFetch)
        throws OpenIDConsumerException {

    if (attributesToFetch == null || !authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
        return Collections.emptyList();
    }//from w  w  w.  j  ava  2 s.c o m

    logger.debug("Extracting attributes retrieved by attribute exchange");

    List<OpenIDAttribute> attributes = Collections.emptyList();

    try {
        MessageExtension ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX);
        if (ext instanceof FetchResponse) {
            FetchResponse fetchResp = (FetchResponse) ext;
            attributes = new ArrayList<OpenIDAttribute>(attributesToFetch.size());

            for (OpenIDAttribute attr : attributesToFetch) {
                List<String> values = fetchResp.getAttributeValues(attr.getName());
                if (!values.isEmpty()) {
                    OpenIDAttribute fetched = new OpenIDAttribute(attr.getName(), attr.getType(), values);
                    fetched.setRequired(attr.isRequired());
                    attributes.add(fetched);
                }
            }
        }
    } catch (MessageException e) {
        throw new OpenIDConsumerException("Attribute retrieval failed", e);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Retrieved attributes" + attributes);
    }

    return attributes;
}

From source file:org.springframework.security.openid.OpenID4JavaConsumer.java

List<OpenIDAttribute> fetchAxAttributes(Message authSuccess, List<OpenIDAttribute> attributesToFetch)
        throws OpenIDConsumerException {

    if (attributesToFetch == null || !authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
        return Collections.emptyList();
    }//from   www .ja  v a  2  s.c o m

    logger.debug("Extracting attributes retrieved by attribute exchange");

    List<OpenIDAttribute> attributes = Collections.emptyList();

    try {
        MessageExtension ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX);
        if (ext instanceof FetchResponse) {
            FetchResponse fetchResp = (FetchResponse) ext;
            attributes = new ArrayList<>(attributesToFetch.size());

            for (OpenIDAttribute attr : attributesToFetch) {
                List<String> values = fetchResp.getAttributeValues(attr.getName());
                if (!values.isEmpty()) {
                    OpenIDAttribute fetched = new OpenIDAttribute(attr.getName(), attr.getType(), values);
                    fetched.setRequired(attr.isRequired());
                    attributes.add(fetched);
                }
            }
        }
    } catch (MessageException e) {
        throw new OpenIDConsumerException("Attribute retrieval failed", e);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Retrieved attributes" + attributes);
    }

    return attributes;
}