001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: AMEvent.java,v 1.8 2009/01/28 05:34:47 ww203982 Exp $ 026 * 027 */ 028 029package com.iplanet.am.sdk; 030 031import java.util.EventObject; 032 033import com.sun.identity.shared.ldap.controls.LDAPPersistSearchControl; 034 035import com.iplanet.services.ldap.event.DSEvent; 036 037/** <p>Represents an event fired by Sun Java System Access Manager SDK.</p> 038 * 039 * <p><code>AMEvent</code>'s state consists of the following: 040 * <ul> 041 * <li>The event source: The underlying object that caused the event. 042 * <li>The event source DN: DN of the underlying object that caused the 043 * event. 044 * <li>The event type 045 * <li>The source object type: Type of the underlying object that caused 046 * event. 047 * </ul> 048 * 049 * @deprecated As of Sun Java System Access Manager 7.1. 050 * @supported.all.api 051 */ 052public class AMEvent extends EventObject { 053 054 private static final long serialVersionUID = 6448554078141700417L; 055 056 /** 057 * Represents an object addition event type. 058 */ 059 public static final int OBJECT_ADDED = LDAPPersistSearchControl.ADD; 060 061 /** 062 * Represents an object change event type. 063 */ 064 public static final int OBJECT_CHANGED = LDAPPersistSearchControl.MODIFY; 065 066 /** 067 * Represents an object removal event type. 068 */ 069 public static final int OBJECT_REMOVED = LDAPPersistSearchControl.DELETE; 070 071 /** Represents an object expiration event type. Occurs when the TTL for the 072 * object data is over. */ 073 public static final int OBJECT_EXPIRED = 9; 074 075 /** 076 * Represents an object renaming event type. 077 */ 078 public static final int OBJECT_RENAMED = LDAPPersistSearchControl.MODDN; 079 080 /* The above constants OBJECT_ADDED, OBJECT_CHANGED, OBJECT_REMOVED, 081 OBJECT_RENAMED should be kept in synch with the corresponding 082 constants defined in com.iplanet.services.ldap.event.IDSEventListener 083 084 OBJECT_ADDED=IDSEventListener.CHANGE_ADD 085 OBJECT_CHANGED=IDSEventListener.CHANGE_MODIFY 086 OBJECT_REMOVED=IDSEventListener.CHANGE_DELETE 087 OBJECT_RENAMED=IDSEventListener.CHANGE_MOD_LOCATION 088 */ 089 090 private int eventType; 091 092 private String sourceDN; 093 094 private int sourceType; 095 096 /** 097 * Constructs an event object. 098 * This constructor accepts the event source object and passes it onto the 099 * base class constructor. 100 * 101 * @param source The source object that caused the event. The source object 102 * could be User, Role, Group, Organization, etc., from this 103 * SDK. The source could also be a String 104 * representing the DN (distinguished name) of the source 105 * object. 106 * @param eventType type of event. 107 */ 108 public AMEvent(Object source, int eventType) { 109 super(source); 110 if (source instanceof DSEvent) { 111 DSEvent dsEvent = (DSEvent) source; 112 this.sourceDN = dsEvent.getID(); 113 this.sourceType = determineSourceType(dsEvent); 114 } else if (source instanceof AMEvent) { 115 this.sourceDN = ((AMEvent) source).getSourceDN(); 116 this.sourceType = AMObject.UNKNOWN_OBJECT_TYPE; 117 } else { 118 this.sourceDN = null; 119 this.sourceType = AMObject.UNKNOWN_OBJECT_TYPE; 120 } 121 this.eventType = eventType; 122 } 123 124 protected AMEvent(Object source, int eventType, String sourceDN, 125 int sourceType) { 126 super(source); 127 this.eventType = eventType; 128 this.sourceDN = sourceDN; 129 this.sourceType = sourceType; 130 } 131 132 /** 133 * Protected constructor for package use only 134 */ 135 protected AMEvent(String dn) { 136 super(new String("")); 137 this.eventType = OBJECT_CHANGED; 138 sourceDN = dn; 139 } 140 141 /** 142 * Returns the distinguished name of the source object in a String format. 143 * Use this method if no searching or parsing operations need to be 144 * performed on the distinguished name. 145 * 146 * @return distinguished name of the source object. 147 */ 148 public String getSourceDN() { 149 return sourceDN; 150 } 151 152 /** 153 * Returns the type of the event. 154 * 155 * @return Returns one of the 156 * following possible values: 157 * <ul> 158 * <li><code>AMEvent.OBJECT_ADDED</code> 159 * <li><code>AMEvent.OBJECT_CHANGED</code> 160 * <li><code>AMEvent.OBJECT_REMOVED</code> 161 * <li><code>AMEvent.OBJECT_RENAMED</code> 162 * <li><code>AMEvent.OBJECT_EXPIRED</code> </ul> 163 */ 164 public int getEventType() { 165 return eventType; 166 } 167 168 /** 169 * Returns the type of the source object that caused the event. 170 * <p> 171 * @return Returns one of the following possible values: 172 * <ul> 173 * <li> <code>AMObject.USER</code> 174 * <li> <code>AMObject.ROLE</code> 175 * <li> <code>AMObject.FILTERED_ROLE</code> 176 * <li> <code>AMObject.GROUP</code> 177 * <li> <code>AMObject.DYNAMIC_GROUP</code> 178 * <li> <code>AMObject.ASSIGNABLE_DYNAMIC_GROUP</code> 179 * <li> <code>AMObject.ORGANIZATION</code> 180 * <li> <code>AMObject.PEOPLE_CONTAINER</code> 181 * <li> <code>AMObject.GROUP_CONTAINER</code> 182 * <li> <code>AMObject.ORGINATIONAL_UNIT</code> 183 * <li> <code>AMObject.UNKNOWN_OBJECT_TYPE</code> if source unknown 184 * </ul> 185 */ 186 public int getSourceType() { 187 return sourceType; 188 } 189 190 private int determineSourceType(DSEvent source) { 191 // getClassName() returns all the object classes as a comma separated 192 // String 193 if (source == null) { 194 return AMObject.UNKNOWN_OBJECT_TYPE; 195 } 196 197 String objectClasses = source.getClassName().toLowerCase(); 198 if (objectClasses.indexOf(AMObjectClassManager 199 .getObjectClass(AMObject.USER)) != -1) { 200 return AMObject.USER; 201 } else if (objectClasses.indexOf(AMObjectClassManager 202 .getObjectClass(AMObject.ROLE)) != -1) { 203 return AMObject.ROLE; 204 } else if (objectClasses.indexOf(AMObjectClassManager 205 .getObjectClass(AMObject.FILTERED_ROLE)) != -1) { 206 return AMObject.FILTERED_ROLE; 207 } else if (objectClasses.indexOf(AMObjectClassManager 208 .getObjectClass(AMObject.ORGANIZATION)) != -1) { 209 return AMObject.ORGANIZATION; 210 } else if (objectClasses.indexOf(AMObjectClassManager 211 .getObjectClass(AMObject.GROUP)) != -1) { 212 return AMObject.GROUP; 213 } else if (objectClasses.indexOf(AMObjectClassManager 214 .getObjectClass(AMObject.ASSIGNABLE_DYNAMIC_GROUP)) != -1) { 215 return AMObject.ASSIGNABLE_DYNAMIC_GROUP; 216 } else if (objectClasses.indexOf(AMObjectClassManager 217 .getObjectClass(AMObject.DYNAMIC_GROUP)) != -1) { 218 return AMObject.DYNAMIC_GROUP; 219 } else if (objectClasses.indexOf(AMObjectClassManager 220 .getObjectClass(AMObject.PEOPLE_CONTAINER)) != -1) { 221 return AMObject.PEOPLE_CONTAINER; 222 } else if (objectClasses.indexOf(AMObjectClassManager 223 .getObjectClass(AMObject.GROUP_CONTAINER)) != -1) { 224 return AMObject.GROUP_CONTAINER; 225 } else if (objectClasses.indexOf(AMObjectClassManager 226 .getObjectClass(AMObject.ORGANIZATIONAL_UNIT)) != -1) { 227 return AMObject.ORGANIZATIONAL_UNIT; 228 } else if (objectClasses.indexOf(AMObjectClassManager 229 .getObjectClass(AMObject.RESOURCE)) != -1) { 230 return AMObject.RESOURCE; 231 } 232 return AMObject.UNKNOWN_OBJECT_TYPE; 233 } 234}
Copyright © 2010-2017, ForgeRock All Rights Reserved.