You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/07/06 15:41:03 UTC
svn commit: r1500262 - in /manifoldcf/branches/CONNECTORS-731/connectors:
jdbc/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jdbc/
jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/
ldap/connector/s...
Author: kwright
Date: Sat Jul 6 13:41:03 2013
New Revision: 1500262
URL: http://svn.apache.org/r1500262
Log:
Revamp more authorities to use the standard conventions, and also add thread support for user checking in Jira authority.
Modified:
manifoldcf/branches/CONNECTORS-731/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jdbc/JDBCAuthority.java
manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java
manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java
manifoldcf/branches/CONNECTORS-731/connectors/ldap/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/ldap/LDAPAuthority.java
Modified: manifoldcf/branches/CONNECTORS-731/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jdbc/JDBCAuthority.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-731/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jdbc/JDBCAuthority.java?rev=1500262&r1=1500261&r2=1500262&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-731/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jdbc/JDBCAuthority.java (original)
+++ manifoldcf/branches/CONNECTORS-731/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jdbc/JDBCAuthority.java Sat Jul 6 13:41:03 2013
@@ -58,11 +58,6 @@ import org.apache.manifoldcf.crawler.sys
public class JDBCAuthority extends BaseAuthorityConnector {
public static final String _rcsid = "@(#)$Id: JDBCAuthority.java $";
- private static final String globalDenyToken = "DEAD_AUTHORITY";
- private static final AuthorizationResponse unreachableResponse = new AuthorizationResponse(new String[]{globalDenyToken},
- AuthorizationResponse.RESPONSE_UNREACHABLE);
- private static final AuthorizationResponse userNotFoundResponse = new AuthorizationResponse(new String[]{globalDenyToken},
- AuthorizationResponse.RESPONSE_USERNOTFOUND);
protected WrappedConnection connection = null;
protected String jdbcProvider = null;
protected String host = null;
@@ -224,16 +219,16 @@ public class JDBCAuthority extends BaseA
loadPS(ps, paramList);
ResultSet rs = ps.executeQuery();
if (rs == null) {
- return unreachableResponse;
+ return RESPONSE_UNREACHABLE;
}
String uid;
if (rs.next()) {
uid = rs.getString(1);
} else {
- return userNotFoundResponse;
+ return RESPONSE_USERNOTFOUND;
}
if (uid == null || uid.isEmpty()) {
- return unreachableResponse;
+ return RESPONSE_UNREACHABLE;
}
// now check tokens
@@ -247,7 +242,7 @@ public class JDBCAuthority extends BaseA
loadPS(ps, paramList);
rs = ps.executeQuery();
if (rs == null) {
- return unreachableResponse;
+ return RESPONSE_UNREACHABLE;
}
ArrayList<String> tokenArray = new ArrayList<String>();
while (rs.next()) {
@@ -268,7 +263,7 @@ public class JDBCAuthority extends BaseA
} catch (Exception e) {
// Unreachable
- return unreachableResponse;
+ return RESPONSE_UNREACHABLE;
}
}
Modified: manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java?rev=1500262&r1=1500261&r2=1500262&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java (original)
+++ manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java Sat Jul 6 13:41:03 2013
@@ -381,8 +381,9 @@ public class JiraAuthorityConnector exte
@Override
public AuthorizationResponse getAuthorizationResponse(String userName)
throws ManifoldCFException {
- // MHL
- return null;
+ if (checkUserExists(userName))
+ return new AuthorizationResponse(new String[]{userName},AuthorizationResponse.RESPONSE_OK);
+ return RESPONSE_USERNOTFOUND;
}
/** Obtain the default access tokens for a given user name.
@@ -406,6 +407,69 @@ public class JiraAuthorityConnector exte
// Background threads
+ protected static class CheckUserExistsThread extends Thread {
+ protected final JiraSession session;
+ protected final String userName;
+ protected Throwable exception = null;
+ protected boolean result = false;
+
+ public CheckUserExistsThread(JiraSession session, String userName) {
+ super();
+ this.session = session;
+ this.userName = userName;
+ setDaemon(true);
+ }
+
+ public void run() {
+ try {
+ result = session.checkUserExists(userName);
+ } catch (Throwable e) {
+ this.exception = e;
+ }
+ }
+
+ public void finishUp()
+ throws InterruptedException, IOException {
+ join();
+ Throwable thr = exception;
+ if (thr != null) {
+ if (thr instanceof IOException) {
+ throw (IOException) thr;
+ } else if (thr instanceof RuntimeException) {
+ throw (RuntimeException) thr;
+ } else {
+ throw (Error) thr;
+ }
+ }
+ }
+
+ public boolean getResult() {
+ return result;
+ }
+
+ }
+
+ protected boolean checkUserExists(String userName) throws ManifoldCFException {
+ CheckUserExistsThread t = new CheckUserExistsThread(getSession(), userName);
+ try {
+ t.start();
+ t.finishUp();
+ return t.getResult();
+ } catch (InterruptedException e) {
+ t.interrupt();
+ throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
+ ManifoldCFException.INTERRUPTED);
+ } catch (java.net.SocketTimeoutException e) {
+ handleIOException(e);
+ } catch (InterruptedIOException e) {
+ t.interrupt();
+ handleIOException(e);
+ } catch (IOException e) {
+ handleIOException(e);
+ }
+ return false;
+ }
+
protected static class CheckConnectionThread extends Thread {
protected final JiraSession session;
Modified: manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java?rev=1500262&r1=1500261&r2=1500262&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java (original)
+++ manifoldcf/branches/CONNECTORS-731/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java Sat Jul 6 13:41:03 2013
@@ -219,4 +219,10 @@ public class JiraSession {
return statistics;
}
+ /** Check if user exists.
+ */
+ public boolean checkUserExists(String userName) throws IOException {
+ // MHL
+ return false;
+ }
}
Modified: manifoldcf/branches/CONNECTORS-731/connectors/ldap/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/ldap/LDAPAuthority.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-731/connectors/ldap/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/ldap/LDAPAuthority.java?rev=1500262&r1=1500261&r2=1500262&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-731/connectors/ldap/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/ldap/LDAPAuthority.java (original)
+++ manifoldcf/branches/CONNECTORS-731/connectors/ldap/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/ldap/LDAPAuthority.java Sat Jul 6 13:41:03 2013
@@ -44,15 +44,6 @@ public class LDAPAuthority extends org.a
*/
private LdapContext session = null;
private long sessionExpirationTime = -1L;
- /**
- * This is the active directory global deny token. This should be ingested
- * with all documents.
- */
- private static final String globalDenyToken = "DEAD_AUTHORITY";
- private static final AuthorizationResponse unreachableResponse = new AuthorizationResponse(new String[]{globalDenyToken},
- AuthorizationResponse.RESPONSE_UNREACHABLE);
- private static final AuthorizationResponse userNotFoundResponse = new AuthorizationResponse(new String[]{globalDenyToken},
- AuthorizationResponse.RESPONSE_USERNOTFOUND);
private ConfigParams parameters;
private String serverName;
private String serverPort;
@@ -317,7 +308,7 @@ public class LDAPAuthority extends org.a
//find user in LDAP tree
SearchResult usrRecord = getUserEntry(session, userName);
if (usrRecord == null) {
- return userNotFoundResponse;
+ return RESPONSE_USERNOTFOUND;
}
ArrayList theGroups = new ArrayList();
@@ -371,10 +362,10 @@ public class LDAPAuthority extends org.a
} catch (NameNotFoundException e) {
// This means that the user doesn't exist
- return userNotFoundResponse;
+ return RESPONSE_USERNOTFOUND;
} catch (NamingException e) {
// Unreachable
- return unreachableResponse;
+ return RESPONSE_UNREACHABLE;
}
}
@@ -388,7 +379,7 @@ public class LDAPAuthority extends org.a
@Override
public AuthorizationResponse getDefaultAuthorizationResponse(String userName) {
// The default response if the getConnection method fails
- return unreachableResponse;
+ return RESPONSE_UNREACHABLE;
}
// UI support methods.