Search in sources :

Example 11 with IDirectoryServices

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

the class AMSDKRepo method assignService.

public void assignService(SSOToken token, IdType type, String name, String serviceName, SchemaType sType, Map attrMap) throws IdRepoException, SSOException {
    if (type.equals(IdType.AGENT) || type.equals(IdType.GROUP)) {
        Object[] args = { this.getClass().getName() };
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICES_NOT_SUPPORTED_FOR_AGENTS_AND_GROUPS, args);
    }
    // Use adminToken if present
    if (adminToken != null) {
        token = adminToken;
    }
    attrMap = new CaseInsensitiveHashMap(attrMap);
    if (type.equals(IdType.USER)) {
        Set OCs = (Set) attrMap.get("objectclass");
        Set attrName = new HashSet(1);
        attrName.add("objectclass");
        Map tmpMap = getAttributes(token, type, name, attrName);
        Set oldOCs = (Set) tmpMap.get("objectclass");
        // Set oldOCs = getAttribute("objectclass");
        OCs = AMCommonUtils.combineOCs(OCs, oldOCs);
        attrMap.put("objectclass", OCs);
        if (sType.equals(SchemaType.USER)) {
            setMixAttributes(token, type, name, attrMap, false);
        } else if (sType.equals(SchemaType.DYNAMIC)) {
            // Map tmpMap = new HashMap();
            // tmpMap.put("objectclass", (Set) attrMap.get("objectclass"));
            setMixAttributes(token, type, name, attrMap, false);
        }
    } else if (type.equals(IdType.ROLE) || type.equals(IdType.FILTEREDROLE) || type.equals(IdType.REALM)) {
        IDirectoryServices dsServices = AMDirectoryAccessFactory.getDirectoryServices();
        try {
            AMStoreConnection amsc = (sc == null) ? new AMStoreConnection(token) : sc;
            AMOrganization amOrg = amsc.getOrganization(orgDN);
            // Check if service is already assigned
            Set assndSvcs = amOrg.getRegisteredServiceNames();
            if (!assndSvcs.contains(serviceName)) {
                amOrg.registerService(serviceName, false, false);
            }
        } catch (AMException ame) {
            if (ame.getErrorCode().equals("464")) {
            // do nothing. Definition already exists. That's OK.
            } else {
                throw IdUtils.convertAMException(ame);
            }
        }
        String dn = getDN(type, name);
        try {
            // Remove OCs. Those are needed only when setting service
            // for users, not roles.
            attrMap.remove("objectclass");
            int priority = type.equals(IdType.REALM) ? 3 : 0;
            Set values = (Set) attrMap.remove("cospriority");
            if ((values != null) && (!values.isEmpty())) {
                try {
                    priority = Integer.parseInt((String) values.iterator().next());
                } catch (NumberFormatException ex) {
                    if (debug.warningEnabled()) {
                        debug.warning("AMSDKRepo.assignService:", ex);
                    }
                }
            }
            dsServices.createAMTemplate(token, dn, getProfileType(type), serviceName, attrMap, priority);
        } catch (AMException ame) {
            debug.error("AMSDKRepo.assignService: Caught AMException", ame);
            throw IdUtils.convertAMException(ame);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) HashSet(java.util.HashSet)

Example 12 with IDirectoryServices

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

the class EventListener method sendNotification.

/**
     * Sends notifications to listeners added via <code>addListener</code>.
     * The parameter <code>nItem</code> is an XML document having a single
     * notification event, using the following DTD.
     * <p>
     * 
     * <pre>
     *       &lt;!-- EventNotification element specifes the change notification
     *       which contains AttributeValuePairs. The attributes defined
     *       are &quot;method&quot;, &quot;entityName&quot;, &quot;
     *       eventType&quot; and &quot;attrNames&quot;. --&gt;
     *       &lt;!ELEMENT EventNotification ( AttributeValuePairs )* &gt;
     *  
     *       &lt;!-- AttributeValuePair element contains attribute name and 
     *       values --&gt;
     *       &lt;!ELEMENT AttributeValuPair ( Attribute, Value*) &gt;
     *  
     *       &lt;!-- Attribute contains the attribute names, and the allowed 
     *       names are &quot;method&quot;, &quot;entityName&quot;, 
     *       &quot;eventType&quot; and &quot;attrNames&quot; --&gt;
     *       &lt;!ELEMENT Attribute EMPTY&gt;
     *       &lt;!ATTRLIST Attribute
     *       name ( method | entityName | eventType | attrNames ) 
     *       &quot;method&quot;
     *       &gt;
     *  
     *       &lt;!-- Value element specifies the values for the attributes 
     *       --&gt; &lt;!ELEMENT Value (#PCDATA) &gt;
     * </pre>
     * 
     * @param nItem
     *            notification event as a xml document
     * 
     */
static void sendNotification(String nItem) {
    if (debug.messageEnabled()) {
        debug.message("EventListener::sendNotification: " + "Received notification.");
    }
    // Construct the XML document
    StringBuilder sb = new StringBuilder(nItem.length() + 50);
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(nItem);
    try {
        Map attrs = CreateServiceConfig.getAttributeValuePairs(SMSSchema.getXMLDocument(sb.toString(), false).getDocumentElement());
        if (debug.messageEnabled()) {
            debug.message("EventListener::sendNotification " + "Decoded Event: " + attrs);
        }
        // Get method name
        String method = getAttributeValue(attrs, METHOD);
        if (method == null) {
            handleError("invalid method name: " + attrs.get(METHOD));
        }
        // Get entity name
        String entityName = getAttributeValue(attrs, ENTITY_NAME);
        if (entityName == null) {
            handleError("invalid entity Name: " + attrs.get(ENTITY_NAME));
        }
        String entryDN = LDAPUtils.formatToRFC(entityName);
        IDirectoryServices dsServices = RemoteServicesFactory.getInstance();
        // Switch based on method
        if (method.equalsIgnoreCase(OBJECT_CHANGED)) {
            int eventType = getEventType((Set) attrs.get(EVENT_TYPE));
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).dirtyCache(entryDN, eventType, false, false, Collections.EMPTY_SET);
            }
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.objectChanged(entityName, eventType, null);
                }
            }
        } else if (method.equalsIgnoreCase(OBJECTS_CHANGED)) {
            int eventType = getEventType((Set) attrs.get(EVENT_TYPE));
            Set attributes = (Set) attrs.get(attrs.get(ATTR_NAMES));
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).dirtyCache(entryDN, eventType, true, false, attributes);
            }
            // Call objectsChanged method on the listeners
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.objectsChanged(entityName, eventType, attributes, null);
                }
            }
        } else if (method.equalsIgnoreCase(PERMISSIONS_CHANGED)) {
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).dirtyCache(entryDN, AMEvent.OBJECT_CHANGED, false, true, Collections.EMPTY_SET);
            }
            // Call permissionChanged method on the listeners
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.permissionsChanged(entityName, null);
                }
            }
        } else if (method.equalsIgnoreCase(ALL_OBJECTS_CHANGED)) {
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).clearCache();
            }
            // Call allObjectsChanged method on listeners
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.allObjectsChanged();
                }
            }
        } else {
            // Invalid method name
            handleError("invalid method name: " + method);
        }
        if (debug.messageEnabled()) {
            debug.message("EventListener::sendNotification: Sent " + "notification.");
        }
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("EventListener::sendNotification: Unable to send" + " notification: " + nItem, e);
        }
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) HashSet(java.util.HashSet) Set(java.util.Set) AMObjectListener(com.iplanet.am.sdk.AMObjectListener) Iterator(java.util.Iterator) ICachedDirectoryServices(com.iplanet.am.sdk.common.ICachedDirectoryServices) Map(java.util.Map) AMEventManagerException(com.iplanet.am.sdk.AMEventManagerException) SSOException(com.iplanet.sso.SSOException)

