Search in sources :

Example 6 with DiscoEntryElement

use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.

the class SMDiscoveryServiceData method getEntries.

/**
     * Returns resource offering entry stored in the Directory Server.
     *
     * @param set Set of entry data.
     * @param type Type of offering entry, global, dynamic or user.
     * @return resource offering entry stored in the Directory Server.
     */
public static SMDiscoveryServiceData getEntries(Set set, int type) throws AMConsoleException {
    SMDiscoveryServiceData smEntry = new SMDiscoveryServiceData();
    smEntry.setEntryType(type);
    if (set != null && !set.isEmpty()) {
        try {
            JAXBContext jc = JAXBContext.newInstance(Utils.getJAXBPackages());
            Unmarshaller u = jc.createUnmarshaller();
            for (Iterator iter = set.iterator(); iter.hasNext(); ) {
                String str = (String) iter.next();
                SMDiscoEntryData smDisco = new SMDiscoEntryData();
                smDisco.discoStr = str;
                DiscoEntryElement entry = (DiscoEntryElement) u.unmarshal(XMLUtils.createSAXSource(new InputSource(new StringReader(str))));
                setDiscoEntryData(entry, smDisco);
                smEntry.addResourceData(smDisco);
            }
        } catch (JAXBException je) {
            debug.error("SMDiscoveryServiceData.getEntries", je);
        }
    }
    return smEntry;
}
Also used : InputSource(org.xml.sax.InputSource) JAXBException(javax.xml.bind.JAXBException) Iterator(java.util.Iterator) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement)

Example 7 with DiscoEntryElement

use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.

the class DiscoEntryHandlerImplUtils method setGlobalDiscoEntries.

/**
     * Registers the discovery service resource offerings to the AMIdentity
     *  
     * This is used by the global disocvery service handler to register
     * the resource offerings to the realm, org, role etc.
     * @param amIdentity the idrepo object that the resource offerings are 
     *                   being set.
     * @param attrName the discovery service attribute name where the disco
     *                 entries are being stored.
     * @param entries the list of discovery services that needs to be set. 
     * @return true if successfully set the entries.
     */
public static boolean setGlobalDiscoEntries(AMIdentity amIdentity, String attrName, Collection entries) {
    try {
        Iterator i = entries.iterator();
        Set xmlStrings = new HashSet();
        String entryId = null;
        StringWriter sw = null;
        while (i.hasNext()) {
            sw = new StringWriter(1000);
            DiscoUtils.getDiscoMarshaller().marshal(((DiscoEntryElement) i.next()), sw);
            xmlStrings.add(sw.getBuffer().toString());
        }
        Map map = new HashMap();
        map.put(attrName, xmlStrings);
        amIdentity.modifyService("sunIdentityServerDiscoveryService", map);
        amIdentity.store();
        return true;
    } catch (Exception e) {
        debug.error("DiscoEntryHandlerImplUtils.setServiceDiscoEntries:" + " Exception", e);
        return false;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) Iterator(java.util.Iterator) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement) HashMap(java.util.HashMap) Map(java.util.Map) JAXBException(javax.xml.bind.JAXBException) HashSet(java.util.HashSet)

Example 8 with DiscoEntryElement

use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.

the class AuthnSvcUtils method setResourceOfferingAndCredentials.

/**
     * Sets resource offering and credentials to the SASL response based on
     * provided sso token.
     * @param saslResp a SASL response
     * @param message a SOAP message containing a SASL request
     * @param userDN Distinguished Name of the User.
     * @return <code>true</code> if it sets correctly
     */
