Author: degenaro Date: Sat Jan 12 12:41:59 2019 New Revision: 1851161 URL: http://svn.apache.org/viewvc?rev=1851161&view=rev Log: UIMA-5787 DUCC Web Server (WS) should honor service administrator
Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/HandlersHelper.java Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java?rev=1851161&r1=1851160&r2=1851161&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java Sat Jan 12 12:41:59 2019 @@ -141,6 +141,35 @@ public class ServicesRegistry { return retVal; } + public ServicesRegistryMapPayload findServiceById(String id) { + String location = "findServiceById"; + ServicesRegistryMapPayload retVal = null; + try { + logger.debug(location, jobid, "size: "+map.size()); + logger.debug(location, jobid, "search: "+id); + for(Long key : map.keySet()) { + ServicesRegistryMapPayload payload = map.get(key); + Properties meta = payload.meta; + if(meta != null) { + if(meta.containsKey(IServicesRegistry.numeric_id)) { + String sid = meta.getProperty(IServicesRegistry.numeric_id); + if(sid.equals(id)) { + retVal = payload; + break; + } + } + } + } + } + catch(Exception e) { + logger.error(location, jobid, e); + } + if(retVal == null) { + logger.warn(location, jobid, "not found: "+id); + } + return retVal; + } + public ServicesRegistryMapPayload findService(String name) { String location = "findService"; ServicesRegistryMapPayload retVal = null; Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java?rev=1851161&r1=1851160&r2=1851161&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java Sat Jan 12 12:41:59 2019 @@ -57,6 +57,7 @@ import org.apache.uima.ducc.ws.DuccDataH import org.apache.uima.ducc.ws.DuccMachinesData; import org.apache.uima.ducc.ws.registry.IServicesRegistry; import org.apache.uima.ducc.ws.registry.ServicesRegistry; +import org.apache.uima.ducc.ws.registry.sort.IServiceAdapter; import org.apache.uima.ducc.ws.server.DuccCookies.DateStyle; import org.apache.uima.ducc.ws.server.IWebMonitor.MonitorType; import org.apache.uima.ducc.ws.utils.FormatHelper; @@ -742,7 +743,34 @@ public abstract class DuccAbstractHandle return getDisabledWithHover(request, resourceOwnerUserId); } - public String getDisabledWithHover(HttpServletRequest request, String resourceOwnerUserId) { + public String getDisabledWithHover(HttpServletRequest request, String resourceOwnerUserId, IServiceAdapter service) { + String location = "getDisabledWithHover"; + String disabled = "disabled=\"disabled\""; + String hover = ""; + try { + String userId = duccWebSessionManager.getUserId(request); + Properties meta = service.getMeta(); + String serviceId = meta.getProperty(IServicesRegistry.numeric_id); + if(HandlersHelper.isLoggedIn(request)) { + if(HandlersHelper.isServiceController(userId, serviceId)) { + disabled = ""; + } + else { + hover = " title=\""+DuccConstants.hintPreferencesNotAdministrator+"\""; + } + } + else { + hover = " title=\""+DuccConstants.hintLogin+"\""; + } + } + catch(Exception e) { + duccLogger.trace(location, null, e); + } + String retVal = disabled+hover; + return retVal; + } + + private String getDisabledWithHover(HttpServletRequest request, String resourceOwnerUserId) { String disabled = "disabled=\"disabled\""; String hover = ""; HandlersHelper.AuthorizationStatus authorizationStatus = HandlersHelper.getAuthorizationStatus(request, resourceOwnerUserId); Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java?rev=1851161&r1=1851160&r2=1851161&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java Sat Jan 12 12:41:59 2019 @@ -4327,15 +4327,13 @@ public class DuccHandler extends DuccAbs String name = "id"; String value = request.getParameter(name).trim(); duccLogger.info(methodName, null, command+" "+messages.fetchLabel("id:")+value); - String text; String id = value.trim(); - ServicesRegistry servicesRegistry = ServicesRegistry.getInstance(); - String resourceOwnerUserId = servicesRegistry.findServiceUser(id); - if(resourceOwnerUserId != null) { - if(HandlersHelper.isUserAuthorized(request,resourceOwnerUserId)) { + String userId = getUserIdFromRequest(request); + String serviceId = id; + if(HandlersHelper.isLoggedIn(request)) { + if(HandlersHelper.isServiceController(userId, serviceId)) { String arg1 = "--"+command; String arg2 = id; - String userId = getUserIdFromRequest(request); String cp = System.getProperty("java.class.path"); String java = "/bin/java"; String jclass = "org.apache.uima.ducc.cli.DuccServiceApi"; @@ -4345,21 +4343,27 @@ public class DuccHandler extends DuccAbs case Administrator: String arg3 = "--"+SpecificationProperties.key_role_administrator; String[] arglistAdministrator = { "-u", userId, "--", jhome+java, "-cp", cp, jclass, arg1, arg2, arg3 }; + duccLogger.debug(methodName, null, String.join(" ", arglistAdministrator)); result = DuccAsUser.duckling(userId, arglistAdministrator); + duccLogger.debug(methodName, null, result); response.getWriter().println(result); break; case User: default: String[] arglistUser = { "-u", userId, "--", jhome+java, "-cp", cp, jclass, arg1, arg2 }; + duccLogger.debug(methodName, null, String.join(" ", arglistUser)); result = DuccAsUser.duckling(userId, arglistUser); + duccLogger.debug(methodName, null, result); response.getWriter().println(result); break; } } + else { + duccLogger.debug(methodName, null, "not logged in"); + } } else { - text = "id "+value+" not found"; - duccLogger.debug(methodName, null, messages.fetch(text)); + duccLogger.debug(methodName, null, "not service controller"); } } catch(Exception e) { Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java?rev=1851161&r1=1851160&r2=1851161&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java Sat Jan 12 12:41:59 2019 @@ -1091,7 +1091,7 @@ public class DuccHandlerClassic extends if(service.isRegistered()) { if(buttonsEnabled) { if(service.isDisabled()) { - sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_enable("+sid+")\" value=\"Enable\" "+getDisabledWithHover(request,user)+"/>"); + sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_enable("+sid+")\" value=\"Enable\" "+getDisabledWithHover(request,user,service)+"/>"); } } } @@ -1102,12 +1102,12 @@ public class DuccHandlerClassic extends if(buttonsEnabled) { if(service.isPingOnly()) { if(service.isPingActive()) { - sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user)+"/>"); + sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user,service)+"/>"); } } else { if(deployments != 0) { - sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user)+"/>"); + sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user,service)+"/>"); } } } Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java?rev=1851161&r1=1851160&r2=1851161&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java Sat Jan 12 12:41:59 2019 @@ -1496,7 +1496,7 @@ public class DuccHandlerJsonFormat exten if(service.isRegistered()) { if(buttonsEnabled) { if(service.isDisabled()) { - col.append("<input type=\"button\" onclick=\"ducc_confirm_service_enable("+sid+")\" value=\"Enable\" "+getDisabledWithHover(request,user)+"/>"); + col.append("<input type=\"button\" onclick=\"ducc_confirm_service_enable("+sid+")\" value=\"Enable\" "+getDisabledWithHover(request,user,service)+"/>"); } } } @@ -1509,12 +1509,12 @@ public class DuccHandlerJsonFormat exten if(buttonsEnabled) { if(service.isPingOnly()) { if(service.isPingActive()) { - col.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user)+"/>"); + col.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user,service)+"/>"); } } else { if(deployments != 0) { - col.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user)+"/>"); + col.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user,service)+"/>"); } } } Modified: uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/HandlersHelper.java URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/HandlersHelper.java?rev=1851161&r1=1851160&r2=1851161&view=diff ============================================================================== --- uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/HandlersHelper.java (original) +++ uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/HandlersHelper.java Sat Jan 12 12:41:59 2019 @@ -68,6 +68,41 @@ public class HandlersHelper { return retVal; } + public static boolean isServiceController(String user, String serviceId) { + String methodName = "isServiceController"; + duccLogger.trace(methodName, null, messages.fetch("enter")); + boolean retVal = false; + duccLogger.debug(methodName, null, user, serviceId); + try { + ServicesRegistry servicesRegistry = ServicesRegistry.getInstance(); + ServicesRegistryMapPayload payload = servicesRegistry.findServiceById(serviceId); + Properties meta = payload.meta; + Properties svc = payload.svc; + if(isServiceOwner(user,meta)) { + retVal = true; + duccLogger.debug(methodName, null, "owner"); + } + else if(isServiceAdministrator(user,svc)) { + retVal = true; + duccLogger.debug(methodName, null, "admin"); + } + else if(isDuccAdministrator(user,meta)) { + retVal = true; + duccLogger.debug(methodName, null, "ducc admin"); + } + } + catch(Exception e) { + duccLogger.error(methodName, null, e); + } + duccLogger.trace(methodName, null, messages.fetch("exit")); + return retVal; + } + + public static boolean isLoggedIn(HttpServletRequest request) { + boolean retVal = duccWebSessionManager.isAuthentic(request); + return retVal; + } + public static AuthorizationStatus getAuthorizationStatus(HttpServletRequest request, String resourceOwnerUserid) { String methodName = "getAuthorizationStatus"; duccLogger.trace(methodName, null, messages.fetch("enter")); @@ -178,26 +213,35 @@ public class HandlersHelper { duccLogger.debug(location, getDuccId(meta), "user="+reqUser+" "+retVal); } } + else { + duccLogger.debug(location, getDuccId(meta), "svcOwner="+svcOwner+" "+retVal); + } + } + else { + duccLogger.debug(location, getDuccId(meta), "meta="+meta+" "+retVal); } } + else { + duccLogger.debug(location, getDuccId(meta), "user="+reqUser+" "+retVal); + } return retVal; } /** * Check if user is a service administrator */ - private static boolean isServiceAdministrator(String reqUser, Properties meta) { + private static boolean isServiceAdministrator(String reqUser, Properties svc) { String location = "isServiceAdministrator"; boolean retVal = false; if(reqUser != null) { - if(meta != null) { - String svcAdministrators = meta.getProperty(IServicesRegistry.administrators); + if(svc != null) { + String svcAdministrators = svc.getProperty(IServicesRegistry.administrators); if(svcAdministrators != null) { String[] tokens = svcAdministrators.split("\\s+"); for(String token : tokens) { if(reqUser.trim().equals(token.trim())) { retVal = true; - duccLogger.debug(location, getDuccId(meta), "user="+reqUser+" "+retVal); + duccLogger.debug(location, getDuccId(svc), "user="+reqUser+" "+retVal); break; } }