Example 13 with IDirectoryServices

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

the class EntryEventListener method allEntriesChanged.

public void allEntriesChanged() {
    debug.error("EntryEventListener: Received all entries changed event" + "from event service");
    IDirectoryServices dsServices = DirectoryServicesFactory.getInstance();
    if (DirectoryServicesFactory.isCachingEnabled()) {
        ((ICachedDirectoryServices) dsServices).clearCache();
    }
    // Call the listeners
    synchronized (listeners) {
        Set keys = listeners.keySet();
        for (Iterator items = keys.iterator(); items.hasNext(); ) {
            AMObjectListener listener = (AMObjectListener) items.next();
            listener.allObjectsChanged();
        }
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) Set(java.util.Set) AMObjectListener(com.iplanet.am.sdk.AMObjectListener) Iterator(java.util.Iterator) ICachedDirectoryServices(com.iplanet.am.sdk.common.ICachedDirectoryServices)

Example 14 with IDirectoryServices

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

the class AMNamingAttrManager method getNamingAttr.

/**
     * Gets the naming attribute after reading it from the corresponding
     * creation template. If not found, a default value will be used
     */
public static String getNamingAttr(int objectType, String orgDN) {
    String cacheKey = (new Integer(objectType)).toString() + ":" + DN.valueOf(orgDN).toString().toLowerCase();
    if (namingAttrMap.containsKey(cacheKey)) {
        return ((String) namingAttrMap.get(cacheKey));
    } else {
        IDirectoryServices dsServices = AMDirectoryAccessFactory.getDirectoryServices();
        String nAttr = dsServices.getNamingAttribute(objectType, orgDN);
        if (nAttr != null) {
            namingAttrMap.put(cacheKey, nAttr);
        }
        return nAttr;
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices)

Example 15 with IDirectoryServices

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

the class AMSDKRepo method setBinaryAttributes.

public void setBinaryAttributes(SSOToken token, IdType type, String name, Map attributes, boolean isAdd) throws IdRepoException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("AMSDKRepo: setBinaryAttributes called" + type + ": " + name + ": " + attributes);
    }
    if (attributes == null || attributes.isEmpty()) {
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.ILLEGAL_ARGUMENTS, null);
    }
    String dn = getDN(type, name);
    int profileType = getProfileType(type);
    try {
        if (adminToken != null) {
            token = adminToken;
        }
        IDirectoryServices dsServices = AMDirectoryAccessFactory.getDirectoryServices();
        dsServices.setAttributes(token, dn, profileType, new AMHashMap(false), attributes, false);
    } catch (AMException ame) {
        debug.error("AMSDKRepo.setBinaryAttributes: Unable to set attributes", ame);
        throw IdUtils.convertAMException(ame);
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) IdRepoException(com.sun.identity.idm.IdRepoException)

Aggregations

IDirectoryServices (com.iplanet.am.sdk.common.IDirectoryServices)15 IdRepoException (com.sun.identity.idm.IdRepoException)6 Set (java.util.Set)6 Iterator (java.util.Iterator)5 AMObjectListener (com.iplanet.am.sdk.AMObjectListener)4 ICachedDirectoryServices (com.iplanet.am.sdk.common.ICachedDirectoryServices)4 Map (java.util.Map)4 SSOException (com.iplanet.sso.SSOException)3 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)2 IdRepoFatalException (com.sun.identity.idm.IdRepoFatalException)2 SMSException (com.sun.identity.sm.SMSException)2 DN (org.forgerock.opendj.ldap.DN)2 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)1 AMException (com.iplanet.am.sdk.AMException)1 AMObject (com.iplanet.am.sdk.AMObject)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1