Commit ef93b36c authored by Brian Major's avatar Brian Major
Browse files

s1885 - fixed merge conflicts

parents af2e548f efc84b5d
......@@ -69,23 +69,22 @@
package ca.nrc.cadc.ac.server.ldap;
import org.apache.log4j.Logger;
import ca.nrc.cadc.ac.server.ldap.LdapConfig.LdapPool;
import ca.nrc.cadc.ac.server.ldap.LdapConfig.PoolPolicy;
import ca.nrc.cadc.ac.server.ldap.LdapConfig.SystemState;
import ca.nrc.cadc.net.TransientException;
import ca.nrc.cadc.profiler.Profiler;
import com.unboundid.ldap.sdk.FewestConnectionsServerSet;
import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPConnectionOptions;
import com.unboundid.ldap.sdk.LDAPConnectionPool;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.RoundRobinServerSet;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldap.sdk.ServerSet;
import com.unboundid.ldap.sdk.SimpleBindRequest;
import org.apache.log4j.Logger;
/**
* This object is designed to be shared between the DAO classes
......@@ -99,8 +98,6 @@ public class LdapConnectionPool
{
private static final Logger logger = Logger.getLogger(LdapConnectionPool.class);
Profiler profiler = new Profiler(LdapConnectionPool.class);
protected LdapConfig currentConfig;
private String poolName;
private LDAPConnectionPool pool;
......@@ -129,6 +126,7 @@ public class LdapConnectionPool
logger.debug("Construct pool: " + poolName + ". system state: " + systemState);
if (SystemState.ONLINE.equals(systemState) || (SystemState.READONLY.equals(systemState) && readOnly))
{
Profiler profiler = new Profiler(LdapConnectionPool.class);
synchronized (poolMonitor)
{
if (!boundPool)
......@@ -168,23 +166,27 @@ public class LdapConnectionPool
try
{
Profiler profiler = new Profiler(LdapConnectionPool.class);
LDAPConnection conn = null;
synchronized (poolMonitor)
{
conn = pool.getConnection();
profiler.checkpoint("pool.getConnection");
// BM: This query to the base dn (starting at dc=) has the
// effect of clearing any proxied authorization state associated
// with the receiving ldap server connection. Without this in
// place, proxied authorization information is sometimes ignored.
logger.debug("Testing connection");
int dcIndex = currentConfig.getGroupsDN().indexOf("dc=");
String dcDN = currentConfig.getGroupsDN().substring(dcIndex);
Filter filter = Filter.createEqualityFilter("dc", "*");
SearchRequest searchRequest = new SearchRequest(dcDN, SearchScope.BASE, filter, new String[] {"entrydn"});
conn.search(searchRequest);
profiler.checkpoint("pool.initConnection");
// logger.debug("Testing connection");
// int index = currentConfig.getGroupsDN().indexOf(',');
// String rdn = currentConfig.getGroupsDN().substring(0, index);
// Filter filter = Filter.create("(" + rdn + ")");
//
// index = rdn.indexOf('=');
// String attribute = rdn.substring(0, index);
//
// SearchRequest searchRequest = new SearchRequest(currentConfig.getGroupsDN(), SearchScope.BASE, filter, new String[] {attribute});
// conn.search(searchRequest);
// profiler.checkpoint("pool.initConnection");
}
logger.debug(poolName + " pool statistics after borrow:\n" + pool.getConnectionPoolStatistics());
profiler.checkpoint("get " + poolName + " only connection");
......@@ -202,7 +204,9 @@ public class LdapConnectionPool
{
if (pool != null)
{
Profiler profiler = new Profiler(LdapConnectionPool.class);
pool.releaseConnection(conn);
profiler.checkpoint("pool.releaseConnection");
logger.debug(poolName + " pool statistics after release:\n" + pool.getConnectionPoolStatistics());
}
}
......@@ -217,8 +221,9 @@ public class LdapConnectionPool
if (pool != null)
{
logger.debug("Closing pool...");
Profiler profiler = new Profiler(LdapConnectionPool.class);
pool.close();
profiler.checkpoint("Pool closed.");
profiler.checkpoint("pool.shutdown");
}
}
......
......@@ -91,8 +91,6 @@ class LdapConnections
{
private final static Logger log = Logger.getLogger(LdapConnections.class);
Profiler profiler = new Profiler(LdapConnections.class);
private LdapPersistence persistence;
private LdapConfig config;
......@@ -134,6 +132,7 @@ class LdapConnections
if (autoConfigReadOnlyConn == null)
{
log.debug("Getting new auto config read only connection.");
Profiler profiler = new Profiler(LdapConnections.class);
autoConfigReadOnlyConn = readOnlyPool.getConnection();
profiler.checkpoint("Get read only connection");
}
......@@ -173,6 +172,7 @@ class LdapConnections
if (autoConfigReadWriteConn == null)
{
log.debug("Getting new auto config read write connection.");
Profiler profiler = new Profiler(LdapConnections.class);
autoConfigReadWriteConn = readWritePool.getConnection();
profiler.checkpoint("Get read write connection");
}
......@@ -212,6 +212,7 @@ class LdapConnections
if (autoConfigUnboundReadOnlyConn == null)
{
log.debug("Getting new auto config unbound read only connection.");
Profiler profiler = new Profiler(LdapConnections.class);
autoConfigUnboundReadOnlyConn = unboundReadOnlyPool.getConnection();
profiler.checkpoint("Get read write connection");
}
......@@ -242,6 +243,7 @@ class LdapConnections
void releaseConnections()
{
Profiler profiler = new Profiler(LdapConnections.class);
if (persistence != null)
{
if (autoConfigReadOnlyConn != null)
......
......@@ -90,8 +90,6 @@ public abstract class LdapDAO
DN subjDN = null;
private Profiler profiler = new Profiler(LdapDAO.class);
public LdapDAO(LdapConnections connections)
{
this.connections = connections;
......@@ -179,8 +177,8 @@ public abstract class LdapDAO
if (config.isSecure())
{
socketFactory = createSSLSocketFactory();
Profiler profiler = new Profiler(LdapDAO.class);
socketFactory = createSSLSocketFactory();
profiler.checkpoint("createSSLSocketFactory");
}
else
......
......@@ -141,8 +141,6 @@ public class LdapGroupDAO extends LdapDAO
LDAP_MODIFY_TIMESTAMP, LDAP_DESCRIPTION, LDAP_UNIQUE_MEMBER
};
private final Profiler profiler = new Profiler(LdapGroupDAO.class);
private LdapUserDAO userDAO;
// this gets filled by the LdapgroupPersistence
......@@ -379,6 +377,7 @@ public class LdapGroupDAO extends LdapDAO
SearchResult searchResult = null;
try
{
Profiler profiler = new Profiler(LdapGroupDAO.class);
LDAPInterface con = getReadOnlyConnection();
profiler.checkpoint("getGroupNames.getConnection");
searchResult = con.search(searchRequest);
......@@ -397,7 +396,7 @@ public class LdapGroupDAO extends LdapDAO
}
LdapDAO.checkLdapResult(searchResult.getResultCode());
profiler.checkpoint("checkLdapResult");
// profiler.checkpoint("checkLdapResult");
return groupNames;
}
......
......@@ -97,8 +97,6 @@ public abstract class LdapPersistence
private static final String LDAP_POOL_JNDI_NAME = ConnectionPools.class.getName();
private static final int POOL_CHECK_INTERVAL_MILLESCONDS = 10000; // 10 seconds
Profiler profiler = new Profiler(LdapPersistence.class);
// static monitor is required for when multiple LdapPersistence objects
// are created.
private static Object jndiMonitor = new Object();
......@@ -208,6 +206,7 @@ public abstract class LdapPersistence
}
if (pools == null)
{
Profiler profiler = new Profiler(LdapPersistence.class);
LdapConfig config = LdapConfig.getLdapConfig();
pools = createPools(config);
InitialContext ic = new InitialContext();
......@@ -238,6 +237,7 @@ public abstract class LdapPersistence
private ConnectionPools createPools(LdapConfig config)
{
Profiler profiler = new Profiler(LdapPersistence.class);
Map<String,LdapConnectionPool> poolMap = new HashMap<String,LdapConnectionPool>(3);
poolMap.put(POOL_READONLY, new LdapConnectionPool(
config, config.getReadOnlyPool(), POOL_READONLY, true, true));
......@@ -276,6 +276,7 @@ public abstract class LdapPersistence
else
{
logger.debug("Detected ldap configuration change, rebuilding pools");
Profiler profiler = new Profiler(LdapPersistence.class);
boolean poolRecreated = false;
final ConnectionPools oldPools = pools;
ConnectionPools newPools = null;
......
......@@ -140,8 +140,6 @@ public class LdapUserDAO extends LdapDAO
private static final Logger logger = Logger.getLogger(LdapUserDAO.class);
private final Profiler profiler = new Profiler(LdapUserDAO.class);
private String internalIdUriPrefix = AC.USER_URI;
// Map of identity type to LDAP attribute
......@@ -680,8 +678,8 @@ public class LdapUserDAO extends LdapDAO
public User getAugmentedUser(final Principal userID)
throws UserNotFoundException, TransientException
{
Profiler profiler = new Profiler(LdapUserDAO.class);
String searchField = userLdapAttrib.get(userID.getClass());
profiler.checkpoint("getAugmentedUser.getSearchField");
if (searchField == null)
{
throw new IllegalArgumentException("getAugmentedUser: unsupported principal type " +
......@@ -709,9 +707,10 @@ public class LdapUserDAO extends LdapDAO
SearchRequest searchRequest = new SearchRequest(
config.getUsersDN(), SearchScope.ONE, filter, identityAttribs);
profiler.checkpoint("getAugmentedUser.createSearchRequest");
SearchResultEntry searchResult = getReadOnlyConnection().searchForEntry(searchRequest);
LDAPConnection con = getReadOnlyConnection();
profiler.checkpoint("getAugmentedUser.getReadOnlyConnection");
SearchResultEntry searchResult = con.searchForEntry(searchRequest);
profiler.checkpoint("getAugmentedUser.searchForEntry");
if (searchResult == null)
......
......@@ -90,7 +90,6 @@ import ca.nrc.cadc.profiler.Profiler;
public class LdapUserPersistence extends LdapPersistence implements UserPersistence
{
private static final Logger logger = Logger.getLogger(LdapUserPersistence.class);
private Profiler profiler = new Profiler(LdapUserPersistence.class);
public LdapUserPersistence()
{
......@@ -244,7 +243,8 @@ public class LdapUserPersistence extends LdapPersistence implements UserPersiste
}
}
/**
/**<<<<<<< HEAD
* Get the user specified by userID with all of the users identities.
*
* @param userID The userID.
......@@ -263,6 +263,7 @@ public class LdapUserPersistence extends LdapPersistence implements UserPersiste
LdapConnections conns = new LdapConnections(this);
try
{
Profiler profiler = new Profiler(LdapUserPersistence.class);
userDAO = getLdapUserDao(conns);
profiler.checkpoint("Create LdapUserDAO");
User user = userDAO.getAugmentedUser(userID);
......@@ -509,7 +510,11 @@ public class LdapUserPersistence extends LdapPersistence implements UserPersiste
/**
* Update a user's password. The given user and authenticating user must match.
*
<<<<<<< HEAD
* @param userID the user.
=======
* @param userID
>>>>>>> efc84b5d25584bd3014fc6cbc820c5acf0d90a2a
* @param oldPassword current password.
* @param newPassword new password.
* @throws UserNotFoundException If the given user does not exist.
......@@ -543,7 +548,11 @@ public class LdapUserPersistence extends LdapPersistence implements UserPersiste
/**
* Reset a user's password. The given user and authenticating user must match.
*
<<<<<<< HEAD
* @param userID The user.
=======
* @param userID
>>>>>>> efc84b5d25584bd3014fc6cbc820c5acf0d90a2a
* @param newPassword new password.
* @throws UserNotFoundException If the given user does not exist.
* @throws TransientException If an temporary, unexpected problem occurred.
......
......@@ -181,7 +181,7 @@ public class UserServlet extends HttpServlet
log.debug("create action " + action.getClass().getSimpleName());
action.setAcceptedContentType(getAcceptedContentType(request));
log.debug("content-type: " + getAcceptedContentType(request));
profiler.checkpoint("created action");
// profiler.checkpoint("created action");
Subject subject;
Subject privilegedSubject = getPrivilegedSubject(request);
......@@ -289,6 +289,7 @@ public class UserServlet extends HttpServlet
}
finally
{
profiler.checkpoint("Action complete");
logInfo.setElapsedTime(System.currentTimeMillis() - start);
log.info(logInfo.end());
}
......
......@@ -75,6 +75,7 @@ import java.util.List;
import ca.nrc.cadc.ac.Group;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.xml.GroupReader;
import ca.nrc.cadc.profiler.Profiler;
public class ModifyGroupAction extends AbstractGroupAction
{
......@@ -92,10 +93,14 @@ public class ModifyGroupAction extends AbstractGroupAction
public void doAction() throws Exception
{
Profiler profiler = new Profiler(ModifyGroupAction.class);
GroupReader groupReader = new GroupReader();
Group group = groupReader.read(this.inputStream);
Group oldGroup = groupPersistence.getGroup(this.groupName);
profiler.checkpoint("get Group");
groupPersistence.modifyGroup(group);
profiler.checkpoint("modify Group");
List<String> addedMembers = new ArrayList<String>();
for (User member : group.getUserMembers())
......@@ -130,6 +135,7 @@ public class ModifyGroupAction extends AbstractGroupAction
deletedMembers = null;
}
logGroupInfo(group.getID(), deletedMembers, addedMembers);
profiler.checkpoint("log GroupInfo");
syncOut.setHeader("Location", request);
syncOut.setCode(303);
......
......@@ -81,14 +81,17 @@ import ca.nrc.cadc.ac.ReaderException;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.UserAlreadyExistsException;
import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.ac.UserRequest;
import ca.nrc.cadc.ac.WriterException;
import ca.nrc.cadc.ac.json.JsonUserListWriter;
import ca.nrc.cadc.ac.json.JsonUserReader;
import ca.nrc.cadc.ac.json.JsonUserRequestReader;
import ca.nrc.cadc.ac.json.JsonUserWriter;
import ca.nrc.cadc.ac.server.UserPersistence;
import ca.nrc.cadc.ac.server.web.SyncOutput;
import ca.nrc.cadc.ac.xml.UserListWriter;
import ca.nrc.cadc.ac.xml.UserReader;
import ca.nrc.cadc.ac.xml.UserRequestReader;
import ca.nrc.cadc.ac.xml.UserWriter;
import ca.nrc.cadc.net.TransientException;
import ca.nrc.cadc.profiler.Profiler;
......@@ -98,7 +101,6 @@ public abstract class AbstractUserAction implements PrivilegedExceptionAction<Ob
private static final Logger log = Logger.getLogger(AbstractUserAction.class);
public static final String DEFAULT_CONTENT_TYPE = "text/xml";
public static final String JSON_CONTENT_TYPE = "application/json";
private Profiler profiler = new Profiler(AbstractUserAction.class);
protected boolean isPrivilegedUser;
protected boolean isPrivilegedSubject;
......@@ -154,6 +156,7 @@ public abstract class AbstractUserAction implements PrivilegedExceptionAction<Ob
{
try
{
Profiler profiler = new Profiler(AbstractUserAction.class);
doAction();
profiler.checkpoint("doAction");
}
......@@ -227,6 +230,7 @@ public abstract class AbstractUserAction implements PrivilegedExceptionAction<Ob
private void sendError(int responseCode, String message)
{
Profiler profiler = new Profiler(AbstractUserAction.class);
syncOut.setCode(responseCode);
syncOut.setHeader("Content-Type", "text/plain");
if (message != null)
......@@ -253,6 +257,40 @@ public abstract class AbstractUserAction implements PrivilegedExceptionAction<Ob
this.acceptedContentType = acceptedContentType;
}
/**
* Read a user request (User pending approval) from the HTTP Request's
* stream.
*
* @param inputStream The Input Stream to read from.
* @return User Request instance.
* @throws IOException Any reading errors.
*/
protected final UserRequest readUserRequest(
final InputStream inputStream) throws ReaderException, IOException
{
Profiler profiler = new Profiler(AbstractUserAction.class);
final UserRequest userRequest;
if (acceptedContentType.equals(DEFAULT_CONTENT_TYPE))
{
UserRequestReader requestReader = new UserRequestReader();
userRequest = requestReader.read(inputStream);
}
else if (acceptedContentType.equals(JSON_CONTENT_TYPE))
{
JsonUserRequestReader requestReader = new JsonUserRequestReader();
userRequest = requestReader.read(inputStream);
}
else
{
// Should never happen.
throw new IOException("Unknown content being asked for: "
+ acceptedContentType);
}
profiler.checkpoint("readUserRequest");
return userRequest;
}
/**
* Read the user from the given stream of marshalled data.
*
......@@ -264,6 +302,7 @@ public abstract class AbstractUserAction implements PrivilegedExceptionAction<Ob
protected User readUser(final InputStream inputStream)
throws ReaderException, IOException
{
Profiler profiler = new Profiler(AbstractUserAction.class);
syncOut.setHeader("Content-Type", acceptedContentType);
final User user;
......@@ -296,6 +335,7 @@ public abstract class AbstractUserAction implements PrivilegedExceptionAction<Ob
protected void writeUser(final User user)
throws WriterException, IOException
{
Profiler profiler = new Profiler(AbstractUserAction.class);
syncOut.setHeader("Content-Type", acceptedContentType);
final Writer writer = syncOut.getWriter();
......@@ -320,6 +360,7 @@ public abstract class AbstractUserAction implements PrivilegedExceptionAction<Ob
protected void writeUsers(final Collection<User> users)
throws WriterException, IOException
{
Profiler profiler = new Profiler(AbstractUserAction.class);
syncOut.setHeader("Content-Type", acceptedContentType);
final Writer writer = syncOut.getWriter();
......
......@@ -94,8 +94,6 @@ public class AuthenticatorImpl implements Authenticator
{
private static final Logger log = Logger.getLogger(AuthenticatorImpl.class);
private Profiler profiler = new Profiler(AuthenticatorImpl.class);
public AuthenticatorImpl() { }
/**
......@@ -104,6 +102,7 @@ public class AuthenticatorImpl implements Authenticator
*/
public Subject getSubject(Subject subject)
{
Profiler profiler = new Profiler(AuthenticatorImpl.class);
log.debug("ac augment subject: " + subject);
AuthMethod am = AuthenticationUtil.getAuthMethod(subject);
if (am == null || AuthMethod.ANON.equals(am))
......@@ -135,6 +134,7 @@ public class AuthenticatorImpl implements Authenticator
{
try
{
Profiler profiler = new Profiler(AuthenticatorImpl.class);
PluginFactory pluginFactory = new PluginFactory();
UserPersistence userPersistence = pluginFactory.createUserPersistence();
User user = userPersistence.getAugmentedUser(subject.getPrincipals().iterator().next());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment