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

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

Introduction

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

Prototype

public OpenIDAttribute(String name, String type, List<String> values) 

Source Link

Usage

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  a  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<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();
    }// 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;
}