You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2013/11/10 12:31:29 UTC
svn commit: r1540466 - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server:
DuccAuthenticator.java DuccHandler.java DuccHandlerUserAuthentication.java
Author: degenaro
Date: Sun Nov 10 11:31:29 2013
New Revision: 1540466
URL: http://svn.apache.org/r1540466
Log:
UIMA-3421 DUCC webserver (WS) native Linux-based authentication mechanism, as plug-in via ducc.properties
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAuthenticator.java
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUserAuthentication.java
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAuthenticator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAuthenticator.java?rev=1540466&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAuthenticator.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAuthenticator.java Sun Nov 10 11:31:29 2013
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.ws.server;
+
+import org.apache.uima.ducc.common.authentication.IAuthenticationManager;
+import org.apache.uima.ducc.common.authentication.IAuthenticationResult;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+
+public class DuccAuthenticator implements IAuthenticationManager {
+
+ private static DuccLogger duccLogger = DuccLoggerComponents.getWsLogger(DuccAuthenticator.class.getName());
+ private static DuccId jobid = null;
+
+ private static DuccAuthenticator instance = new DuccAuthenticator();
+
+ private DuccPropertiesResolver duccPropertiesResolver = null;
+
+ private IAuthenticationManager iAuthenticationManager = null;
+
+ public static DuccAuthenticator getInstance() {
+ return instance;
+ }
+
+ public DuccAuthenticator() {
+ duccPropertiesResolver = DuccPropertiesResolver.getInstance();
+ initializeAuthenticator();
+ }
+
+ private void initializeAuthenticator() {
+ String methodName = "initializeAuthenticator";
+ try {
+ String key = DuccPropertiesResolver.ducc_authentication_implementer;
+ String value = duccPropertiesResolver.getProperty(key);
+ Class<?> authenticationImplementer = Class.forName(value);
+ iAuthenticationManager = (IAuthenticationManager)authenticationImplementer.newInstance();
+ duccLogger.info(methodName, jobid, iAuthenticationManager.getVersion());
+ }
+ catch(Throwable t) {
+ duccLogger.error(methodName, jobid, t);
+ }
+ }
+
+ @Override
+ public String getVersion() {
+ String methodName = "getVersion";
+ String retVal = null;
+ try {
+ retVal = iAuthenticationManager.getVersion();
+ duccLogger.debug(methodName, jobid, retVal);
+ }
+ catch(Throwable t) {
+ duccLogger.error(methodName, jobid, t);
+ }
+ return retVal;
+ }
+
+ @Override
+ public boolean isPasswordChecked() {
+ String methodName = "isPasswordChecked";
+ boolean retVal = false;
+ try {
+ retVal = iAuthenticationManager.isPasswordChecked();
+ duccLogger.debug(methodName, jobid, retVal);
+ }
+ catch(Throwable t) {
+ duccLogger.error(methodName, jobid, t);
+ }
+ return retVal;
+ }
+
+ @Override
+ public IAuthenticationResult isAuthenticate(String userid, String domain, String password) {
+ String methodName = "isAuthenticate";
+ IAuthenticationResult retVal = null;
+ try {
+ retVal = iAuthenticationManager.isAuthenticate(userid, domain, password);
+ duccLogger.debug(methodName, jobid, retVal);
+ }
+ catch(Throwable t) {
+ duccLogger.error(methodName, jobid, t);
+ }
+ return retVal;
+ }
+
+ @Override
+ public IAuthenticationResult isGroupMember(String userid, String domain, Role role) {
+ String methodName = "isGroupMember";
+ IAuthenticationResult retVal = null;
+ try {
+ retVal = iAuthenticationManager.isGroupMember(userid, domain, role);
+ duccLogger.debug(methodName, jobid, retVal);
+ }
+ catch(Throwable t) {
+ duccLogger.error(methodName, jobid, t);
+ }
+ return retVal;
+ }
+
+}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java?rev=1540466&r1=1540465&r2=1540466&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java Sun Nov 10 11:31:29 2013
@@ -46,8 +46,6 @@ import javax.servlet.http.HttpServletRes
import org.apache.uima.ducc.cli.ws.json.MachineFacts;
import org.apache.uima.ducc.cli.ws.json.MachineFactsList;
import org.apache.uima.ducc.common.NodeConfiguration;
-import org.apache.uima.ducc.common.authentication.AuthenticationManager;
-import org.apache.uima.ducc.common.authentication.IAuthenticationManager;
import org.apache.uima.ducc.common.boot.DuccDaemonRuntimeProperties;
import org.apache.uima.ducc.common.boot.DuccDaemonRuntimeProperties.DaemonName;
import org.apache.uima.ducc.common.internationalization.Messages;
@@ -107,12 +105,12 @@ public class DuccHandler extends DuccAbs
private static Messages messages = Messages.getInstance();
private static DuccId jobid = null;
- private static IAuthenticationManager iAuthenticationManager = AuthenticationManager.getInstance();
-
private enum DetailsType { Job, Reservation, Service };
private enum ShareType { JD, MR, SPC, SPU, UIMA };
private enum LogType { POP, UIMA };
+ private DuccAuthenticator duccAuthenticator = DuccAuthenticator.getInstance();
+
private String duccVersion = duccContext+"/version";
private String duccLoginLink = duccContext+"/login-link";
@@ -188,29 +186,12 @@ public class DuccHandler extends DuccAbs
public DuccHandler(DuccWebServer duccWebServer) {
super.init(duccWebServer);
- initializeAuthenticator();
}
public String getFileName() {
return dir_home+File.separator+dir_resources+File.separator+getDuccWebServer().getClassDefinitionFile();
}
- private void initializeAuthenticator() {
- String methodName = "initializeAuthenticator";
- try {
- Properties properties = DuccWebProperties.get();
- String key = "ducc.authentication.implementer";
- if(properties.containsKey(key)) {
- String value = properties.getProperty(key);
- Class<?> authenticationImplementer = Class.forName(value);
- iAuthenticationManager = (IAuthenticationManager)authenticationImplementer.newInstance();
- }
- }
- catch(Exception e) {
- duccLogger.error(methodName, jobid, e);
- }
- }
-
/*
* non-authenticated
*/
@@ -304,7 +285,7 @@ public class DuccHandler extends DuccAbs
String methodName = "handleDuccServletAuthenticatorVersion";
duccLogger.trace(methodName, null, messages.fetch("enter"));
StringBuffer sb = new StringBuffer();
- sb.append(iAuthenticationManager.getVersion());
+ sb.append(duccAuthenticator.getVersion());
response.getWriter().println(sb);
duccLogger.trace(methodName, null, messages.fetch("exit"));
}
@@ -315,7 +296,7 @@ public class DuccHandler extends DuccAbs
String methodName = "handleDuccServletduccAuthenticatorPasswordChecked";
duccLogger.trace(methodName, null, messages.fetch("enter"));
StringBuffer sb = new StringBuffer();
- if(iAuthenticationManager.isPasswordChecked()) {
+ if(duccAuthenticator.isPasswordChecked()) {
sb.append("<input type=\"password\" name=\"password\"/>");
}
else {
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUserAuthentication.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUserAuthentication.java?rev=1540466&r1=1540465&r2=1540466&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUserAuthentication.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUserAuthentication.java Sun Nov 10 11:31:29 2013
@@ -19,14 +19,11 @@
package org.apache.uima.ducc.ws.server;
import java.io.IOException;
-import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.uima.ducc.common.authentication.AuthenticationManager;
-import org.apache.uima.ducc.common.authentication.IAuthenticationManager;
import org.apache.uima.ducc.common.authentication.IAuthenticationManager.Role;
import org.apache.uima.ducc.common.authentication.IAuthenticationResult;
import org.apache.uima.ducc.common.internationalization.Messages;
@@ -45,28 +42,11 @@ public class DuccHandlerUserAuthenticati
public final String userLogin = duccContextUser+"-login";
public final String userAuthenticationStatus = duccContextUser+"-authentication-status";
- private static IAuthenticationManager iAuthenticationManager = AuthenticationManager.getInstance();
+ private DuccAuthenticator duccAuthenticator = DuccAuthenticator.getInstance();
- private static DuccWebSessionManager duccWebSessionManager = DuccWebSessionManager.getInstance();
+ private DuccWebSessionManager duccWebSessionManager = DuccWebSessionManager.getInstance();
public DuccHandlerUserAuthentication() {
- initializeAuthenticator();
- }
-
- private void initializeAuthenticator() {
- String methodName = "initializeAuthenticator";
- try {
- Properties properties = DuccWebProperties.get();
- String key = "ducc.authentication.implementer";
- if(properties.containsKey(key)) {
- String value = properties.getProperty(key);
- Class<?> authenticationImplementer = Class.forName(value);
- iAuthenticationManager = (IAuthenticationManager)authenticationImplementer.newInstance();
- }
- }
- catch(Exception e) {
- duccLogger.error(methodName, jobid, e);
- }
}
protected boolean isAuthenticated(HttpServletRequest request,HttpServletResponse response) {
@@ -125,7 +105,7 @@ public class DuccHandlerUserAuthenticati
duccLogger.info(methodName, jobid, messages.fetch("login ")+userId+" "+messages.fetch("failed"));
sb.append("failure");
}
- else if(iAuthenticationManager.isPasswordChecked() && (((password == null) || (password.trim().length() == 0)))) {
+ else if(duccAuthenticator.isPasswordChecked() && (((password == null) || (password.trim().length() == 0)))) {
duccLogger.info(methodName, jobid, messages.fetch("login ")+userId+" "+messages.fetch("failed"));
sb.append("failure");
}
@@ -139,13 +119,15 @@ public class DuccHandlerUserAuthenticati
domain = parts[1];
}
}
- duccLogger.info(methodName, jobid, messages.fetchLabel("version")+iAuthenticationManager.getVersion());
- IAuthenticationResult result1 = iAuthenticationManager.isAuthenticate(userId, domain, password);
- IAuthenticationResult result2 = iAuthenticationManager.isGroupMember(userId, domain, role);
+ duccLogger.debug(methodName, jobid, messages.fetchLabel("version")+duccAuthenticator.getVersion());
+ IAuthenticationResult result1 = duccAuthenticator.isAuthenticate(userId, domain, password);
+ IAuthenticationResult result2 = duccAuthenticator.isGroupMember(userId, domain, role);
+ duccLogger.debug(methodName, jobid, messages.fetch("login ")+userId+" "+"group reason: "+result2.getReason());
if(result1.isSuccess() && result2.isSuccess()) {
duccWebSessionManager.login(request, userId);
duccLogger.info(methodName, jobid, messages.fetch("login ")+userId+" "+messages.fetch("success"));
sb.append("success");
+
}
else {
IAuthenticationResult result;