Search in sources :

Example 1 with Status

use of com.sun.identity.liberty.ws.common.Status in project OpenAM by OpenRock.

the class DiscoveryService method lookup.

/**
     * Finds the resource offerings requested in the query.
     * @param query The incoming Discovery Query request.
     * @param message soapbinding message that contains info regarding sending
     *          identities that can be used in access control
     * @return org.w3c.dom.Element which is the QueryResponse of this operation.
     *          Inside this QueryResponse, Credentials may be included, and
     *          ResourceID may be encrypted if required.
     */
private org.w3c.dom.Element lookup(com.sun.identity.liberty.ws.disco.jaxb.QueryType query, com.sun.identity.liberty.ws.soapbinding.Message message) throws JAXBException {
    DiscoUtils.debug.message("in lookup.");
    Status status = new Status(DiscoConstants.DISCO_NS, DiscoConstants.DISCO_NSPREFIX);
    QueryResponse resp = new QueryResponse(status);
    String providerID = DiscoServiceManager.getDiscoProviderID();
    String resourceID = null;
    ResourceIDType resID = query.getResourceID();
    if (resID == null) {
        resourceID = getResourceID(query.getEncryptedResourceID(), providerID);
    } else {
        resourceID = resID.getValue();
    }
    DiscoEntryHandler entryHandler = null;
    String userDN = null;
    boolean isB2E = false;
    if (resourceID == null || resourceID.equals(DiscoConstants.IMPLIED_RESOURCE)) {
        // B2E case           
        DiscoUtils.debug.message("DiscoveryService.lookup: in B2E case");
        isB2E = true;
    }
    if (!isB2E) {
        // find the disco ResourceIDMapper from config
        ResourceIDMapper idMapper = DiscoServiceManager.getResourceIDMapper(providerID);
        if (idMapper == null) {
            idMapper = DiscoServiceManager.getDefaultResourceIDMapper();
        }
        userDN = idMapper.getUserID(providerID, resourceID, message);
        if (userDN == null) {
            DiscoUtils.debug.error("DiscoService.lookup: couldn't find the " + "user associated with the resourceID:" + resourceID);
            status.setCode(DiscoConstants.QNAME_FAILED);
            Document doc = null;
            try {
                doc = XMLUtils.newDocument();
            } catch (Exception ex) {
                DiscoUtils.debug.error("DiscoService.lookup:", ex);
            }
            DiscoUtils.getDiscoMarshaller().marshal(resp, doc);
            return doc.getDocumentElement();
        }
        if (DiscoUtils.debug.messageEnabled()) {
            DiscoUtils.debug.message("DiscoService.lookup: userDN=" + userDN);
        }
        entryHandler = DiscoServiceManager.getDiscoEntryHandler();
    } else {
        entryHandler = DiscoServiceManager.getGlobalEntryHandler();
    }
    if (entryHandler == null) {
        status.setCode(DiscoConstants.QNAME_FAILED);
        DiscoUtils.debug.message("DiscoService.lookup: null DiscoEntryHandler.");
        return XMLUtils.toDOMDocument(resp.toString(), null).getDocumentElement();
    }
    Map discoEntriesMap = entryHandler.getDiscoEntries(userDN, query.getRequestedServiceType());
    Collection results = discoEntriesMap.values();
    Map returnMap = null;
    if (results.size() == 0) {
        if (DiscoUtils.debug.messageEnabled()) {
            DiscoUtils.debug.message("DiscoService.lookup: lookup " + "NoResults for user:" + userDN);
        }
        status.setCode(DiscoConstants.QNAME_FAILED);
        String[] data = { userDN };
        LogUtil.error(Level.INFO, LogUtil.DS_LOOKUP_FAILURE, data);
    } else {
        if (DiscoUtils.debug.messageEnabled()) {
            DiscoUtils.debug.message("DiscoService.lookup: find " + results.size() + "ResourceOfferings for userDN:" + userDN);
        }
        Authorizer authorizer = null;
        if (DiscoServiceManager.needPolicyEvalLookup()) {
            DiscoUtils.debug.message("DiscoService.lookup:needPolicyEval.");
            authorizer = DiscoServiceManager.getAuthorizer();
            if (authorizer == null) {
                status.setCode(DiscoConstants.QNAME_FAILED);
                String[] data = { userDN };
                LogUtil.error(Level.INFO, LogUtil.DS_LOOKUP_FAILURE, data);
                return XMLUtils.toDOMDocument(resp.toString(), null).getDocumentElement();
            }
        }
        returnMap = DiscoUtils.checkPolicyAndHandleDirectives(userDN, message, results, authorizer, null, null, message.getToken());
        List offerings = (List) returnMap.get(DiscoUtils.OFFERINGS);
        if (offerings.isEmpty()) {
            if (DiscoUtils.debug.messageEnabled()) {
                DiscoUtils.debug.message("DiscoService.lookup: after policy" + " check and directive handling, NoResults for:" + userDN);
            }
            status.setCode(DiscoConstants.QNAME_FAILED);
            String[] data = { userDN };
            LogUtil.error(Level.INFO, LogUtil.DS_LOOKUP_FAILURE, data);
        } else {
            resp.setResourceOffering(offerings);
            DiscoUtils.debug.message("after resp.getresoff.addall");
            List credentials = (List) returnMap.get(DiscoUtils.CREDENTIALS);
            if ((credentials != null) && (!credentials.isEmpty())) {
                DiscoUtils.debug.message("DiscoService.lookup: has cred.");
                resp.setCredentials(credentials);
            }
            status.setCode(DiscoConstants.QNAME_OK);
            String[] data = { userDN };
            LogUtil.access(Level.INFO, LogUtil.DS_LOOKUP_SUCCESS, data);
        }
    }
    return XMLUtils.toDOMDocument(resp.toString(), null).getDocumentElement();
}
Also used : Status(com.sun.identity.liberty.ws.common.Status) JAXBException(javax.xml.bind.JAXBException) Collection(java.util.Collection) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Status

