Search in sources :

Example 1 with DiscoEntryElement

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

the class SMDiscoEntryData method setDiscoStr.

public void setDiscoStr(boolean isUserView) throws AMConsoleException {
    try {
        ResourceOfferingType res = discoFac.createResourceOfferingType();
        ResourceIDType rid = discoFac.createResourceIDType();
        // if user resource offering then set resource id type.
        if (isUserView) {
            if ((resourceIdAttribute != null) && resourceIdAttribute.length() > 0) {
                rid.setId(resourceIdAttribute);
            }
            rid.setValue(resourceIdValue);
            res.setEntryID(entryId);
        } else {
            /*
                 * jaxb api requires that we set resource id value to empty
                 * string if there is no value so that it will create empty tag
                 * for Resource ID.
                 */
            rid.setValue("");
        }
        ServiceInstanceType svc = createServiceInstanceEntry();
        List descriptionTypeList = (List) svc.getDescription();
        res.setServiceInstance(svc);
        res.setResourceID(rid);
        if (abstractValue != null && abstractValue.length() > 0) {
            res.setAbstract(abstractValue);
        }
        if (!noOption) {
            res.setOptions(createOptionsEntry());
        }
        DiscoEntryElement de = entryFac.createDiscoEntryElement();
        de.setResourceOffering(res);
        createDirectivesEntry(de, descriptionTypeList);
        String str = convertDiscoEntryToXmlStr(de);
        if (str == null || str.length() == 0) {
            throw new AMConsoleException("discoEntryFailed.message");
        } else {
            discoStr = str;
        }
    } catch (JAXBException e) {
        Throwable t = e.getLinkedException();
        String str = (t != null) ? t.getMessage() : e.toString();
        throw new AMConsoleException(str);
    }
}
Also used : ServiceInstanceType(com.sun.identity.liberty.ws.disco.jaxb.ServiceInstanceType) JAXBException(javax.xml.bind.JAXBException) ResourceOfferingType(com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType) ArrayList(java.util.ArrayList) List(java.util.List) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) ResourceIDType(com.sun.identity.liberty.ws.disco.jaxb.ResourceIDType) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement)

Example 2 with DiscoEntryElement

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

the class FSDiscoveryBootStrap method getResourceOffering.

/**
     * Gets the discovery bootstrap resource offering for the user.
     * @return Document Discovery Resource Offering in an attribute statement
     * @exception FSException if there's any failure.
     */
