Search in sources :

Example 1 with DiscoveryException

use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.

the class LibertyManagerClient method getDiscoveryResourceOffering.

/**
     * Returns the discovery service bootstrap resource offering. 
     * @param token Single Sign On Token.
     * @param hostProviderID Hosted <code>ProviderID</code>.
     * @return <code>ResourceOffering</code> Discovery Service bootstrap
     *  resource offering.
     * @exception FSException if any failure.
     */
public ResourceOffering getDiscoveryResourceOffering(Object token, String hostProviderID) throws FSException {
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        String tokenID = sessionProvider.getSessionID(token);
        String cacheKey = tokenID + DISCO_RO;
        ResourceOffering ro = (ResourceOffering) bootStrapCache.get(cacheKey);
        if (ro != null) {
            return ro;
        }
        String[] objs = { tokenID, hostProviderID };
        String resourceOffering = (String) client.send("getDiscoveryResourceOffering", objs, null, null);
        if ((resourceOffering == null) || (resourceOffering.length() == 0)) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: ResouceOffering is null or empty");
            }
            return null;
        }
        Document doc = XMLUtils.toDOMDocument(resourceOffering, FSUtils.debug);
        ro = new ResourceOffering(doc.getDocumentElement());
        sessionProvider.addListener(token, new LibertyClientSSOTokenListener());
        bootStrapCache.put(cacheKey, ro);
        return ro;
    } catch (SessionException se) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ResourceOffering: InvalidSessionToken", se);
        }
        throw new FSException(FSUtils.bundle.getString("invalidSSOToken"));
    } catch (DiscoveryException de) {
        FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: Invalid ResourceOffering", de);
        throw new FSException(FSUtils.bundle.getString("invalidResourceOffering"));
    } catch (Exception ex) {
        FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: SOAPClient Exception", ex);
        throw new FSException(FSUtils.bundle.getString("soapException"));
    }
}
Also used : ResourceOffering(com.sun.identity.liberty.ws.disco.ResourceOffering) FSException(com.sun.identity.federation.common.FSException) SessionException(com.sun.identity.plugin.session.SessionException) Document(org.w3c.dom.Document) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException) SessionException(com.sun.identity.plugin.session.SessionException) FSException(com.sun.identity.federation.common.FSException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 2 with DiscoveryException

use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.

the class GlobalDiscoEntryHandler method modifyDiscoEntries.

/**
     * Modify DiscoEntries for the default organization.
     * @param userID This is not used in this implementation.
     *
     * @param removes List of
     *          com.sun.identity.liberty.ws.disco.jaxb.RemoveEntryType jaxb
     *          objects.
     * @param inserts List of
     *          com.sun.identity.liberty.ws.disco.jaxb.InsertEntryType jaxb
     *          objects.
     * @return Map which contains the following key value pairs:
     *          Key: <code>DiscoEntryHandler.STATUS_CODE</code>
     *          Value: status code String such as "OK", "Failed", etc.
     *          Key: <code>DiscoEntryHandler.NEW_ENTRY_IDS</code>
     *          Value: List of entryIds for the entries that were added.
     *          The second key/value pair will only exist when status code is
     *          "OK", and there are InsertEntry elements in the Modify request.
     *          When successful, all modification (removes and inserts) should
     *          be done. No partial changes should be done.
     */
public Map modifyDiscoEntries(String userID, List removes, List inserts) {
    if (DiscoUtils.debug.messageEnabled()) {
        DiscoUtils.debug.message("GlobalDiscoEntryHandler.modifyDisco" + "Entries: init ");
    }
    Map result = new HashMap();
    result.put(STATUS_CODE, DiscoConstants.STATUS_FAILED);
    Map discoEntries = new HashMap();
    try {
        // Try to register discovery service if not already registered
        registerDiscoveryService();
        AMIdentity amId = getRealmIdentity();
        DiscoEntryHandlerImplUtils.getGlobalDiscoEntries(getRealmIdentity(), DYNAMIC_ATTR_NAME, discoEntries, userID);
        if ((removes != null) && (removes.size() != 0)) {
            if (!DiscoEntryHandlerImplUtils.handleRemoves(discoEntries, removes)) {
                return result;
            }
        }
        Set entries = new HashSet();
        entries.addAll(discoEntries.values());
        List newEntryIDs = null;
        if ((inserts != null) && (inserts.size() != 0)) {
            Map insertResults = DiscoEntryHandlerImplUtils.handleInserts(entries, inserts);
            if (!((String) insertResults.get(STATUS_CODE)).equals(DiscoConstants.STATUS_OK)) {
                return result;
            }
            newEntryIDs = (List) insertResults.get(NEW_ENTRY_IDS);
        }
        if (!DiscoEntryHandlerImplUtils.setGlobalDiscoEntries(amId, DYNAMIC_ATTR_NAME, entries)) {
            return result;
        } else {
            result.put(STATUS_CODE, DiscoConstants.STATUS_OK);
            if ((newEntryIDs != null) && (newEntryIDs.size() != 0)) {
                result.put(NEW_ENTRY_IDS, newEntryIDs);
            }
            return result;
        }
    } catch (DiscoveryException de) {
        DiscoUtils.debug.error("GlobalDiscoEntryHandler.modify" + "DiscoEntries: Exception", de);
        return result;
    } catch (Exception ex) {
        DiscoUtils.debug.error("GlobalDiscoEntryHandler.modify" + "DiscoEntries: Exception", ex);
        return result;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AMIdentity(com.sun.identity.idm.AMIdentity) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet)

Example 3 with DiscoveryException

use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.

the class GlobalDiscoEntryHandler method getRealmIdentity.

/**
     * Returns the default realm identity object.
     */
private static synchronized AMIdentity getRealmIdentity() throws DiscoveryException {
    try {
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        AMIdentityRepository idRepo = new AMIdentityRepository(adminToken, "/");
        return idRepo.getRealmIdentity();
    } catch (IdRepoException ire) {
        DiscoUtils.debug.error("GlobalDiscoEntryHandler.getRealm" + "Identity: Initialization failed", ire);
        throw new DiscoveryException(ire.getMessage());
    } catch (SSOException se) {
        DiscoUtils.debug.error("GlobalDiscoEntryHandler.getRealm" + "Identity: SSOException ", se);
        throw new DiscoveryException(se.getMessage());
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException)

Example 4 with DiscoveryException

use of com.sun.identity.liberty.ws.disco.DiscoveryException in project OpenAM by OpenRock.

the class GlobalDiscoEntryHandler method registerDiscoveryService.

/**
     * This method registers the Discovery Service to the root realm if
     * the service is not already registered.
     */
private static void registerDiscoveryService() throws DiscoveryException {
    try {
        AMIdentity amId = getRealmIdentity();
        Set assignedServices = amId.getAssignedServices();
        if (assignedServices != null && assignedServices.contains(DISCO_SERVICE)) {
            return;
        }
        amId.assignService(DISCO_SERVICE, null);
    } catch (IdRepoException ire) {
        DiscoUtils.debug.error("GlobalDiscoEntryHandler.register" + "DiscoveryService: Exception", ire);
        throw new DiscoveryException(ire.getMessage());
    } catch (SSOException se) {
        DiscoUtils.debug.error("GlobalDiscoEntryHandler.register" + "DiscoveryService: Exception", se);
        throw new DiscoveryException(se.getMessage());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) DiscoveryException(com.sun.identity.liberty.ws.disco.DiscoveryException)

Example 5 with DiscoveryException

use of com.sun.identity.liberty.ws.disco.DiscoveryException 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)

Aggregations

DiscoveryException (com.sun.identity.liberty.ws.disco.DiscoveryException)9 SSOException (com.iplanet.sso.SSOException)3 IdRepoException (com.sun.identity.idm.IdRepoException)3 SessionException (com.sun.identity.plugin.session.SessionException)3 List (java.util.List)3 Document (org.w3c.dom.Document)3 NodeList (org.w3c.dom.NodeList)3 FSException (com.sun.identity.federation.common.FSException)2 AMIdentity (com.sun.identity.idm.AMIdentity)2 ResourceOffering (com.sun.identity.liberty.ws.disco.ResourceOffering)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Element (org.w3c.dom.Element)2 SSOToken (com.iplanet.sso.SSOToken)1 FSSession (com.sun.identity.federation.services.FSSession)1 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)1 Status (com.sun.identity.liberty.ws.common.Status)1 SecurityAssertion (com.sun.identity.liberty.ws.security.SecurityAssertion)1 SessionProvider (com.sun.identity.plugin.session.SessionProvider)1