summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cms/servlet/csadmin/LDAPSecurityDomainSessionTable.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/servlet/csadmin/LDAPSecurityDomainSessionTable.java')
-rw-r--r--pki/base/common/src/com/netscape/cms/servlet/csadmin/LDAPSecurityDomainSessionTable.java142
1 files changed, 83 insertions, 59 deletions
diff --git a/pki/base/common/src/com/netscape/cms/servlet/csadmin/LDAPSecurityDomainSessionTable.java b/pki/base/common/src/com/netscape/cms/servlet/csadmin/LDAPSecurityDomainSessionTable.java
index da2a3ccb..b7b52129 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/csadmin/LDAPSecurityDomainSessionTable.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/csadmin/LDAPSecurityDomainSessionTable.java
@@ -36,11 +36,11 @@ import com.netscape.certsrv.base.ISecurityDomainSessionTable;
import com.netscape.cmsutil.password.IPasswordStore;
/**
- * This object stores the values for IP, uid and group based on the cookie id in LDAP.
- * Entries are stored under ou=Security Domain, ou=sessions, $basedn
+ * This object stores the values for IP, uid and group based on the cookie id in
+ * LDAP. Entries are stored under ou=Security Domain, ou=sessions, $basedn
*/
-public class LDAPSecurityDomainSessionTable
- implements ISecurityDomainSessionTable {
+public class LDAPSecurityDomainSessionTable implements
+ ISecurityDomainSessionTable {
private long m_timeToLive;
@@ -48,8 +48,7 @@ public class LDAPSecurityDomainSessionTable
m_timeToLive = timeToLive;
}
- public int addEntry(String sessionId, String ip,
- String uid, String group) {
+ public int addEntry(String sessionId, String ip, String uid, String group) {
IConfigStore cs = CMS.getConfigStore();
LDAPConnection conn = null;
boolean sessions_exists = true;
@@ -61,7 +60,8 @@ public class LDAPSecurityDomainSessionTable
basedn = cs.getString("internaldb.basedn");
sessionsdn = "ou=sessions,ou=Security Domain," + basedn;
} catch (Exception e) {
- CMS.debug("SecurityDomainSessionTable: addEntry: failed to read basedn" + e);
+ CMS.debug("SecurityDomainSessionTable: addEntry: failed to read basedn"
+ + e);
return status;
}
@@ -77,14 +77,16 @@ public class LDAPSecurityDomainSessionTable
attrs.add(new LDAPAttribute("ou", "sessions"));
entry = new LDAPEntry(sessionsdn, attrs);
conn.add(entry);
- } catch (Exception e) {
- if ((e instanceof LDAPException) && (((LDAPException) e).getLDAPResultCode() == LDAPException.ENTRY_ALREADY_EXISTS)) {
+ } catch (Exception e) {
+ if ((e instanceof LDAPException)
+ && (((LDAPException) e).getLDAPResultCode() == LDAPException.ENTRY_ALREADY_EXISTS)) {
// continue
} else {
- CMS.debug("SecurityDomainSessionTable: unable to create ou=sessions:" + e);
+ CMS.debug("SecurityDomainSessionTable: unable to create ou=sessions:"
+ + e);
sessions_exists = false;
}
- }
+ }
// add new entry
try {
@@ -93,27 +95,32 @@ public class LDAPSecurityDomainSessionTable
String entrydn = "cn=" + sessionId + "," + sessionsdn;
attrs = new LDAPAttributeSet();
attrs.add(new LDAPAttribute("objectclass", "top"));
- attrs.add(new LDAPAttribute("objectclass", "securityDomainSessionEntry"));
+ attrs.add(new LDAPAttribute("objectclass",
+ "securityDomainSessionEntry"));
attrs.add(new LDAPAttribute("cn", sessionId));
attrs.add(new LDAPAttribute("host", ip));
attrs.add(new LDAPAttribute("uid", uid));
attrs.add(new LDAPAttribute("cmsUserGroup", group));
- attrs.add(new LDAPAttribute("dateOfCreate", Long.toString((new Date()).getTime())));
+ attrs.add(new LDAPAttribute("dateOfCreate", Long
+ .toString((new Date()).getTime())));
entry = new LDAPEntry(entrydn, attrs);
if (sessions_exists) {
conn.add(entry);
- CMS.debug("SecurityDomainSessionTable: added session entry" + sessionId);
+ CMS.debug("SecurityDomainSessionTable: added session entry"
+ + sessionId);
status = SUCCESS;
}
- } catch(Exception e) {
- CMS.debug("SecurityDomainSessionTable: unable to create session entry" + sessionId + ": " + e);
- }
+ } catch (Exception e) {
+ CMS.debug("SecurityDomainSessionTable: unable to create session entry"
+ + sessionId + ": " + e);
+ }
try {
conn.disconnect();
} catch (Exception e) {
- CMS.debug("SecurityDomainSessionTable:addEntry: Error in disconnecting from database: " + e);
+ CMS.debug("SecurityDomainSessionTable:addEntry: Error in disconnecting from database: "
+ + e);
}
return status;
}
@@ -124,21 +131,25 @@ public class LDAPSecurityDomainSessionTable
int status = FAILURE;
try {
String basedn = cs.getString("internaldb.basedn");
- String dn = "cn=" + sessionId + ",ou=sessions,ou=Security Domain," + basedn;
+ String dn = "cn=" + sessionId + ",ou=sessions,ou=Security Domain,"
+ + basedn;
conn = getLDAPConn();
conn.delete(dn);
status = SUCCESS;
} catch (Exception e) {
- if ((e instanceof LDAPException) && (((LDAPException) e).getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT)) {
+ if ((e instanceof LDAPException)
+ && (((LDAPException) e).getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT)) {
// continue
} else {
- CMS.debug("SecurityDomainSessionTable: unable to delete session " + sessionId + ": " + e);
+ CMS.debug("SecurityDomainSessionTable: unable to delete session "
+ + sessionId + ": " + e);
}
}
try {
conn.disconnect();
} catch (Exception e) {
- CMS.debug("SecurityDomainSessionTable: removeEntry: Error in disconnecting from database: " + e);
+ CMS.debug("SecurityDomainSessionTable: removeEntry: Error in disconnecting from database: "
+ + e);
}
return status;
}
@@ -154,21 +165,24 @@ public class LDAPSecurityDomainSessionTable
String[] attrs = { "cn" };
conn = getLDAPConn();
- LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB, filter, attrs, false);
- if (res.getCount() > 0) ret = true;
- } catch(Exception e) {
- CMS.debug("SecurityDomainSessionTable: unable to query session " + sessionId + ": " + e);
+ LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB,
+ filter, attrs, false);
+ if (res.getCount() > 0)
+ ret = true;
+ } catch (Exception e) {
+ CMS.debug("SecurityDomainSessionTable: unable to query session "
+ + sessionId + ": " + e);
}
try {
conn.disconnect();
} catch (Exception e) {
- CMS.debug("SecurityDomainSessionTable: isSessionIdExist: Error in disconnecting from database: " + e);
+ CMS.debug("SecurityDomainSessionTable: isSessionIdExist: Error in disconnecting from database: "
+ + e);
}
return ret;
}
-
public Enumeration getSessionIds() {
IConfigStore cs = CMS.getConfigStore();
LDAPConnection conn = null;
@@ -181,27 +195,31 @@ public class LDAPSecurityDomainSessionTable
String[] attrs = { "cn" };
conn = getLDAPConn();
- LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB, filter, attrs, false);
+ LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB,
+ filter, attrs, false);
while (res.hasMoreElements()) {
LDAPEntry entry = res.next();
ret.add(entry.getAttribute("cn").getStringValueArray()[0]);
}
} catch (LDAPException e) {
switch (e.getLDAPResultCode()) {
- case LDAPException.NO_SUCH_OBJECT:
- CMS.debug("SecurityDomainSessionTable: getSessionIds(): no sessions have been created");
- break;
- default:
- CMS.debug("SecurityDomainSessionTable: unable to query sessionIds due to ldap exception: " + e);
+ case LDAPException.NO_SUCH_OBJECT:
+ CMS.debug("SecurityDomainSessionTable: getSessionIds(): no sessions have been created");
+ break;
+ default:
+ CMS.debug("SecurityDomainSessionTable: unable to query sessionIds due to ldap exception: "
+ + e);
}
- } catch(Exception e) {
- CMS.debug("SecurityDomainSessionTable: unable to query sessionIds: " + e);
+ } catch (Exception e) {
+ CMS.debug("SecurityDomainSessionTable: unable to query sessionIds: "
+ + e);
}
try {
conn.disconnect();
} catch (Exception e) {
- CMS.debug("SecurityDomainSessionTable: getSessionIds: Error in disconnecting from database: " + e);
+ CMS.debug("SecurityDomainSessionTable: getSessionIds: Error in disconnecting from database: "
+ + e);
}
return ret.elements();
@@ -211,25 +229,28 @@ public class LDAPSecurityDomainSessionTable
IConfigStore cs = CMS.getConfigStore();
LDAPConnection conn = null;
String ret = null;
- try {
+ try {
String basedn = cs.getString("internaldb.basedn");
String sessionsdn = "ou=sessions,ou=Security Domain," + basedn;
String filter = "(cn=" + sessionId + ")";
String[] attrs = { attr };
conn = getLDAPConn();
- LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB, filter, attrs, false);
- if (res.getCount() > 0) {
+ LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB,
+ filter, attrs, false);
+ if (res.getCount() > 0) {
LDAPEntry entry = res.next();
ret = entry.getAttribute(attr).getStringValueArray()[0];
}
- } catch(Exception e) {
- CMS.debug("SecurityDomainSessionTable: unable to query session " + sessionId + ": " + e);
+ } catch (Exception e) {
+ CMS.debug("SecurityDomainSessionTable: unable to query session "
+ + sessionId + ": " + e);
}
try {
conn.disconnect();
} catch (Exception e) {
- CMS.debug("SecurityDomainSessionTable: isSessionIdExist: Error in disconnecting from database: " + e);
+ CMS.debug("SecurityDomainSessionTable: isSessionIdExist: Error in disconnecting from database: "
+ + e);
}
return ret;
}
@@ -261,7 +282,7 @@ public class LDAPSecurityDomainSessionTable
public int getSize() {
IConfigStore cs = CMS.getConfigStore();
LDAPConnection conn = null;
- int ret =0;
+ int ret = 0;
try {
String basedn = cs.getString("internaldb.basedn");
@@ -270,24 +291,25 @@ public class LDAPSecurityDomainSessionTable
String[] attrs = { "cn" };
conn = getLDAPConn();
- LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB, filter, attrs, false);
+ LDAPSearchResults res = conn.search(sessionsdn, LDAPv2.SCOPE_SUB,
+ filter, attrs, false);
ret = res.getCount();
- } catch(Exception e) {
- CMS.debug("SecurityDomainSessionTable: unable to query sessionIds: " + e);
+ } catch (Exception e) {
+ CMS.debug("SecurityDomainSessionTable: unable to query sessionIds: "
+ + e);
}
try {
conn.disconnect();
} catch (Exception e) {
- CMS.debug("SecurityDomainSessionTable: getSessionIds: Error in disconnecting from database: " + e);
+ CMS.debug("SecurityDomainSessionTable: getSessionIds: Error in disconnecting from database: "
+ + e);
}
return ret;
}
- private LDAPConnection getLDAPConn()
- throws IOException
- {
+ private LDAPConnection getLDAPConn() throws IOException {
IConfigStore cs = CMS.getConfigStore();
String host = "";
@@ -299,12 +321,13 @@ public class LDAPSecurityDomainSessionTable
IPasswordStore pwdStore = CMS.getPasswordStore();
if (pwdStore != null) {
- //CMS.debug("SecurityDomainSessionTable: getLDAPConn: password store available");
+ // CMS.debug("SecurityDomainSessionTable: getLDAPConn: password store available");
pwd = pwdStore.getPassword("internaldb");
}
- if ( pwd == null) {
- throw new IOException("SecurityDomainSessionTable: Failed to obtain password from password store");
+ if (pwd == null) {
+ throw new IOException(
+ "SecurityDomainSessionTable: Failed to obtain password from password store");
}
try {
@@ -329,14 +352,15 @@ public class LDAPSecurityDomainSessionTable
LDAPConnection conn = null;
if (security.equals("true")) {
- //CMS.debug("SecurityDomainSessionTable getLDAPConn: creating secure (SSL) connection for internal ldap");
- conn = new LDAPConnection(CMS.getLdapJssSSLSocketFactory());
+ // CMS.debug("SecurityDomainSessionTable getLDAPConn: creating secure (SSL) connection for internal ldap");
+ conn = new LDAPConnection(CMS.getLdapJssSSLSocketFactory());
} else {
- //CMS.debug("SecurityDomainSessionTable getLDAPConn: creating non-secure (non-SSL) connection for internal ldap");
- conn = new LDAPConnection();
+ // CMS.debug("SecurityDomainSessionTable getLDAPConn: creating non-secure (non-SSL) connection for internal ldap");
+ conn = new LDAPConnection();
}
- //CMS.debug("SecurityDomainSessionTable connecting to " + host + ":" + p);
+ // CMS.debug("SecurityDomainSessionTable connecting to " + host + ":" +
+ // p);
try {
conn.connect(host, p, binddn, pwd);
} catch (LDAPException e) {