private Document getResourceOffering(FSSubject libSubject, AuthnContext authnContext, String userID, String wscID, String realm) throws FSException {
    FSUtils.debug.message("FSDiscoveryBootStrap.getResourceOffering:Init");
    StringBuffer sb = new StringBuffer(300);
    sb.append("<").append(SAMLConstants.ASSERTION_PREFIX).append("AttributeValue").append(SAMLConstants.assertionDeclareStr).append(">").append(SAMLConstants.NL);
    DiscoEntryElement discoEntry = DiscoServiceManager.getBootstrappingDiscoEntry();
    if (discoEntry == null) {
        throw new FSException("nullDiscoveryOffering", null);
    }
    try {
        ResourceOfferingType offering = discoEntry.getResourceOffering();
        ServiceInstanceType serviceInstance = offering.getServiceInstance();
        String providerID = serviceInstance.getProviderID();
        if (!DiscoServiceManager.useImpliedResource()) {
            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, userID);
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSDiscoveryBootStrap.getResource" + "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);
        SessionSubject sessionSubject = null;
        if (DiscoServiceManager.encryptNIinSessionContext()) {
            sessionSubject = new SessionSubject(EncryptedNameIdentifier.getEncryptedNameIdentifier(libSubject.getNameIdentifier(), realm, providerID), libSubject.getSubjectConfirmation(), libSubject.getIDPProvidedNameIdentifier());
        } else {
            sessionSubject = new SessionSubject(libSubject.getNameIdentifier(), libSubject.getSubjectConfirmation(), libSubject.getIDPProvidedNameIdentifier());
        }
        SessionContext invocatorSession = new SessionContext(sessionSubject, authnContext, providerID);
        Map map = DiscoUtils.checkPolicyAndHandleDirectives(userID, null, discoEntryList, null, invocatorSession, wscID, _ssoToken);
        List offerings = (List) map.get(DiscoUtils.OFFERINGS);
        if (offerings.isEmpty()) {
            FSUtils.debug.message("FSDiscoBootStrap.getResourceOffering:no ResourceOffering");
            throw new FSException("nullDiscoveryOffering", null);
        }
        ResourceOffering resourceOffering = (ResourceOffering) offerings.get(0);
        _assertions = (List) map.get(DiscoUtils.CREDENTIALS);
        if ((_assertions != null) && (_assertions.size() != 0)) {
            _hasCredentials = true;
        }
        sb.append(resourceOffering.toString());
        sb.append("</").append(SAMLConstants.ASSERTION_PREFIX).append("AttributeValue>");
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSDiscoveryBootStap.getResourceOffering:Resource Offering:" + sb.toString());
        }
        return XMLUtils.toDOMDocument(sb.toString(), null);
    } catch (Exception ex) {
        FSUtils.debug.error("FSDiscoveryBootStrap.getResourceOffering:" + "Exception while creating resource offering.", ex);
        throw new FSException(ex);
    }
}
Also used : ResourceOffering(com.sun.identity.liberty.ws.disco.ResourceOffering) ArrayList(java.util.ArrayList) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement) FSException(com.sun.identity.federation.common.FSException) ResourceIDMapper(com.sun.identity.liberty.ws.interfaces.ResourceIDMapper) FSException(com.sun.identity.federation.common.FSException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with DiscoEntryElement

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

the class DiscoEntryHandlerImplUtils method handleInserts.

/*
     * Adds discovery entries.
     * Used by implementations of SPI <code>DiscoEntryHandler</code>:
     * <code>UserDiscoEntryHandler</code> and
     * <code>UserDynamicEntryHandler</code>.
     *
     * @param discoEntriesMap Discovery Entries Map.
     * @param removes List of entries to be added.
     * @return true if the operation is successful; false otherwise.
     */
public static Map handleInserts(Set discoEntries, List inserts) {
    /*
         * if support proxy:
         * look through discoEntries and find all the serviceTypes that have
         *  proxy proxyServiceTypes
         */
    Map insertResults = new HashMap();
    insertResults.put(DiscoEntryHandler.STATUS_CODE, DiscoConstants.STATUS_FAILED);
    Set supportedDirectives = DiscoServiceManager.getSupportedDirectives();
    if (debug.messageEnabled()) {
        debug.message("DiscoEntryHandlerImplUtils.handleInserts: " + "size of supportedDirective is " + supportedDirectives.size());
    }
    Iterator i = inserts.iterator();
    InsertEntryType insertEntry = null;
    DiscoEntryElement de = null;
    ResourceOfferingType resOff = null;
    List newEntryIDs = new LinkedList();
    while (i.hasNext()) {
        insertEntry = (InsertEntryType) i.next();
        try {
            de = DiscoUtils.getDiscoEntryFactory().createDiscoEntryElement();
        } catch (JAXBException je) {
            debug.error("DiscoEntryHandlerImplUtils.handleInserts: couldn't " + "create DiscoEntry: ", je);
            return insertResults;
        }
        resOff = insertEntry.getResourceOffering();
        String newEntryID = SAMLUtils.generateID();
        if (debug.messageEnabled()) {
            debug.message("DiscoEntryHandlerImplUtils: newEntryID=" + newEntryID);
        }
        resOff.setEntryID(newEntryID);
        newEntryIDs.add(newEntryID);
        de.setResourceOffering(resOff);
        List dirs = insertEntry.getAny();
        if ((dirs != null) && !dirs.isEmpty()) {
            Iterator j = dirs.iterator();
            while (j.hasNext()) {
                Object dir = j.next();
                if (dir instanceof AuthenticateRequesterElement) {
                    if (!supportedDirectives.contains(DiscoConstants.AUTHN_DIRECTIVE)) {
                        debug.error("Directive AuthenticateRequester is " + "not supported.");
                        return insertResults;
                    }
                } else if (dir instanceof AuthorizeRequesterElement) {
                    if (!supportedDirectives.contains(DiscoConstants.AUTHZ_DIRECTIVE)) {
                        debug.error("Directive AuthorizeRequester is " + "not supported.");
                        return insertResults;
                    }
                } else if (dir instanceof AuthenticateSessionContextElement) {
                    if (!supportedDirectives.contains(DiscoConstants.SESSION_DIRECTIVE)) {
                        debug.error("Directive AuthenticateSessionContext " + "is not supported.");
                        return insertResults;
                    }
                } else if (dir instanceof EncryptResourceIDElement) {
                    if (!supportedDirectives.contains(DiscoConstants.ENCRYPT_DIRECTIVE)) {
                        debug.error("Directive EncryptResourceID " + "is not supported.");
                        return insertResults;
                    }
                } else if (dir instanceof GenerateBearerTokenElement) {
                    if (!supportedDirectives.contains(DiscoConstants.BEARER_DIRECTIVE)) {
                        debug.error("Directive GenerateBearerToken " + "is not supported.");
                        return insertResults;
                    }
                } else {
                    debug.error("Directive " + dir + " is not supported.");
                    return insertResults;
                }
            }
            de.getAny().addAll(dirs);
        }
        if (!discoEntries.add(de)) {
            debug.error("DiscoEntryHandlerImplUtils.handleInserts: couldn't " + "add DiscoEntry to Set.");
            return insertResults;
        }
    }
    insertResults.put(DiscoEntryHandler.STATUS_CODE, DiscoConstants.STATUS_OK);
    insertResults.put(DiscoEntryHandler.NEW_ENTRY_IDS, newEntryIDs);
    return insertResults;
}
Also used : GenerateBearerTokenElement(com.sun.identity.liberty.ws.disco.jaxb11.GenerateBearerTokenElement) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) ResourceOfferingType(com.sun.identity.liberty.ws.disco.jaxb.ResourceOfferingType) AuthenticateSessionContextElement(com.sun.identity.liberty.ws.disco.jaxb.AuthenticateSessionContextElement) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement) AuthorizeRequesterElement(com.sun.identity.liberty.ws.disco.jaxb.AuthorizeRequesterElement) LinkedList(java.util.LinkedList) EncryptResourceIDElement(com.sun.identity.liberty.ws.disco.jaxb.EncryptResourceIDElement) Iterator(java.util.Iterator) AuthenticateRequesterElement(com.sun.identity.liberty.ws.disco.jaxb.AuthenticateRequesterElement) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) InsertEntryType(com.sun.identity.liberty.ws.disco.jaxb.InsertEntryType)