use of com.sun.identity.liberty.ws.common.Status in project OpenAM by OpenRock.

the class DiscoSDKUtils method parseStatus.

/**
     * Parses Status element.
     * @param elem Status element.
     * @return Status object.
     * @exception DiscoveryException if error occurs.
     */
public static Status parseStatus(org.w3c.dom.Element elem) throws DiscoveryException {
    if (elem == null) {
        debug.message("DiscoUtils.parseStatus: nullInput");
        throw new DiscoveryException(bundle.getString("nullInput"));
    }
    String nameSpaceURI = elem.getNamespaceURI();
    String prefix = elem.getPrefix();
    Status status = new Status(nameSpaceURI, prefix);
    String code = elem.getAttribute("code");
    if ((code == null) || (code.length() == 0)) {
        debug.message("DiscoUtils.parseStatus: missing status code.");
        throw new DiscoveryException(bundle.getString("missingStatusCode"));
    }
    String codeNS = nameSpaceURI;
    String codePrefix = prefix;
    String localPart = code;
    if (code.indexOf(":") != -1) {
        StringTokenizer st = new StringTokenizer(code, ":");
        if (st.countTokens() != 2) {
            debug.message("DiscoUtils.parseStatus: wrong status code.");
            throw new DiscoveryException(bundle.getString("wrongInput"));
        }
        codePrefix = st.nextToken();
        localPart = st.nextToken();
    }
    if ((codePrefix != null) && (prefix != null) && (!codePrefix.equals(prefix))) {
        codeNS = elem.getAttribute("xmlns:" + codePrefix);
    }
    if ((codeNS != null) && (codeNS.length() != 0)) {
        if ((codePrefix != null) && (codePrefix.length() != 0)) {
            status.setCode(new QName(codeNS, localPart, codePrefix));
        } else {
            status.setCode(new QName(codeNS, localPart));
        }
    } else {
        status.setCode(new QName(localPart));
    }
    status.setComment(elem.getAttribute("comment"));
    status.setRef(elem.getAttribute("ref"));
    List subStatusL = XMLUtils.getElementsByTagNameNS1(elem, DiscoConstants.DISCO_NS, "Status");
    int num = subStatusL.size();
    if (num != 0) {
        if (num == 1) {
            status.setSubStatus(parseStatus((Element) subStatusL.get(0)));
        } else {
            if (debug.messageEnabled()) {
                debug.message("DiscoUtils.parseStatus: included more than " + "one sub status.");
            }
            throw new DiscoveryException(bundle.getString("moreElement"));
        }
    }
    return status;
}
Also used : Status(com.sun.identity.liberty.ws.common.Status) StringTokenizer(java.util.StringTokenizer) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException)

Example 3 with Status

use of com.sun.identity.liberty.ws.common.Status in project OpenAM by OpenRock.

the class DSTUtils method parseStatus.

public static Status parseStatus(Element element) throws DSTException {
    if (element == null) {
        debug.error("DSTUtils.parseStatus: nullInputParams");
        throw new DSTException(bundle.getString("nullInputParams"));
    }
    String nameSpaceURI = element.getNamespaceURI();
    String prefix = element.getPrefix();
    Status status = new Status(nameSpaceURI, prefix);
    String code = element.getAttribute("code");
    if (code != null && code.length() != 0) {
        String localPart = null;
        String codePrefix = "";
        if (code.indexOf(":") != -1) {
            StringTokenizer st = new StringTokenizer(code, ":");
            if (st.countTokens() != 2) {
                throw new DSTException(bundle.getString("invalidStatus"));
            }
            codePrefix = st.nextToken();
            localPart = st.nextToken();
        } else {
            localPart = code;
        }
        QName qName = new QName(nameSpaceURI, localPart, codePrefix);
        status.setCode(qName);
    } else {
        throw new DSTException(bundle.getString("invalidStatus"));
    }
    status.setComment(element.getAttribute("comment"));
    status.setRef(element.getAttribute("ref"));
    return status;
}
Also used : Status(com.sun.identity.liberty.ws.common.Status) StringTokenizer(java.util.StringTokenizer) QName(javax.xml.namespace.QName)

Aggregations

Status (com.sun.identity.liberty.ws.common.Status)3 List (java.util.List)2 StringTokenizer (java.util.StringTokenizer)2 QName (javax.xml.namespace.QName)2 DiscoveryException (com.sun.identity.liberty.ws.disco.DiscoveryException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JAXBException (javax.xml.bind.JAXBException)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1