Java Code Examples for org.apache.jasper.security.SecurityUtil#isPackageProtectionEnabled()

The following examples show how to use org.apache.jasper.security.SecurityUtil#isPackageProtectionEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PageContextImpl.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public Object getAttribute(final String name, final int scope) {

        if (name == null) {
            throw new NullPointerException(
                    Localizer.getMessage("jsp.error.attribute.null_name"));
        }

        if (SecurityUtil.isPackageProtectionEnabled()){
            return AccessController.doPrivileged(new PrivilegedAction<Object>(){
                public Object run(){
                    return doGetAttribute(name, scope);
                }
            });
        } else {
            return doGetAttribute(name, scope);
        }

    }
 
Example 2
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public int getAttributesScope(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (AccessController
                .doPrivileged(new PrivilegedAction<Integer>() {
                    @Override
                    public Integer run() {
                        return Integer.valueOf(doGetAttributeScope(name));
                    }
                })).intValue();
    } else {
        return doGetAttributeScope(name);
    }
}
 
Example 3
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setAttribute(final String name, final Object attribute) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doSetAttribute(name, attribute);
                return null;
            }
        });
    } else {
        doSetAttribute(name, attribute);
    }
}
 
Example 4
Source File: PageContextImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Object findAttribute(final String name) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return AccessController.doPrivileged(
                new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                if (name == null) {
                    throw new NullPointerException(Localizer
                            .getMessage("jsp.error.attribute.null_name"));
                }

                return doFindAttribute(name);
            }
        });
    } else {
        if (name == null) {
            throw new NullPointerException(Localizer
                    .getMessage("jsp.error.attribute.null_name"));
        }

        return doFindAttribute(name);
    }
}
 
Example 5
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void removeAttribute(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doRemoveAttribute(name);
                return null;
            }
        });
    } else {
        doRemoveAttribute(name);
    }
}
 
Example 6
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void forward(final String relativeUrlPath) throws ServletException,
        IOException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Void>() {
                @Override
                public Void run() throws Exception {
                    doForward(relativeUrlPath);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            Exception ex = e.getException();
            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (ServletException) ex;
            }
        }
    } else {
        doForward(relativeUrlPath);
    }
}
 
Example 7
Source File: PageContextImpl.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public void setAttribute(final String name, final Object attribute) {

        if (name == null) {
            throw new NullPointerException(
                    Localizer.getMessage("jsp.error.attribute.null_name"));
        }

        if (SecurityUtil.isPackageProtectionEnabled()){
            AccessController.doPrivileged(new PrivilegedAction<Object>(){
                public Object run(){
                    doSetAttribute(name, attribute);
                    return null;
                }
            });
        } else {
            doSetAttribute(name, attribute);
        }
    }
 
Example 8
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void removeAttribute(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doRemoveAttribute(name);
                return null;
            }
        });
    } else {
        doRemoveAttribute(name);
    }
}
 
Example 9
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public int getAttributesScope(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (AccessController
                .doPrivileged(new PrivilegedAction<Integer>() {
                    @Override
                    public Integer run() {
                        return Integer.valueOf(doGetAttributeScope(name));
                    }
                })).intValue();
    } else {
        return doGetAttributeScope(name);
    }
}
 
Example 10
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void removeAttribute(final String name, final int scope) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }
    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doRemoveAttribute(name, scope);
                return null;
            }
        });
    } else {
        doRemoveAttribute(name, scope);
    }
}
 
Example 11
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setAttribute(final String name, final Object o, final int scope) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doSetAttribute(name, o, scope);
                return null;
            }
        });
    } else {
        doSetAttribute(name, o, scope);
    }

}
 
Example 12
Source File: PageContextImpl.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public Object findAttribute(final String name) {
    if (SecurityUtil.isPackageProtectionEnabled()){
        return AccessController.doPrivileged(new PrivilegedAction<Object>(){
            public Object run(){
                if (name == null) {
                    throw new NullPointerException(
                            Localizer.getMessage("jsp.error.attribute.null_name"));
                }

                return doFindAttribute(name);
            }
        });
    } else {
        if (name == null) {
            throw new NullPointerException(
                    Localizer.getMessage("jsp.error.attribute.null_name"));
        }

        return doFindAttribute(name);
    }
}
 
Example 13
Source File: PageContextImpl.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public Object getAttribute(final String name) {

        if (name == null) {
            throw new NullPointerException(
                    Localizer.getMessage("jsp.error.attribute.null_name"));
        }

        if (SecurityUtil.isPackageProtectionEnabled()){
            return AccessController.doPrivileged(new PrivilegedAction<Object>(){
                public Object run(){
                    return doGetAttribute(name);
                }
            });
        } else {
            return doGetAttribute(name);
        }

    }
 
