Search in sources :

Example 6 with AMEntity

use of com.iplanet.am.sdk.AMEntity in project OpenAM by OpenRock.

the class AMClientCapData method modifyClient.

/**
     * Modify the properties of the Client instance in externalDB. Valid only
     * with instance of externalDB. <br>
     * <b>Note: To add a property in the external db to mask the corresponding
     * property value in internal db, add the property with a " "
     * ("&lt;space&gt;") not an empty "" string. This is required because, when
     * dsame fetches the value from directory and sees it has no value, it
     * returns an empty set. (And we discard empty sets internally - bcos dsame
     * stores values for every property defined in the schema).</b>
     * 
     * Also, if the additionalProperties are being modified, it should contain
     * both the modified and the unmodified ones. This is required since all the
     * additionalProperties are stored in a single Attribute
     * "additionalProperties".
     * 
     * @param token
     *            SSOToken to validate the user.
     * @param props
     *            Map of profiles known to ClientCapabilities. The Map contains
     *            key of property name(s) and Set for the values. It wont
     *            overwrite the property names not in the Map. A key with an
     *            empty Set for the values will delete the property (DSAME
     *            cannot handle null values - throws NullPointerExcptn). The Map
     *            "must" have a property "clientType"
     * 
     * @return 0 on success
     * @exception AMClientCapException
     *                if Client could not be modified - permission problems OR
     *                if the clientType property is mising in the Map.
     */
public int modifyClient(SSOToken token, Map props) throws AMClientCapException {
    int status = 0;
    if (isInternalInstance()) {
        throw new AMClientCapException(BUNDLE_NAME, CANNOT_MOD_INT_DB, null);
    }
    String ct = getClientType(props);
    try {
        AMStoreConnection localConn = new AMStoreConnection(token);
        String dn = generateClientDN(ct);
        AMEntity amEntity = localConn.getEntity(dn);
        if (amEntity.isExists()) {
            Map m = getKnownProperties(props);
            // modify shouldn't have the RDN
            m.remove(CLIENTTYPE_ATTR);
            amEntity.setAttributes(m);
            amEntity.store();
        } else {
            //
            // Need to add if the entry doesn't exist
            //
            status = addClient(token, props);
        }
    } catch (Exception e) {
        String[] errArgs = { ct };
        AMClientCapException ace = new AMClientCapException(BUNDLE_NAME, MODIFY_FAILED, errArgs);
        String msg = ace.getMessage();
        debug.error(dbStr + msg, e);
        throw ace;
    }
    return status;
}
Also used : AMEntity(com.iplanet.am.sdk.AMEntity) AMStoreConnection(com.iplanet.am.sdk.AMStoreConnection) HashMap(java.util.HashMap) Map(java.util.Map) SSOException(com.iplanet.sso.SSOException)

Example 7 with AMEntity

use of com.iplanet.am.sdk.AMEntity in project OpenAM by OpenRock.

the class EntityObjectImpl method modifyEntity.

/**
     * Sets or replaces attribute values with the new values supplied and Stores
     * the changes to directory server.
     * 
     * @param ssoToken User's Single Sign Token.
     * @param entityName Name of this entity. example
     *        <code>cn=websphereAgent</code>
     * @param entityType Type of entity being created. eg. Agent The types
     *        supported by SDK are configured in the list of Managed Objects
     *        in the <code>DAI</code> service.
     * @param entityLocation Location of the entity creation. example 
     *        <code>www.abc.com</code>.
     * @throws EntityException if there is an internal error in the AM Store.
     * @throws SSOException if the sign on is no longer valid.
     * @throws RemoteException
     */
public void modifyEntity(String ssoToken, String entityName, String entityType, String entityLocation, Map attributes) throws EntityException, SSOException, RemoteException {
    initializeObject(ssoToken, entityLocation);
    AMEntity amEntity = getAMEntity(ssoToken, entityName, entityType, entityLocation);
    try {
        if (amEntity != null) {
            amEntity.setAttributes(attributes);
            amEntity.store();
        }
    } catch (AMException amex) {
        EntityUtils.debug.error("EntityObjectImpl.modifyEntity() : " + "Modify Entity Failed. " + amex);
        throw EntityUtils.convertException(amex);
    }
}
Also used : AMEntity(com.iplanet.am.sdk.AMEntity) AMException(com.iplanet.am.sdk.AMException)

Aggregations

AMEntity (com.iplanet.am.sdk.AMEntity)7 SSOException (com.iplanet.sso.SSOException)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AMStoreConnection (com.iplanet.am.sdk.AMStoreConnection)2 AMException (com.iplanet.am.sdk.AMException)1