OpenDJPersistentStore.java revision 94ab7a4a8fa00e44d9fe93df2c2a77c134a8e31c
/**
* 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 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
debug.message("Initializing Configuration for the OpenAM Session Repository using Implementation Class: " +
// Create and Initialize all Necessary Attribute Linked Sets.
// Finish Initialization
debug.message("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 {
public void run() {
}
});
// Obtain our Directory Connection.
// This needs to come from a connection pool.
try {
debug.warning("Search for base container yielded Result Code: "+results.getResultCode().toString()+"]");
} catch (DirectoryException directoryException) {
// TODO -- Abort further setup.
}
// 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) {
}
}
}
return false;
}
return false;
}
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()) {
}
} 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;
try {
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));
} else {
}
}
throws StoreException {
dn.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
} 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
*
*/
}
throws StoreException, NotFoundException {
dn.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
}
}
public void deleteExpired() throws Exception {
// TODO -- Delete all Expired Sessions.
}
public void deleteExpired(long expDate)
throws StoreException {
try {
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 {
}
}
}
/**
* Deletes session record from the repository.
*
* @param sid session ID.
* @throws Exception if anything goes wrong.
*/
}
// TODO
}
throws NotFoundException, StoreException {
try {
baseDN.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
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) {
}
}
throws StoreException, NotFoundException {
try {
baseDN.append(Constants.BASE_DN).append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
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));
}
}
throws StoreException {
try {
baseDN.append(Constants.BASE_DN).append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
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));
}
}
public void shutdown() {
}
protected void internalShutdown() {
shutdown = true;
try {
//EmbeddedOpenDJ.shutdownServer();
}
}
public DBStatistics getDBStatistics() {
try {
} catch (StoreException se) {
}
return stats;
}
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 (!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 {
}
/*
* ret.put(SESSIONID, message.getString(SESSIONID)); ret.put(DATA,
* message.getString(DATA));
*/
return is;
} catch (Exception e) {
+ "session", e);
return null;
}
}
return null; // TODO
}
public long getRunPeriod() {
return 0; // TODO
}
throws StoreException {
baseDn.append(Constants.COMMA).append(SystemPropertiesManager.get(SYS_PROPERTY_SESSION_HA_REPOSITORY_ROOT_DN));
try {
if (!searchResult.isEmpty()) {
} else {
}
}
}
}
return null;
} else {
}
} catch (DirectoryException dex) {
}
return serverList;
}
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 to Collection to be removed from Queue.
}
}
}