Example 14
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Enumeration<String> getAttributeNamesInScope(final int scope) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return AccessController.doPrivileged(
                new PrivilegedAction<Enumeration<String>>() {
                    @Override
                    public Enumeration<String> run() {
                        return doGetAttributeNamesInScope(scope);
                    }
                });
    } else {
        return doGetAttributeNamesInScope(scope);
    }
}
 
Example 15
Source File: PageContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void handlePageException(final Throwable t) throws IOException,
        ServletException {
    if (t == null)
        throw new NullPointerException("null Throwable");

    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Void>() {
                @Override
                public Void run() throws Exception {
                    doHandlePageException(t);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            Exception ex = e.getException();
            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (ServletException) ex;
            }
        }
    } else {
        doHandlePageException(t);
    }

}
 
Example 16
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void handlePageException(final Throwable t) throws IOException,
        ServletException {
    if (t == null)
        throw new NullPointerException("null Throwable");

    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Void>() {
                @Override
                public Void run() throws Exception {
                    doHandlePageException(t);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            Exception ex = e.getException();
            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (ServletException) ex;
            }
        }
    } else {
        doHandlePageException(t);
    }

}
 
Example 17
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public Enumeration<String> getAttributeNamesInScope(final int scope) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return AccessController.doPrivileged(
                new PrivilegedAction<Enumeration<String>>() {
                    @Override
                    public Enumeration<String> run() {
                        return doGetAttributeNamesInScope(scope);
                    }
                });
    } else {
        return doGetAttributeNamesInScope(scope);
    }
}
 
Example 18
Source File: ProtectedFunctionMapper.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * Creates an instance for this class, and stores the Method for
    * the given EL function prefix and name. This method is used for
    * the case when there is only one function in the EL expression.
    *
    * @param fnQName The EL function qualified name (including prefix)
    * @param c The class containing the Java method
    * @param methodName The name of the Java method
    * @param args The arguments of the Java method
    * @throws RuntimeException if no method with the given signature
    *     could be found.
    */
   public static ProtectedFunctionMapper getMapForFunction(
	String fnQName, final Class<?> c,
               final String methodName, final Class<?>[] args )
   {
       java.lang.reflect.Method method;
       ProtectedFunctionMapper funcMapper;
       if (SecurityUtil.isPackageProtectionEnabled()){
           funcMapper = AccessController.doPrivileged(
               new PrivilegedAction<ProtectedFunctionMapper>(){
               public ProtectedFunctionMapper run() {
                   return new ProtectedFunctionMapper();
               }
           });

           try{
               method = AccessController.doPrivileged(
                   new PrivilegedExceptionAction<Method>(){
                   public Method run() throws Exception{
                       return c.getDeclaredMethod(methodName, args);
                   }
               });
           } catch (PrivilegedActionException ex){
               throw new RuntimeException(
                   "Invalid function mapping - no such method: "
                   + ex.getException().getMessage());
           }
       } else {
    funcMapper = new ProtectedFunctionMapper();
            try {
               method = c.getDeclaredMethod(methodName, args);
           } catch( NoSuchMethodException e ) {
               throw new RuntimeException(
                   "Invalid function mapping - no such method: "
                   + e.getMessage());
           }
       }
       funcMapper.theMethod = method;
return funcMapper;
   }
 
Example 19
Source File: PageContextImpl.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public void handlePageException(final Throwable t)
    throws IOException, ServletException
{
    if (t == null)
        throw new NullPointerException("null Throwable");

    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
                public Object run() throws Exception{
                    doHandlePageException(t);
                    return null;
                }
            });
        } catch (PrivilegedActionException e){
            Exception ex =  e.getException();
            if (ex instanceof IOException){
                throw (IOException)ex;
            } else {
                throw (ServletException)ex;
            }
        }
    } else {
        doHandlePageException(t);
    }

}
 
Example 20
Source File: ProtectedFunctionMapper.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * Stores a mapping from the given EL function prefix and name to 
    * the given Java method.
    *
    * @param fnQName The EL function qualified name (including prefix)
    * @param c The class containing the Java method
    * @param methodName The name of the Java method
    * @param args The arguments of the Java method
    * @throws RuntimeException if no method with the given signature
    *     could be found.
    */
   public void mapFunction(String fnQName, final Class<?> c,
		    final String methodName, final Class<?>[] args ) 
   {
java.lang.reflect.Method method;
       if (SecurityUtil.isPackageProtectionEnabled()){
           try{
               method = AccessController.doPrivileged(
               new PrivilegedExceptionAction<Method>(){
                   public Method run() throws Exception{
                       return c.getDeclaredMethod(methodName, args);
                   }                
               });      
           } catch (PrivilegedActionException ex){
               throw new RuntimeException(
                   "Invalid function mapping - no such method: "
	    + ex.getException().getMessage());               
           }
       } else {
            try {
               method = c.getDeclaredMethod(methodName, args);
           } catch( NoSuchMethodException e ) {
               throw new RuntimeException(
                   "Invalid function mapping - no such method: "
	    + e.getMessage());
           }
       }

this.fnmap.put(fnQName, method );
   }