public static boolean setResourceOfferingAndCredentials(SASLResponse saslResp, Message message, String userDN) {
    try {
        DiscoEntryElement discoEntry = (DiscoEntryElement) DiscoServiceManager.getBootstrappingDiscoEntry();
        ResourceOfferingType offering = discoEntry.getResourceOffering();
        if (!DiscoServiceManager.useImpliedResource()) {
            ServiceInstanceType serviceInstance = offering.getServiceInstance();
            String providerID = serviceInstance.getProviderID();
            ResourceIDMapper idMapper = DiscoServiceManager.getResourceIDMapper(providerID);
            if (idMapper == null) {
                idMapper = DiscoServiceManager.getDefaultResourceIDMapper();
            }
            ObjectFactory fac = new com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory();
            ResourceIDType resourceID = fac.createResourceIDType();
            String resourceIDValue = idMapper.getResourceID(providerID, userDN);
            if (AuthnSvcUtils.debug.messageEnabled()) {
                AuthnSvcUtils.debug.message("AuthnSvcUtils.setResourceOfferingAndCredentials" + "Offering: ResourceID Value:" + resourceIDValue);
            }
            resourceID.setValue(resourceIDValue);
            offering.setResourceID(resourceID);
        } else {
            ObjectFactory fac = new com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory();
            ResourceIDType resourceID = fac.createResourceIDType();
            resourceID.setValue(DiscoConstants.IMPLIED_RESOURCE);
            offering.setResourceID(resourceID);
        }
        List discoEntryList = new ArrayList();
        discoEntryList.add(discoEntry);
        Map map = DiscoUtils.checkPolicyAndHandleDirectives(userDN, message, discoEntryList, null, null, null, message.getToken());
        List offerings = (List) map.get(DiscoUtils.OFFERINGS);
        if (offerings.isEmpty()) {
            if (AuthnSvcUtils.debug.messageEnabled()) {
                AuthnSvcUtils.debug.message("AuthnSvcUtils.setResourceOfferingAndCredentials" + "no ResourceOffering");
            }
            return false;
        }
        ResourceOffering ro = (ResourceOffering) offerings.get(0);
        saslResp.setResourceOffering(ro);
        List assertions = (List) map.get(DiscoUtils.CREDENTIALS);
        if ((assertions != null) && (!assertions.isEmpty())) {
            Iterator iter = assertions.iterator();
            List credentials = new ArrayList();
            while (iter.hasNext()) {
                SecurityAssertion assertion = (SecurityAssertion) iter.next();
                Document doc = XMLUtils.toDOMDocument(assertion.toString(true, true), AuthnSvcUtils.debug);
                credentials.add(doc.getDocumentElement());
            }
            saslResp.setCredentials(credentials);
        }
        return true;
    } catch (Exception ex) {
        debug.error("AuthnSvcUtils.setResourceOfferingAndCredentials:", ex);
        return false;
    }
}
Also used : ResourceOffering(com.sun.identity.liberty.ws.disco.ResourceOffering) ResourceOfferingType(com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType) ArrayList(java.util.ArrayList) SecurityAssertion(com.sun.identity.liberty.ws.security.SecurityAssertion) Document(org.w3c.dom.Document) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement) ServiceInstanceType(com.sun.identity.liberty.ws.disco.jaxb.ServiceInstanceType) ResourceIDMapper(com.sun.identity.liberty.ws.interfaces.ResourceIDMapper) ObjectFactory(com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ResourceIDType(com.sun.identity.liberty.ws.disco.jaxb.ResourceIDType) Map(java.util.Map)

Example 9 with DiscoEntryElement

use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.

the class DiscoEntryHandlerImplUtils method getGlobalDiscoEntries.

/**
     * This is used by the global disocvery service handler to retrieve
     * the resource offerings registered at the realm, org, role etc.
     */
public static void getGlobalDiscoEntries(AMIdentity amIdentity, String attrName, Map discoEntries, String userID) throws Exception {
    Map map = amIdentity.getServiceAttributes("sunIdentityServerDiscoveryService");
    Set attr = (Set) map.get(attrName);
    if (attr == null || attr.isEmpty()) {
        debug.error("DiscoEntryHandlerImplUtils.getServiceDiscoEntries: " + "The resource offerings are not available");
        return;
    }
    if (debug.messageEnabled()) {
        debug.message("DiscoEntryHandlerImplUtils.getServiceDiscoEntries: " + attr);
    }
    Iterator j = attr.iterator();
    String entryStr = null;
    String resIDValue = null;
    DiscoEntryElement entry = null;
    ResourceIDType resID = null;
    ResourceOfferingType resOff = null;
    String entryID = null;
    String providerID = null;
    while (j.hasNext()) {
        entryStr = (String) j.next();
        try {
            entry = (DiscoEntryElement) DiscoUtils.getDiscoUnmarshaller().unmarshal(XMLUtils.createSAXSource(new InputSource(new StringReader(entryStr))));
            resOff = entry.getResourceOffering();
            entryID = resOff.getEntryID();
            if (entryID == null) {
                entryID = SAMLUtils.generateID();
                resOff.setEntryID(entryID);
            }
            ResourceIDType rid = resOff.getResourceID();
            if ((rid == null) || (rid.getValue() == null) || (rid.getValue().equals(""))) {
                com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory discoFac = new com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory();
                resID = discoFac.createResourceIDType();
                resID.setValue(DiscoConstants.IMPLIED_RESOURCE);
                resOff.setResourceID(resID);
            }
            entry.setResourceOffering(resOff);
            discoEntries.put(entryID, entry);
        } catch (Exception e) {
            debug.error("DiscoEntryHandlerImplUtils.getServiceDiscoEntries:" + " Exception for getting entry: " + entryStr + ":", e);
            continue;
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) HashSet(java.util.HashSet) Set(java.util.Set) ResourceOfferingType(com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement) JAXBException(javax.xml.bind.JAXBException) Iterator(java.util.Iterator) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map) ResourceIDType(com.sun.identity.liberty.ws.disco.jaxb.ResourceIDType)

Example 10 with DiscoEntryElement

use of com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement in project OpenAM by OpenRock.

the class DiscoEntryHandlerImplUtils method getQueryResults.

/*
     * Finds the matching resource offering according to RequestedServiceType.
     * Used by <code>DiscoEntryHandler</code>s.
     *
     * @param discoEntries all discovery entries
     * @param reqServiceTypes List of requested service types
     * @return Map of matching discovery entries. In this map,
     *  key is <code>entryId</code>, value is <code>DiscoEntryElement</code>.
     */
public static Map getQueryResults(Map discoEntries, List reqServiceTypes) {
    Map results = null;
    if ((reqServiceTypes == null) || (reqServiceTypes.size() == 0)) {
        if (debug.messageEnabled()) {
            debug.message("DiscoEntryHandlerImplUtils.getQueryResults: " + "no reqServiceTypes");
        }
        results = discoEntries;
    } else {
        results = new HashMap();
        Iterator i = discoEntries.keySet().iterator();
        while (i.hasNext()) {
            String curKey = (String) i.next();
            DiscoEntryElement cur = (DiscoEntryElement) discoEntries.get(curKey);
            ResourceOfferingType offering = cur.getResourceOffering();
            String serviceType = offering.getServiceInstance().getServiceType();
            List options = null;
            if (offering.getOptions() != null) {
                options = offering.getOptions().getOption();
            }
            Iterator j = reqServiceTypes.iterator();
            while (j.hasNext()) {
                RequestedServiceTypeType curReqType = (RequestedServiceTypeType) j.next();
                String requestedServiceType = curReqType.getServiceType();
                if (!requestedServiceType.equals(serviceType)) {
                    continue;
                }
                List queryOptions = null;
                if (curReqType.getOptions() != null) {
                    queryOptions = curReqType.getOptions().getOption();
                }
                if (evaluateOptionsRules(queryOptions, options)) {
                    /* code for proxy support
                        if (proxyServiceTypes.contains(serviceType)) {
                            if (this cur is that proxy) {
                                results.add(cur);
                            } else if (requester is the provider) {
                                results.add(cur);
                            }
                        } else {
                            results.add(cur);
                        }
                        */
                    results.put(curKey, cur);
                    break;
                }
            }
        }
    }
    return results;
}
Also used : RequestedServiceTypeType(com.sun.identity.liberty.ws.disco.jaxb.QueryType.RequestedServiceTypeType) HashMap(java.util.HashMap) Iterator(java.util.Iterator) ResourceOfferingType(com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement)

Aggregations

DiscoEntryElement (com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement)11 Iterator (java.util.Iterator)8 Map (java.util.Map)8 JAXBException (javax.xml.bind.JAXBException)7 ResourceOfferingType (com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType)6 List (java.util.List)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 ResourceIDType (com.sun.identity.liberty.ws.disco.jaxb.ResourceIDType)4 ArrayList (java.util.ArrayList)4 ResourceOffering (com.sun.identity.liberty.ws.disco.ResourceOffering)3 ServiceInstanceType (com.sun.identity.liberty.ws.disco.jaxb.ServiceInstanceType)3 ResourceIDMapper (com.sun.identity.liberty.ws.interfaces.ResourceIDMapper)3 StringReader (java.io.StringReader)3 InputSource (org.xml.sax.InputSource)3 ObjectFactory (com.sun.identity.liberty.ws.disco.jaxb.ObjectFactory)2 StringWriter (java.io.StringWriter)2 LinkedList (java.util.LinkedList)2 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)1