OpenDJPersistentStore.java revision e70418658b6daa84fc8a1f13677d2cb616a66725
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012 ForgeRock AS Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
*
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Portions Copyrighted [2010-2012] [ForgeRock AS]
*
*/
/**
* Provide Implementation of AMSessionRepository using the internal
* Configuration Directory as OpenAM's Session and Token Store.
* <p/>
* Having a replicated Directory
*
* @author steve
* @author jeff.schenk@forgerock.com
*/
/**
* Debug Logging
*/
/**
* Service Globals
*/
private boolean shutdown = false;
private Thread storeThread;
/**
* Grace Period
*/
/**
* Configuration Aspect Definitions
*/
private static boolean caseSensitiveUUID =
/**
* Internal LDAP Connection.
*/
private boolean icConnAvailable = false;
private static InternalClientConnection icConn;
/**
* Directory Constructs
*/
/**
* Search Constructs
*/
/**
* Deferred Operation Queue.
*/
private static ConcurrentLinkedQueue<AMSessionRepositoryDeferredOperation>
/**
* Time period between two successive runs of repository cleanup thread
* which checks and removes expired records
*/
private static long cleanUpValue = 0;
public static final String CLEANUP_RUN_PERIOD =
"com.sun.identity.session.repository.cleanupRunPeriod";
/**
* Time period between two successive runs of DBHealthChecker thread which
* checks for Database availability.
*/
public static final String HEALTH_CHECK_RUN_PERIOD =
"com.sun.identity.session.repository.healthCheckRunPeriod";
/**
* This period is actual one that is used by the thread. The value is set to
* the smallest value of cleanUPPeriod and healthCheckPeriod.
*/
/**
* Initialize all Timing Periods.
*/
static {
try {
} catch (Exception e) {
+ ", using default");
}
try {
} catch (Exception e) {
+ ", using default");
}
try {
} catch (Exception e) {
+ ", using default");
}
}
/**
* Initialize Singleton Service Implementation
*/
static {
initialize();
}
/**
* Perform Initialization
*/
private static void initialize() {
// Initialize this Service
Log.logger.log(Level.INFO, "Initializing Configuration for the OpenAM Session Repository using Implementation Class: " +
// Create and Initialize all Necessary Attribute Linked Sets.
// Finish Initialization
Log.logger.log(Level.INFO, "Successful Configuration Initialization for the OpenAM Session Repository using Implementation Class: " +
}
/**
* OpenDJ Persistent Store Constructor
* Bootstrap this Service Implementation.
*
* @throws StoreException
*/
@SuppressWarnings("CallToThreadStartDuringObjectConstruction")
public OpenDJPersistentStore()
throws StoreException {
// Set up Shutdown Thread Hook.
public void run() {
}
});
// Obtain our Directory Connection.
// This needs to come from a connection pool.
try {
String sfhaDN = SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN, Constants.DEFAULT_SESSION_HA_ROOT_DN);
Log.logger.log(Level.INFO, "Search for base container: "+sfhaDN+", yielded Result Code: " + results.getResultCode().toString() + "]");
icConnAvailable = true;
} catch (DirectoryException directoryException) {
icConnAvailable = false;
}
// Start our AM Repository Store Thread.
storeThread = new Thread(this);
storeThread.start();
}
/**
* Service Thread Run Process Loop.
*/
@SuppressWarnings("SleepWhileInLoop")
public void run() {
while (!shutdown) {
try {
// Process any Deferred Operations
} catch (InterruptedException ie) {
} catch (StoreException se) {
}
}
}
/**
* Service Method
* @param obj
* @return
*/
return false;
}
/**
* Service Method
* @param obj
* @return
*/
return false;
}
/**
* Servie Method
* @return
*/
public boolean isEmpty() {
return true;
}
/**
* Saves session state to the repository If it is a new session (version ==
* 0) it inserts new record(s) to the repository. For an existing session it
* updates repository record instead while checking that versions in the
* InternalSession and in the record match In case of version mismatch or
* missing record IllegalArgumentException will be thrown
*
* @param is reference to <code>InternalSession</code> object being saved.
* @throws Exception if anything goes wrong.
*/
}
try {
//if (debug.messageEnabled()) {
//}
// Persist Session Record
} catch (Exception e) {
+ "to save Session", e);
}
}
/**
* Takes an AMRecord and writes this to the store
*
* @param amRootEntity The record object to store
* @throws com.iplanet.dpro.session.exceptions.StoreException
*
*/
}
/**
* Takes an AMRecord and writes this to the store
*
* @param record The record object to store
* @throws com.iplanet.dpro.session.exceptions.StoreException
*
*/
throws StoreException {
boolean found = false;
// TODO -- Remove me after testing
Log.logger.log(Level.INFO,"OpenDJPersistence.writeImmediate:\nBaseDN:[" + baseDN.toString() + "] " +
try {
if (!icConnAvailable)
found = true;
} else {
}
} catch (DirectoryException dex) {
}
if (found) {
} else {
}
}
throws StoreException {
dn.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
if (!icConnAvailable)
// TODO -- Remove me after testing
} else {
}
}
throws StoreException {
dn.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
if (!icConnAvailable)
// TODO -- Remove me after testing
} else {
}
}
throws StoreException {
}
return mods;
}
/**
* Deletes a record from the store.
*
* @param id The id of the record to delete from the store
* @throws com.iplanet.dpro.session.exceptions.StoreException
*
* @throws com.iplanet.dpro.session.exceptions.NotFoundException
*
*/
}
/**
* Deletes session record from the repository.
*
* @param sid session ID.
* @throws Exception if anything goes wrong.
*/
}
}
throws StoreException, NotFoundException {
dn.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
if (!icConnAvailable)
}
}
public void deleteExpired() throws Exception {
}
public void deleteExpired(long expDate)
throws StoreException {
try {
if (!icConnAvailable)
if (!searchResult.isEmpty()) {
try {
deleteImmediate(v);
} catch (NotFoundException nfe) {
}
}
}
}
}
final LocalizableMessage message = DB_ENT_NOT_P.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
} else {
final LocalizableMessage message = DB_ENT_ACC_FAIL.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN), resultCode.toString());
}
} catch (DirectoryException dex) {
final LocalizableMessage message = DB_ENT_ACC_FAIL2.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
if (!shutdown) {
} else {
}
}
}
/**
* Read the Persisted Session Record from the Store.
*
* @param id The primary key of the record to find
* @return
* @throws NotFoundException
* @throws StoreException
*/
throws NotFoundException, StoreException {
{ return null; }
try {
baseDN.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
// TODO -- Remove me after testing
if (!icConnAvailable)
// TODO -- Remove me after testing
if (!searchResult.isEmpty()) {
AMRecordDataEntry dataEntry = new AMRecordDataEntry("pkey=" + id + "," + baseDN, AMRecord.READ, results);
return dataEntry.getAMRecord();
} else {
return null;
}
return null;
} else {
}
} catch (DirectoryException dex) {
}
}
/**
* Read with Security Key.
*
* @param id The secondary key on which to search the store
* @return
* @throws StoreException
* @throws NotFoundException
*/
throws StoreException, NotFoundException {
try {
baseDN.append(Constants.BASE_DN).append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
// TODO -- Remove me after testing
debug.error("OpenDJPersistence.readWithSecKey: Attempting Read of BaseDN:[" + baseDN.toString()+"]");
if (!icConnAvailable)
// TODO -- Remove me after testing
if (!searchResult.isEmpty()) {
}
}
}
return result;
} else {
return null;
}
final LocalizableMessage message = DB_ENT_NOT_P.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
return null;
} else {
final LocalizableMessage message = DB_ENT_ACC_FAIL.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN), resultCode.toString());
}
} catch (DirectoryException dex) {
final LocalizableMessage message = DB_ENT_ACC_FAIL2.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
}
}
/**
* Get Record Counts
*
* @param id
* @return
* @throws StoreException
*/
throws StoreException {
try {
baseDN.append(Constants.BASE_DN).append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
if (!icConnAvailable)
if (!searchResult.isEmpty()) {
key = v;
}
}
}
}
}
return result;
} else {
return null;
}
final LocalizableMessage message = DB_ENT_NOT_P.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
return null;
} else {
final LocalizableMessage message = DB_ENT_ACC_FAIL.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN), resultCode.toString());
}
} catch (DirectoryException dex) {
final LocalizableMessage message = DB_ENT_ACC_FAIL2.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
}
}
/**
* Perform Service Shutdown.
*/
public void shutdown() {
}
/**
* Internal Service Shutdown.
*/
protected void internalShutdown() {
shutdown = true;
}
/**
* Get DB Statistics
*
* @return
*/
public DBStatistics getDBStatistics() {
try {
} catch (StoreException se) {
}
return stats;
}
/**
* Helper method to obtain number of Subordinates.
*
* @return
* @throws StoreException
*/
protected int getNumSubordinates()
throws StoreException {
int recordCount = -1;
baseDN.append(Constants.BASE_DN).append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
try {
if (!icConnAvailable)
if (!searchResult.isEmpty()) {
try {
} catch (NumberFormatException nfe) {
}
}
}
}
}
}
final LocalizableMessage message = DB_ENT_NOT_P.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
} else {
final LocalizableMessage message = DB_ENT_ACC_FAIL.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN), resultCode.toString());
}
} catch (DirectoryException dex) {
final LocalizableMessage message = DB_ENT_ACC_FAIL2.get(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
}
return recordCount;
}
/**
* Retrieve a persisted Internal Session.
*
* @param sid session ID
* @return
* @throws Exception
*/
try {
if ( (amRootEntity != null) &&
{
}
// Return Internal Session.
return is;
} catch (Exception e) {
+ "session", e);
return null;
}
}
/**
* Returns the expiration information of all sessions belonging to a user.
* The returned value will be a Map (sid->expiration_time).
*
* @param uuid
* User's universal unique ID.
* @return Map of all Session for the user
* @throws Exception
* if there is any problem with accessing the session
* repository.
*/
try {
}
return sessions;
} catch (Exception e) {
throw new SessionException(e);
}
}
/**
* Return Service Run Period.
*
* @return long current run period.
*/
public long getRunPeriod() {
return runPeriod;
}
/**
* Obtain a List of Configured Servers
*
* @return Set<AMSessionDBOpenDJServer>
* @throws StoreException
*/
throws StoreException {
baseDn.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
try {
if (!icConnAvailable)
if (!searchResult.isEmpty()) {
} else {
}
}
}
}
return null;
} else {
}
} catch (DirectoryException dex) {
}
return serverList;
}
/**
* Private Helper Method to Obtain a DN from a Host URL.
* @param urlHost
* @return
*/
try {
} catch (MalformedURLException mue) {
return urlHost;
}
}
/**
* Process any and all deferred AM Session Repository Operations.
*/
private synchronized void processDeferredAMSessionRepositoryOperations() {
int count = 0;
count++;
// TODO -- Build out Implementation to invoke Session Repository Events.
// Place Entry in Collection to be removed from Queue.
}
if (count > 0)
}
}