/** * Method to be called to validate the entry before any of the get/put/ remove methods are called. * * @throws AMException if the entry does not exist in the DS */ private void validateEntry(SSOToken token, CacheBlock cb) throws AMException { if (!cb.hasExpiredAndUpdated() && !cb.isExists()) { // Entry does not exist in DS, invalid entry String params[] = {cb.getEntryDN()}; boolean isPresent = super.doesEntryExists(token, params[0]); if (getDebug().messageEnabled()) { getDebug() .message( "CachedRemoteServicesImpl.validateEntry():" + " DN" + params[0] + " got from DS & exists: " + isPresent); } if (isPresent) { // Intialize the CacheBlock based on isPresent // else throw '461' exception/error message. // This is for certain containers created dynamically. // eg. ou=agents,ou=container,ou=agents. String dn = MiscUtils.formatToRFC(params[0]); cb = new CacheBlock(params[0], isPresent); sdkCache.put(dn, cb); } else { String locale = MiscUtils.getUserLocale(token); throw new AMException(AMSDKBundle.getString("461", params, locale), "461", params); } } }
/** * Gets the type of the object given its DN. * * @param token token a valid SSOToken * @param dn DN of the object whose type is to be known. * @throws AMException if the data store is unavailable or if the objecttype is unknown * @throws SSOException if ssoToken is invalid or expired. */ public int getObjectType(SSOToken token, String dn) throws AMException, SSOException { int objectType = AMObject.UNDETERMINED_OBJECT_TYPE; String entryDN = MiscUtils.formatToRFC(dn); CacheBlock cb = (CacheBlock) sdkCache.get(entryDN); if (cb != null) { // Check if the entry exists, if not present throw an exception if (!doesEntryExists(token, dn)) { String locale = MiscUtils.getUserLocale(token); String params[] = {cb.getEntryDN()}; throw new AMException(AMSDKBundle.getString("461", params, locale), "461", params); } validateEntry(token, cb); objectType = cb.getObjectType(); if (objectType != AMObject.UNDETERMINED_OBJECT_TYPE) { return objectType; } } // Use admintoken to get object type, so that it can be cached SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance()); // The method below will throw an AMException if the entry does not // exist in the directory. If it exists, then create a cache entry for // this DN if (cb == null) { objectType = super.getObjectType(adminToken, entryDN); cb = new CacheBlock(entryDN, true); sdkCache.put(entryDN, cb); } else { objectType = super.getObjectType( adminToken, entryDN, cb.getAttributes(MiscUtils.getPrincipalDN(adminToken), false)); } cb.setObjectType(objectType); if (objectType == AMObject.ORGANIZATION || objectType == AMObject.ORGANIZATIONAL_UNIT) { cb.setOrganizationDN(entryDN); } return objectType; }