You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/01/12 16:33:38 UTC

[tomcat] branch main updated: Removed unused class

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 8a9ce361bb Removed unused class
8a9ce361bb is described below

commit 8a9ce361bb587b7173efd2e0be8bdedb4e5c1d21
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jan 12 16:33:28 2023 +0000

    Removed unused class
---
 .../catalina/security/LocalStrings.properties      |   2 -
 .../catalina/security/LocalStrings_es.properties   |   2 -
 .../catalina/security/LocalStrings_fr.properties   |   2 -
 .../catalina/security/LocalStrings_ja.properties   |   2 -
 .../catalina/security/LocalStrings_ko.properties   |   2 -
 .../security/LocalStrings_zh_CN.properties         |   2 -
 .../org/apache/catalina/security/SecurityUtil.java | 412 ---------------------
 7 files changed, 424 deletions(-)

diff --git a/java/org/apache/catalina/security/LocalStrings.properties b/java/org/apache/catalina/security/LocalStrings.properties
index 1c604fd388..f685b9a2ed 100644
--- a/java/org/apache/catalina/security/LocalStrings.properties
+++ b/java/org/apache/catalina/security/LocalStrings.properties
@@ -20,5 +20,3 @@ SecurityListener.checkUmaskNone=No umask setting was found in system property [{
 SecurityListener.checkUmaskParseFail=Failed to parse value [{0}] as a valid umask.
 SecurityListener.checkUmaskSkip=Unable to determine umask. It appears Tomcat is running on Windows so skip the umask check.
 SecurityListener.checkUserWarning=Start attempted while running as user [{0}]. Running Tomcat as this user has been blocked by the Lifecycle listener org.apache.catalina.security.SecurityListener (usually configured in CATALINA_BASE/conf/server.xml)
-
-SecurityUtil.doAsPrivilege=An exception occurs when running the PrivilegedExceptionAction block.
diff --git a/java/org/apache/catalina/security/LocalStrings_es.properties b/java/org/apache/catalina/security/LocalStrings_es.properties
index a3f2be9b30..fb08237a53 100644
--- a/java/org/apache/catalina/security/LocalStrings_es.properties
+++ b/java/org/apache/catalina/security/LocalStrings_es.properties
@@ -18,5 +18,3 @@ SecurityListener.checkUmaskNone=No se ha hallado valor de umask en propiedad de
 SecurityListener.checkUmaskParseFail=No pude anallizar el valor [{0}] como in válido umask.
 SecurityListener.checkUmaskSkip=No pude determinar umask. Parece que Tomcat se está ejecutando en Windows, por lo que se salta el chequeo de umsak.
 SecurityListener.checkUserWarning=Se ha intentado arrancar mientras se ejecutaba como usuario [{0}]. Ejecutando Tomcat como este usuario user ha sido bloqueado por el oyente de Ciclos de Vida org.apache.catalina.security.SecurityListener (normalmente configurado en  CATALINA_BASE/conf/server.xml)
-
-SecurityUtil.doAsPrivilege=Ha tenido lugar una excepción al ejecutar el bloque PrivilegedExceptionAction.
diff --git a/java/org/apache/catalina/security/LocalStrings_fr.properties b/java/org/apache/catalina/security/LocalStrings_fr.properties
index d3861dbbf0..3aff0bed5e 100644
--- a/java/org/apache/catalina/security/LocalStrings_fr.properties
+++ b/java/org/apache/catalina/security/LocalStrings_fr.properties
@@ -19,6 +19,4 @@ SecurityListener.checkUmaskParseFail=Impossible de traiter la valeur [{0}] comme
 SecurityListener.checkUmaskSkip=Impossible de déterminer le "umask".  Il semble que Tomcat tourne ici sous Windows, donc évitez la vérification du "umask".
 SecurityListener.checkUserWarning=Tentative de démarrage avec l''utilisateur [{0}}, qui a été bloquée par l''écouteur org.apache.catalina.security.SecurityListener (configuré habituellement dans CATALINA_BASE/conf/server.xml)
 
-SecurityUtil.doAsPrivilege=Une exception s'est produite lors de l'exécution du bloc "PrivilegedExceptionAction".
-
 listener.notServer=Ce listener ne peut être ajouté qu''à des éléments Server, mais est dans [{0}]
diff --git a/java/org/apache/catalina/security/LocalStrings_ja.properties b/java/org/apache/catalina/security/LocalStrings_ja.properties
index df0614f353..0896f452fc 100644
--- a/java/org/apache/catalina/security/LocalStrings_ja.properties
+++ b/java/org/apache/catalina/security/LocalStrings_ja.properties
@@ -19,6 +19,4 @@ SecurityListener.checkUmaskParseFail=値[{0}]を有効なumaskとして解析で
 SecurityListener.checkUmaskSkip=umask を取得できません。Tomcat を Windows で実行するときは umask をチェックしません。
 SecurityListener.checkUserWarning=ユーザー[{0}]として実行中に開始しようとしました。 このユーザーでのTomcatの実行はライフサイクルリスナーorg.apache.catalina.security.SecurityListener(通常はCATALINA_BASE/conf /server.xmlで構成されている)によってブロックされています。
 
-SecurityUtil.doAsPrivilege=PrivilegedExceptionActionブロックを実行中に例外が発生しました。
-
 listener.notServer=このlistenerはServer要素内にのみネストする必要がありますが、[{0}] にあります。
diff --git a/java/org/apache/catalina/security/LocalStrings_ko.properties b/java/org/apache/catalina/security/LocalStrings_ko.properties
index 0448fb2dc0..9e93b172ef 100644
--- a/java/org/apache/catalina/security/LocalStrings_ko.properties
+++ b/java/org/apache/catalina/security/LocalStrings_ko.properties
@@ -19,6 +19,4 @@ SecurityListener.checkUmaskParseFail=값 [{0}]이(가) 유효한 umask 값이 
 SecurityListener.checkUmaskSkip=umask를 결정할 수 없습니다. Tomcat이 Windows에서 실행되는 것으로 보이므로, umask 점검을 건너뜁니다.
 SecurityListener.checkUserWarning=사용자 [{0}](으)로서 실행하면서, 프로그램 시작이 시도 되었습니다. 이 사용자로서 Tomcat을 실행하는 것은, Lifecycle 리스너인 org.apache.catalina.security.SecurityListener (보통 CATALINA_BASE/conf/server.xml에서 설정)에 의해 차단되었습니다.
 
-SecurityUtil.doAsPrivilege=PrivilegedExceptionAction 블록을 실행하는 중 예외가 발생했습니다.
-
 listener.notServer=리스너 엘리먼트는 서버 엘리먼트 내에 위치해야 합니다만, 현재 [{0}] 내에 있습니다.
diff --git a/java/org/apache/catalina/security/LocalStrings_zh_CN.properties b/java/org/apache/catalina/security/LocalStrings_zh_CN.properties
index 8a44aea07e..2198a3dac8 100644
--- a/java/org/apache/catalina/security/LocalStrings_zh_CN.properties
+++ b/java/org/apache/catalina/security/LocalStrings_zh_CN.properties
@@ -19,6 +19,4 @@ SecurityListener.checkUmaskParseFail=无法将值[{0}]分析为有效的umask。
 SecurityListener.checkUmaskSkip=无法确定权限。这表示 Tomcat 正在 Windows 上运行,所以跳过权限检查。
 SecurityListener.checkUserWarning=以用户[{0}]身份运行时尝试启动。作为此用户运行Tomcat已被生命周期侦听器org.apache.catalina.security.security listener(通常在catalina_BASE/conf/server.xml中配置)阻止
 
-SecurityUtil.doAsPrivilege=运行privilegedexception块时发生异常。
-
 listener.notServer=此侦听器只能嵌套在 Server 元素中,但位于 [{0}] 中。\n
diff --git a/java/org/apache/catalina/security/SecurityUtil.java b/java/org/apache/catalina/security/SecurityUtil.java
deleted file mode 100644
index 5a245217b8..0000000000
--- a/java/org/apache/catalina/security/SecurityUtil.java
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
- * 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.catalina.security;
-
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.Principal;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.security.auth.Subject;
-
-import jakarta.servlet.Filter;
-import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.UnavailableException;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpSession;
-
-import org.apache.catalina.Globals;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import org.apache.tomcat.util.ExceptionUtils;
-import org.apache.tomcat.util.res.StringManager;
-/**
- * This utility class associates a <code>Subject</code> to the current
- * <code>AccessControlContext</code>. When a <code>SecurityManager</code> is
- * used, the container will always associate the called thread with an
- * AccessControlContext containing only the principal of the requested
- * Servlet/Filter.
- *
- * This class uses reflection to invoke the methods.
- */
-
-public final class SecurityUtil{
-
-    // Note that indexes overlap.
-    // A Servlet uses "init", "service", "event", "destroy".
-    // A Filter uses "doFilter", "doFilterEvent", "destroy".
-    private static final int INIT= 0;
-    private static final int SERVICE = 1;
-    private static final int DOFILTER = 1;
-    private static final int EVENT = 2;
-    private static final int DOFILTEREVENT = 2;
-    private static final int DESTROY = 3;
-
-    private static final String INIT_METHOD = "init";
-    private static final String DOFILTER_METHOD = "doFilter";
-    private static final String SERVICE_METHOD = "service";
-    private static final String EVENT_METHOD = "event";
-    private static final String DOFILTEREVENT_METHOD = "doFilterEvent";
-    private static final String DESTROY_METHOD = "destroy";
-
-    /**
-     * Cache every class for which we are creating methods.
-     */
-    private static final Map<Class<?>,Method[]> classCache = new ConcurrentHashMap<>();
-
-    private static final Log log = LogFactory.getLog(SecurityUtil.class);
-
-    /**
-     * The string resources for this package.
-     */
-    private static final StringManager sm =
-        StringManager.getManager(Constants.PACKAGE);
-
-
-    /**
-     * Perform work as a particular <code>Subject</code>. Here the work
-     * will be granted to a <code>null</code> subject.
-     *
-     * @param methodName the method to apply the security restriction
-     * @param targetObject the <code>Servlet</code> on which the method will
-     * be called.
-     * @throws Exception an execution error occurred
-     */
-    public static void doAsPrivilege(final String methodName,
-                                     final Servlet targetObject) throws Exception {
-         doAsPrivilege(methodName, targetObject, null, null, null);
-    }
-
-
-    /**
-     * Perform work as a particular <code>Subject</code>. Here the work
-     * will be granted to a <code>null</code> subject.
-     *
-     * @param methodName the method to apply the security restriction
-     * @param targetObject the <code>Servlet</code> on which the method will
-     * be called.
-     * @param targetType <code>Class</code> array used to instantiate a
-     * <code>Method</code> object.
-     * @param targetArguments <code>Object</code> array contains the runtime
-     * parameters instance.
-     * @throws Exception an execution error occurred
-     */
-    public static void doAsPrivilege(final String methodName,
-                                     final Servlet targetObject,
-                                     final Class<?>[] targetType,
-                                     final Object[] targetArguments)
-        throws Exception {
-
-         doAsPrivilege(methodName,
-                       targetObject,
-                       targetType,
-                       targetArguments,
-                       null);
-    }
-
-
-    /**
-     * Perform work as a particular <code>Subject</code>. Here the work
-     * will be granted to a <code>null</code> subject.
-     *
-     * @param methodName the method to apply the security restriction
-     * @param targetObject the <code>Servlet</code> on which the method will
-     *  be called.
-     * @param targetParameterTypes <code>Class</code> array used to instantiate a
-     *  <code>Method</code> object.
-     * @param targetArguments <code>Object</code> array contains the
-     *  runtime parameters instance.
-     * @param principal the <code>Principal</code> to which the security
-     *  privilege applies
-     * @throws Exception an execution error occurred
-     */
-    public static void doAsPrivilege(final String methodName,
-                                     final Servlet targetObject,
-                                     final Class<?>[] targetParameterTypes,
-                                     final Object[] targetArguments,
-                                     Principal principal)
-        throws Exception {
-
-        Method method = null;
-        Method[] methodsCache = classCache.get(Servlet.class);
-        if(methodsCache == null) {
-            method = createMethodAndCacheIt(null,
-                                            Servlet.class,
-                                            methodName,
-                                            targetParameterTypes);
-        } else {
-            method = findMethod(methodsCache, methodName);
-            if (method == null) {
-                method = createMethodAndCacheIt(methodsCache,
-                                                Servlet.class,
-                                                methodName,
-                                                targetParameterTypes);
-            }
-        }
-
-        execute(method, targetObject, targetArguments, principal);
-    }
-
-
-    /**
-     * Perform work as a particular <code>Subject</code>. Here the work
-     * will be granted to a <code>null</code> subject.
-     *
-     * @param methodName the method to apply the security restriction
-     * @param targetObject the <code>Filter</code> on which the method will
-     *  be called.
-     * @throws Exception an execution error occurred
-     */
-    public static void doAsPrivilege(final String methodName,
-                                     final Filter targetObject)
-        throws Exception {
-
-         doAsPrivilege(methodName, targetObject, null, null);
-    }
-
-
-    /**
-     * Perform work as a particular <code>Subject</code>. Here the work
-     * will be granted to a <code>null</code> subject.
-     *
-     * @param methodName the method to apply the security restriction
-     * @param targetObject the <code>Filter</code> on which the method will
-     *  be called.
-     * @param targetType <code>Class</code> array used to instantiate a
-     *  <code>Method</code> object.
-     * @param targetArguments <code>Object</code> array contains the
-     *  runtime parameters instance.
-     * @throws Exception an execution error occurred
-     */
-    public static void doAsPrivilege(final String methodName,
-                                     final Filter targetObject,
-                                     final Class<?>[] targetType,
-                                     final Object[] targetArguments)
-        throws Exception {
-
-        doAsPrivilege(
-                methodName, targetObject, targetType, targetArguments, null);
-    }
-
-    /**
-     * Perform work as a particular <code>Subject</code>. Here the work
-     * will be granted to a <code>null</code> subject.
-     *
-     * @param methodName the method to apply the security restriction
-     * @param targetObject the <code>Filter</code> on which the method will
-     *  be called.
-     * @param targetParameterTypes <code>Class</code> array used to instantiate a
-     *  <code>Method</code> object.
-     * @param targetParameterValues <code>Object</code> array contains the
-     *  runtime parameters instance.
-     * @param principal the <code>Principal</code> to which the security
-     *  privilege applies
-     * @throws Exception an execution error occurred
-     */
-    public static void doAsPrivilege(final String methodName,
-                                     final Filter targetObject,
-                                     final Class<?>[] targetParameterTypes,
-                                     final Object[] targetParameterValues,
-                                     Principal principal)
-        throws Exception {
-
-        Method method = null;
-        Method[] methodsCache = classCache.get(Filter.class);
-        if(methodsCache == null) {
-            method = createMethodAndCacheIt(null,
-                                            Filter.class,
-                                            methodName,
-                                            targetParameterTypes);
-        } else {
-            method = findMethod(methodsCache, methodName);
-            if (method == null) {
-                method = createMethodAndCacheIt(methodsCache,
-                                                Filter.class,
-                                                methodName,
-                                                targetParameterTypes);
-            }
-        }
-
-        execute(method, targetObject, targetParameterValues, principal);
-    }
-
-
-    /**
-     * Perform work as a particular <code>Subject</code>. Here the work
-     * will be granted to a <code>null</code> subject.
-     *
-     * @param method the method to apply the security restriction
-     * @param targetObject the <code>Servlet</code> on which the method will
-     *  be called.
-     * @param targetArguments <code>Object</code> array contains the
-     *  runtime parameters instance.
-     * @param principal the <code>Principal</code> to which the security
-     *  privilege applies
-     * @throws Exception an execution error occurred
-     */
-    private static void execute(final Method method,
-                                final Object targetObject,
-                                final Object[] targetArguments,
-                                Principal principal)
-        throws Exception {
-
-        try{
-            Subject subject = null;
-            PrivilegedExceptionAction<Void> pea =
-                    () -> {
-                       method.invoke(targetObject, targetArguments);
-                       return null;
-                    };
-
-            // The first argument is always the request object
-            if (targetArguments != null
-                    && targetArguments[0] instanceof HttpServletRequest){
-                HttpServletRequest request =
-                    (HttpServletRequest)targetArguments[0];
-
-                boolean hasSubject = false;
-                HttpSession session = request.getSession(false);
-                if (session != null){
-                    subject =
-                        (Subject)session.getAttribute(Globals.SUBJECT_ATTR);
-                    hasSubject = (subject != null);
-                }
-
-                if (subject == null){
-                    subject = new Subject();
-
-                    if (principal != null){
-                        subject.getPrincipals().add(principal);
-                    }
-                }
-
-                if (session != null && !hasSubject) {
-                    session.setAttribute(Globals.SUBJECT_ATTR, subject);
-                }
-            }
-
-            Subject.doAsPrivileged(subject, pea, null);
-        } catch( PrivilegedActionException pe) {
-            Throwable e;
-            if (pe.getException() instanceof InvocationTargetException) {
-                e = pe.getException().getCause();
-                ExceptionUtils.handleThrowable(e);
-            } else {
-                e = pe;
-            }
-
-            if (log.isDebugEnabled()){
-                log.debug(sm.getString("SecurityUtil.doAsPrivilege"), e);
-            }
-
-            if (e instanceof UnavailableException) {
-                throw (UnavailableException) e;
-            } else if (e instanceof ServletException) {
-                throw (ServletException) e;
-            } else if (e instanceof IOException) {
-                throw (IOException) e;
-            } else if (e instanceof RuntimeException) {
-                throw (RuntimeException) e;
-            } else {
-                throw new ServletException(e.getMessage(), e);
-            }
-        }
-    }
-
-
-    /**
-     * Find a method stored within the cache.
-     * @param methodsCache the cache used to store method instance
-     * @param methodName the method to apply the security restriction
-     * @return the method instance, null if not yet created.
-     */
-    private static Method findMethod(Method[] methodsCache,
-                                     String methodName){
-        if (methodName.equals(INIT_METHOD)){
-            return methodsCache[INIT];
-        } else if (methodName.equals(DESTROY_METHOD)){
-            return methodsCache[DESTROY];
-        } else if (methodName.equals(SERVICE_METHOD)){
-            return methodsCache[SERVICE];
-        } else if (methodName.equals(DOFILTER_METHOD)){
-            return methodsCache[DOFILTER];
-        } else if (methodName.equals(EVENT_METHOD)){
-            return methodsCache[EVENT];
-        } else if (methodName.equals(DOFILTEREVENT_METHOD)){
-            return methodsCache[DOFILTEREVENT];
-        }
-        return null;
-    }
-
-
-    /**
-     * Create the method and cache it for further re-use.
-     * @param methodsCache the cache used to store method instance
-     * @param targetType the class on which the method will be called.
-     * @param methodName the method to apply the security restriction
-     * @param parameterTypes <code>Class</code> array used to instantiate a
-     *  <code>Method</code> object.
-     * @return the method instance.
-     * @throws Exception an execution error occurred
-     */
-    private static Method createMethodAndCacheIt(Method[] methodsCache,
-                                                 Class<?> targetType,
-                                                 String methodName,
-                                                 Class<?>[] parameterTypes)
-            throws Exception {
-
-        if (methodsCache == null) {
-            methodsCache = new Method[4];
-        }
-
-        Method method = targetType.getMethod(methodName, parameterTypes);
-
-        if (methodName.equals(INIT_METHOD)){
-            methodsCache[INIT] = method;
-        } else if (methodName.equals(DESTROY_METHOD)){
-            methodsCache[DESTROY] = method;
-        } else if (methodName.equals(SERVICE_METHOD)){
-            methodsCache[SERVICE] = method;
-        } else if (methodName.equals(DOFILTER_METHOD)){
-            methodsCache[DOFILTER] = method;
-        } else if (methodName.equals(EVENT_METHOD)){
-            methodsCache[EVENT] = method;
-        } else if (methodName.equals(DOFILTEREVENT_METHOD)){
-            methodsCache[DOFILTEREVENT] = method;
-        }
-
-        classCache.put(targetType, methodsCache);
-
-        return method;
-    }
-
-
-    /**
-     * Remove the object from the cache.
-     *
-     * @param cachedObject The object to remove
-     */
-    public static void remove(Object cachedObject){
-        classCache.remove(cachedObject);
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org