Skip to content

Commit

Permalink
Preparing to roll RC4. Changes are final cleanup of new pooling code,…
Browse files Browse the repository at this point in the history
… removing a bunch of dead/commented code. Moved a class.
  • Loading branch information
jjg-123 committed Jul 3, 2018
1 parent 335685d commit 3803a1d
Show file tree
Hide file tree
Showing 53 changed files with 609 additions and 258 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.uiuc.ncsa.security.core;

import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -49,4 +50,11 @@ public interface Store<V extends Identifiable> extends Map<Identifier, V> {
*/
public void save(V value);

/**
* Method to get every element in the store. This is useful for command line interfaces. Note
* that this might be very expensive.
* @return
*/
public List<V> getAll();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public abstract class Pool<T> {
public static final int INFINITE = -1;
int maxSize = INFINITE;
protected int inUse = 0;
protected int inUse = 0;
List<T> stack = new LinkedList<T>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public List<V> stores() {
* Caveat! This does not check if the store has already been added! This is because store comparison
* is probably too expensive and in some cases almost impossible to do. It is up to the application not
* to add multiple copies of the same store.
*
* @param store
*/
public void addStore(V store) {
stores.add(store);
stores.add(store);
}



protected void checkValid() {
if (0 == stores.size()) {
throw new GeneralException("Error: Aggregate store is empty. There must be at least one store in the aggregate.");
Expand Down Expand Up @@ -88,12 +88,12 @@ public void register(Identifiable value) {
public void save(Identifiable value) {
for (Store s : stores) {
// try to get it to the right store.
try{
if (s.containsKey(value.getIdentifier())) {
s.save(value);
return;
}
}catch(Throwable t){
try {
if (s.containsKey(value.getIdentifier())) {
s.save(value);
return;
}
} catch (Throwable t) {
t.printStackTrace();
}
}
Expand Down Expand Up @@ -232,5 +232,14 @@ public Set entrySet() {
}
return set;
}

@Override
public List getAll() {
LinkedList<V> allEntries = new LinkedList<>();
for (Object object : values()) {
allEntries.add((V) object);
}
return allEntries;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ public V get(Object key) {
return (V) loadByIdentifier(key.toString());
}

@Override
public List<V> getAll() {
LinkedList<V> allEntries = new LinkedList<>();
for(Identifier d : keySet()){
allEntries.add(get(d));
}
return allEntries;
}

public boolean delete(String identifier) {
V t = loadByIdentifier(identifier);
Expand Down Expand Up @@ -440,4 +448,8 @@ public V create() {
checkPermissions();
return super.create();
}

public MapConverter<V> getConverter() {
return converter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import edu.uiuc.ncsa.security.core.exceptions.UnregisteredObjectException;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
* An in-memory store. This is useful in several different ways and is in effect
Expand Down Expand Up @@ -101,5 +103,12 @@ public void save(V value) {
realSave(value);
}


@Override
public List<V> getAll() {
LinkedList<V> allEntries = new LinkedList<>();
for(Identifier d: keySet()){
allEntries.add(get(d));
}
return allEntries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ protected AdminConnectionParameters(
int port,
String jdbcDriver,
String clientUsername,
boolean useSSL) {
super(username, password,databaseName,schema, host, port, jdbcDriver, useSSL);
boolean useSSL,
String parameters) {
super(username, password,databaseName,schema, host, port, jdbcDriver, useSSL, parameters);
this.clientUsername = clientUsername;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.uiuc.ncsa.security.storage.sql;

import edu.uiuc.ncsa.security.core.util.DebugUtil;
import edu.uiuc.ncsa.security.core.util.Pool;
import edu.uiuc.ncsa.security.core.util.PoolException;

Expand Down Expand Up @@ -29,6 +30,7 @@ public Connection create() throws PoolException {
Connection con = DriverManager.getConnection(getConnectionParameters().getJdbcUrl());
return con;
} catch (Exception x) {
DebugUtil.dbg(this, "Connection failure, JDBC URL=" + getConnectionParameters().getJdbcUrl());
x.printStackTrace();
throw new PoolException(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class ConnectionPoolProvider<T extends ConnectionPool> extends H
public static final String DRIVER = "driver";
public static final String USE_SSL = "useSSL";
public static final String DATABASE = "database";
public static final String PARAMETERS = "parameters";
public static final String SCHEMA = SQLStoreProvider.SCHEMA; // since this is shared, really.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,12 @@ public String getUser() {
protected void init2() throws SQLException {
Connection c = getConnection();
Statement s = c.createStatement();
try {
createSchema(s);
createTables(s);
setPermissions(s);

} finally {
s.close();
c.close();
}
createSchema(s);
createTables(s);
setPermissions(s);
s.close();
c.close();
releaseConnection(c);
}

public boolean init() {
Expand All @@ -133,13 +130,11 @@ public boolean init() {
protected void destroy2() throws SQLException {
Connection c = getConnection();
Statement s = c.createStatement();
try {
dropTables(s);
dropSchema(s);
} finally {
s.close();
c.close();
}
dropTables(s);
dropSchema(s);
s.close();
c.close();
releaseConnection(c);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ protected SQLConnectionImpl(
String host,
int port,
String jdbcDriver,
boolean useSSL
) {
boolean useSSL,
String parameters
) {
this.databaseName = databaseName;
this.host = host;
this.jdbcDriver = jdbcDriver;
Expand All @@ -28,15 +29,52 @@ protected SQLConnectionImpl(
this.schema = schema;
this.username = username;
this.useSSL = useSSL;
this.parameters = parameters;
init();
}

/**
* Add parameters from the configuration file if they exist. The parameter string is of the form
* <pre>
* key0=value0&key1=value1&key2=value2...
* </pre>
* <b>NOTE:</b> this method does not set the ssl connection parameter -- tjhat should be done before invoking this method
* because that is very vendor specific. This method passes along whatever parameters to the driver the user needs or skips them
* if there are none.
* @param jdbcURL
* @return
*/
protected String addParameters(String jdbcURL) {
String p = null;
if (getParameters() != null && !getParameters().isEmpty()) {
p = getParameters();
}
if (p != null) {
if (p.startsWith("&")) {
p = p.substring(1); // drop initial "&"
}
if (p.endsWith("&")) {
p = p.substring(0, p.length() - 1); //shave off final &
}
jdbcURL = jdbcURL + "&" + p;
}

return jdbcURL;
}

public String getParameters() {
return parameters;
}

String parameters;

@Override
public String getUsername() {
return username;
}

protected boolean useSSL = false;

protected void init() {
if (jdbcDriver == null) {
throw new MyConfigurationException("Missing JDBC driver");
Expand Down Expand Up @@ -78,34 +116,37 @@ public String toString() {
x = x + ", port=" + port;
x = x + ", jdbcDriver=" + jdbcDriver;
x = x + ", useSSL? " + useSSL;
x = x + ", parameters? " + parameters;
x = x + ", jdbcURL=" + getJdbcUrl();

x = x + "]";
return x;
}

boolean compareString(String x, String y){
if(x == null){
if(y==null) return true;
boolean compareString(String x, String y) {
if (x == null) {
if (y == null) return true;
return false;
}else{
if(y==null) return false;
} else {
if (y == null) return false;
}
return x.equals(y);
}

@Override
public boolean equals(Object obj) {
if(obj == null)return false;
if(!(obj instanceof SQLConnectionImpl))return false;
if (obj == null) return false;
if (!(obj instanceof SQLConnectionImpl)) return false;
SQLConnectionImpl z = (SQLConnectionImpl) obj;
if(!compareString(username,z.username)) return false;
if(!compareString(password,z.password)) return false;
if(!compareString(schema,z.schema)) return false;
if(!compareString(databaseName,z.databaseName)) return false;
if(!compareString(host,z.host)) return false;
if(!compareString(jdbcDriver,z.jdbcDriver)) return false;
if(port != z.port) return false;
if(useSSL != z.useSSL) return false;
if (!compareString(username, z.username)) return false;
if (!compareString(password, z.password)) return false;
if (!compareString(schema, z.schema)) return false;
if (!compareString(databaseName, z.databaseName)) return false;
if (!compareString(host, z.host)) return false;
if (!compareString(jdbcDriver, z.jdbcDriver)) return false;
// does not compare parameters since that is not well-defined....
if (port != z.port) return false;
if (useSSL != z.useSSL) return false;
return true;
}
}
Loading

0 comments on commit 3803a1d

Please sign in to comment.