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);
}
}
}
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>
* <!-- EventNotification element specifes the change notification
* which contains AttributeValuePairs. The attributes defined
* are "method", "entityName", "
* eventType" and "attrNames". -->
* <!ELEMENT EventNotification ( AttributeValuePairs )* >
*
* <!-- AttributeValuePair element contains attribute name and
* values -->
* <!ELEMENT AttributeValuPair ( Attribute, Value*) >
*
* <!-- Attribute contains the attribute names, and the allowed
* names are "method", "entityName",
* "eventType" and "attrNames" -->
* <!ELEMENT Attribute EMPTY>
* <!ATTRLIST Attribute
* name ( method | entityName | eventType | attrNames )
* "method"
* >
*
* <!-- Value element specifies the values for the attributes
* --> <!ELEMENT Value (#PCDATA) >
* </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);
}
}
}
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();
}
}
}
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;
}
}
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);
}
}
Aggregations