Example 4 with DiscoEntryElement

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

the class DiscoEntryHandlerImplUtils method setUserDiscoEntries.

/*
     * Sets discovery entries to user entry.
     * Used by implementations of SPI <code>DiscoEntryHandler:
     * <code>UserDiscoEntryHandler</code> and
     * <code>UserDynamicEntryHandler</code>.
     * @param store <code>DataStoreProvider</code> object.
     * @param userID user ID.
     * @param attrName name of the user attribute to set to.
     * @param entries <code>Collection</code> of <code>DiscoEntryElement</code>
     *  to be set.
     * @return true if the operation is successful.
     */
public static boolean setUserDiscoEntries(DataStoreProvider store, String userID, String attrName, Collection entries) {
    debug.message("in DiscoEntryHandlerImplUtils.setUserDiscoEntries");
    try {
        Iterator i = entries.iterator();
        Set xmlStrings = new HashSet();
        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);
        store.setAttributes(userID, map);
        return true;
    } catch (Exception e) {
        debug.error("DiscoEntryHandlerImplUtils.setUserDiscoEntries: 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 5 with DiscoEntryElement

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

the class DiscoEntryHandlerImplUtils method getUserDiscoEntries.

/*
     * Retrieves discovery entries from an user entry.
     * Used by implementations of SPI <code>DiscoEntryHandler</code>:
     * <code>DynamicDiscoEntryHandler</code> and
     * <code>UserDynamicEntryHandler</code>.
     * @param store <code>DataStoreProvider</code> object.
     * @param userID user ID.
     * @param attrName name of the user attribute.
     * @param discoEntries The results are returned through Map of
     *  <code>entryId</code> to <code>DiscoEntryElement</code> object.
     * @return true if the results need to be stored; false otherwise.
     * @throws Exception if SDK errors occurred.
     */
public static boolean getUserDiscoEntries(DataStoreProvider store, String userID, String attrName, Map discoEntries) throws Exception {
    boolean needStore = false;
    Set attr = store.getAttribute(userID, attrName);
    Iterator i = attr.iterator();
    DiscoEntryElement entry = null;
    String entryID = null;
    String entryStr = null;
    while (i.hasNext()) {
        entryStr = (String) i.next();
        try {
            entry = (DiscoEntryElement) DiscoUtils.getDiscoUnmarshaller().unmarshal(XMLUtils.createSAXSource(new InputSource(new StringReader(entryStr))));
            entryID = entry.getResourceOffering().getEntryID();
            if ((entryID == null) || (entryID.length() == 0)) {
                entryID = SAMLUtils.generateID();
                entry.getResourceOffering().setEntryID(entryID);
                needStore = true;
            }
            discoEntries.put(entryID, entry);
        } catch (Exception e) {
            // this is to skip this miss configured entry
            // remove it from the store for predictable behavior
            debug.error("DiscoEntryHandlerImplUtils.getUserDiscoEntries: wrong " + "format for entry. Removing it from store: " + entryStr);
            needStore = true;
            continue;
        }
    }
    return needStore;
}
Also used : InputSource(org.xml.sax.InputSource) HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) StringReader(java.io.StringReader) DiscoEntryElement(com.sun.identity.liberty.ws.disco.plugins.jaxb.DiscoEntryElement) JAXBException(javax.xml.bind.JAXBException)

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