Java 类org.apache.catalina.security.SecurityUtil 实例源码

项目:tomcat7    文件:StandardManager.java   
@Override
public void load() throws ClassNotFoundException, IOException {
    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            AccessController.doPrivileged( new PrivilegedDoLoad() );
        } catch (PrivilegedActionException ex){
            Exception exception = ex.getException();
            if (exception instanceof ClassNotFoundException) {
                throw (ClassNotFoundException)exception;
            } else if (exception instanceof IOException) {
                throw (IOException)exception;
            }
            if (log.isDebugEnabled()) {
                log.debug("Unreported exception in load() ", exception);
            }
        }
    } else {
        doLoad();
    }
}
项目:tomcat7    文件:PersistentManagerBase.java   
/**
 * Remove this Session from the active Sessions for this Manager,
 * and from the Store.
 *
 * @param id Session's id to be removed
 */    
protected void removeSession(String id){
    try {
        if (SecurityUtil.isPackageProtectionEnabled()){
            try{
                AccessController.doPrivileged(new PrivilegedStoreRemove(id));
            }catch(PrivilegedActionException ex){
                Exception exception = ex.getException();
                log.error("Exception in the Store during removeSession: "
                          + exception, exception);
            }
        } else {
             store.remove(id);
        }               
    } catch (IOException e) {
        log.error("Exception removing session  " + e.getMessage(), e);
    }        
}
项目:tomcat7    文件:StandardSession.java   
/**
 * Return the <code>HttpSession</code> for which this object
 * is the facade.
 */
@Override
public HttpSession getSession() {

    if (facade == null){
        if (SecurityUtil.isPackageProtectionEnabled()){
            final StandardSession fsession = this;
            facade = AccessController.doPrivileged(
                    new PrivilegedAction<StandardSessionFacade>(){
                @Override
                public StandardSessionFacade run(){
                    return new StandardSessionFacade(fsession);
                }
            });
        } else {
            facade = new StandardSessionFacade(this);
        }
    }
    return (facade);

}
项目:apache-tomcat-7.0.73-with-comment    文件:PersistentManagerBase.java   
/**
 * Clear all sessions from the Store.
 */
public void clearStore() {

    if (store == null)
        return;

    try {     
        if (SecurityUtil.isPackageProtectionEnabled()){
            try{
                AccessController.doPrivileged(new PrivilegedStoreClear());
            }catch(PrivilegedActionException ex){
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception,
                        exception);
            }
        } else {
            store.clear();
        }
    } catch (IOException e) {
        log.error("Exception clearing the Store: " + e, e);
    }

}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardSession.java   
/**
 * Return the <code>HttpSession</code> for which this object
 * is the facade.
 */
@Override
public HttpSession getSession() {

    if (facade == null){
        if (SecurityUtil.isPackageProtectionEnabled()){
            final StandardSession fsession = this;
            facade = AccessController.doPrivileged(
                    new PrivilegedAction<StandardSessionFacade>(){
                @Override
                public StandardSessionFacade run(){
                    return new StandardSessionFacade(fsession);
                }
            });
        } else {
            facade = new StandardSessionFacade(this);
        }
    }
    return (facade);

}
项目:tomcat7    文件:Response.java   
public StringBuffer generateCookieString(final Cookie cookie) {
    final StringBuffer sb = new StringBuffer();
    //web application code can receive a IllegalArgumentException
    //from the appendCookieValue invocation
    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run(){
                ServerCookie.appendCookieValue
                    (sb, cookie.getVersion(), cookie.getName(),
                     cookie.getValue(), cookie.getPath(),
                     cookie.getDomain(), cookie.getComment(),
                     cookie.getMaxAge(), cookie.getSecure(),
                     cookie.isHttpOnly());
                return null;
            }
        });
    } else {
        ServerCookie.appendCookieValue
            (sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
                 cookie.getPath(), cookie.getDomain(), cookie.getComment(),
                 cookie.getMaxAge(), cookie.getSecure(),
                 cookie.isHttpOnly());
    }
    return sb;
}
项目:lazycat    文件:ApplicationContextFacade.java   
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public <T extends Servlet> T createServlet(Class<T> c) throws ServletException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            return (T) invokeMethod(context, "createServlet", new Object[] { c });
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            if (t instanceof ServletException) {
                throw (ServletException) t;
            }
            return null;
        }
    } else {
        return context.createServlet(c);
    }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
/**
 * @deprecated As of Java Servlet API 2.1, with no direct replacement.
 */
@Override
@Deprecated
public Servlet getServlet(String name)
    throws ServletException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            return (Servlet) invokeMethod(context, "getServlet", 
                                          new Object[]{name});
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            if (t instanceof ServletException) {
                throw (ServletException) t;
            }
            return null;
        }
    } else {
        return context.getServlet(name);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardManager.java   
@Override
public void load() throws ClassNotFoundException, IOException {
    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            AccessController.doPrivileged( new PrivilegedDoLoad() );
        } catch (PrivilegedActionException ex){
            Exception exception = ex.getException();
            if (exception instanceof ClassNotFoundException) {
                throw (ClassNotFoundException)exception;
            } else if (exception instanceof IOException) {
                throw (IOException)exception;
            }
            if (log.isDebugEnabled()) {
                log.debug("Unreported exception in load() ", exception);
            }
        }
    } else {
        doLoad();
    }
}
项目:lazycat    文件:RequestFacade.java   
@Override
public String[] getParameterValues(String name) {

    if (request == null) {
        throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }

    String[] ret = null;

    /*
     * Clone the returned array only if there is a security manager in
     * place, so that performance won't suffer in the non-secure case
     */
    if (SecurityUtil.isPackageProtectionEnabled()) {
        ret = AccessController.doPrivileged(new GetParameterValuePrivilegedAction(name));
        if (ret != null) {
            ret = ret.clone();
        }
    } else {
        ret = request.getParameterValues(name);
    }

    return ret;
}
项目:tomcat7    文件:ApplicationContextFacade.java   
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public <T extends Servlet> T createServlet(Class<T> c)
throws ServletException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            return (T) invokeMethod(context, "createServlet", 
                                          new Object[]{c});
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            if (t instanceof ServletException) {
                throw (ServletException) t;
            }
            return null;
        }
    } else {
        return context.createServlet(c);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ApplicationContextFacade.java   
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public <T extends Filter> T createFilter(Class<T> c)
throws ServletException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            return (T) invokeMethod(context, "createFilter", 
                                          new Object[]{c});
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            if (t instanceof ServletException) {
                throw (ServletException) t;
            }
            return null;
        }
    } else {
        return context.createFilter(c);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ApplicationContextFacade.java   
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public <T extends Servlet> T createServlet(Class<T> c)
throws ServletException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            return (T) invokeMethod(context, "createServlet", 
                                          new Object[]{c});
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            if (t instanceof ServletException) {
                throw (ServletException) t;
            }
            return null;
        }
    } else {
        return context.createServlet(c);
    }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public <T extends EventListener> T createListener(Class<T> c)
        throws ServletException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            return (T) invokeMethod(context, "createListener", 
                                          new Object[]{c});
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            if (t instanceof ServletException) {
                throw (ServletException) t;
            }
            return null;
        }
    } else {
        return context.createListener(c);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:RequestFacade.java   
@Override
public Cookie[] getCookies() {

    if (request == null) {
        throw new IllegalStateException(
                        sm.getString("requestFacade.nullRequest"));
    }

    Cookie[] ret = null;

    /*
     * Clone the returned array only if there is a security manager
     * in place, so that performance won't suffer in the non-secure case
     */
    if (SecurityUtil.isPackageProtectionEnabled()){
        ret = AccessController.doPrivileged(
            new GetCookiesPrivilegedAction());
        if (ret != null) {
            ret = ret.clone();
        }
    } else {
        ret = request.getCookies();
    }

    return ret;
}
项目:lazycat    文件:PersistentManagerBase.java   
/**
 * Clear all sessions from the Store.
 */
public void clearStore() {

    if (store == null)
        return;

    try {
        if (SecurityUtil.isPackageProtectionEnabled()) {
            try {
                AccessController.doPrivileged(new PrivilegedStoreClear());
            } catch (PrivilegedActionException ex) {
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception, exception);
            }
        } else {
            store.clear();
        }
    } catch (IOException e) {
        log.error("Exception clearing the Store: " + e, e);
    }

}
项目:lams    文件:PersistentManagerBase.java   
/**
 * Remove this Session from the active Sessions for this Manager,
 * and from the Store.
 *
 * @param id Session's id to be removed
 */    
protected void removeSession(String id){
    try {
        if (SecurityUtil.isPackageProtectionEnabled()){
            try{
                AccessController.doPrivileged(new PrivilegedStoreRemove(id));
            }catch(PrivilegedActionException ex){
                Exception exception = ex.getException();
                log.error("Exception in the Store during removeSession: "
                          + exception);
                exception.printStackTrace();                        
            }
        } else {
             store.remove(id);
        }               
    } catch (IOException e) {
        log.error("Exception removing session  " + e.getMessage());
        e.printStackTrace();
    }        
}
项目:lams    文件:StandardSession.java   
/**
 * Return the <code>HttpSession</code> for which this object
 * is the facade.
 */
public HttpSession getSession() {

    if (facade == null){
        if (SecurityUtil.isPackageProtectionEnabled()){
            final StandardSession fsession = this;
            facade = (StandardSessionFacade)AccessController.doPrivileged(new PrivilegedAction(){
                public Object run(){
                    return new StandardSessionFacade(fsession);
                }
            });
        } else {
            facade = new StandardSessionFacade(this);
        }
    }
    return (facade);

}
项目:lams    文件:ApplicationFilterConfig.java   
/**
 * Release the Filter instance associated with this FilterConfig,
 * if there is one.
 */
void release() {

    if (this.filter != null)
    {
        if (Globals.IS_SECURITY_ENABLED) {
            try {
                SecurityUtil.doAsPrivilege("destroy", filter);
            } catch(java.lang.Exception ex){
                context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex);
            }
            SecurityUtil.remove(filter);
        } else {
            filter.destroy();
        }
        if (!context.getIgnoreAnnotations()) {
            try {
                ((StandardContext) context).getInstanceManager().destroyInstance(this.filter);
            } catch (Exception e) {
                context.getLogger().error("ApplicationFilterConfig.preDestroy", e);
            }
        }
    }
    this.filter = null;

 }
项目:lams    文件:ApplicationContextFacade.java   
/**
 * Executes the method of the specified <code>ApplicationContext</code>
 * @param method The method object to be invoked.
 * @param context The AppliationContext object on which the method
 *                   will be invoked
 * @param params The arguments passed to the called method.
 */
private Object executeMethod(final Method method, 
                             final ApplicationContext context,
                             final Object[] params) 
        throws PrivilegedActionException, 
               IllegalAccessException,
               InvocationTargetException {

    if (SecurityUtil.isPackageProtectionEnabled()){
       return AccessController.doPrivileged(new PrivilegedExceptionAction(){
            public Object run() throws IllegalAccessException, InvocationTargetException{
                return method.invoke(context,  params);
            }
        });
    } else {
        return method.invoke(context, params);
    }        
}
项目:lazycat    文件:ApplicationContextFacade.java   
/**
 * @deprecated As of Java Servlet API 2.1, with no direct replacement.
 */
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
@Deprecated
public Enumeration<String> getServletNames() {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (Enumeration<String>) doPrivileged("getServletNames", null);
    } else {
        return context.getServletNames();
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:CoyoteInputStream.java   
@Override
public int available() throws IOException {

    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            Integer result =
                AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Integer>(){

                        @Override
                        public Integer run() throws IOException{
                            Integer integer = Integer.valueOf(ib.available());
                            return integer;
                        }

            });
            return result.intValue();
        } catch(PrivilegedActionException pae){
            Exception e = pae.getException();
            if (e instanceof IOException){
                throw (IOException)e;
            } else {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    } else {
       return ib.available();
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ApplicationContextFacade.java   
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public Map<String, ? extends ServletRegistration> getServletRegistrations() {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (Map<String, ? extends ServletRegistration>) doPrivileged(
                "getServletRegistrations", null);
    } else {
        return context.getServletRegistrations();
    }
}
项目:tomcat7    文件:ResponseFacade.java   
@Override
public void setContentType(String type) {

    if (isCommitted()) {
        return;
    }

    if (SecurityUtil.isPackageProtectionEnabled()){
        AccessController.doPrivileged(new SetContentTypePrivilegedAction(type));
    } else {
        response.setContentType(type);
    }
}
项目:tomcat7    文件:ResponseFacade.java   
@Override
public void flushBuffer()
    throws IOException {

    if (isFinished()) {
        //            throw new IllegalStateException
        //                (/*sm.getString("responseFacade.finished")*/);
        return;
    }

    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Void>(){

                @Override
                public Void run() throws IOException{
                    response.setAppCommitted(true);

                    response.flushBuffer();
                    return null;
                }
            });
        } catch(PrivilegedActionException e){
            Exception ex = e.getException();
            if (ex instanceof IOException){
                throw (IOException)ex;
            }
        }
    } else {
        response.setAppCommitted(true);

        response.flushBuffer();
    }

}
项目:tomcat7    文件:CoyoteInputStream.java   
@Override
public int read()
    throws IOException {
    if (SecurityUtil.isPackageProtectionEnabled()){

        try{
            Integer result =
                AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Integer>(){

                        @Override
                        public Integer run() throws IOException{
                            Integer integer = Integer.valueOf(ib.readByte());
                            return integer;
                        }

            });
            return result.intValue();
        } catch(PrivilegedActionException pae){
            Exception e = pae.getException();
            if (e instanceof IOException){
                throw (IOException)e;
            } else {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    } else {
        return ib.readByte();
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ApplicationContextFacade.java   
@Override
public RequestDispatcher getNamedDispatcher(String name) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (RequestDispatcher) doPrivileged("getNamedDispatcher", 
                                                new Object[]{name});
    } else {
        return context.getNamedDispatcher(name);
    }
}
项目:tomcat7    文件:CoyoteInputStream.java   
@Override
public int read(final byte[] b) throws IOException {

    if (SecurityUtil.isPackageProtectionEnabled()){
        try{
            Integer result =
                AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Integer>(){

                        @Override
                        public Integer run() throws IOException{
                            Integer integer =
                                Integer.valueOf(ib.read(b, 0, b.length));
                            return integer;
                        }

            });
            return result.intValue();
        } catch(PrivilegedActionException pae){
            Exception e = pae.getException();
            if (e instanceof IOException){
                throw (IOException)e;
            } else {
                throw new RuntimeException(e.getMessage() ,e);
            }
        }
    } else {
        return ib.read(b, 0, b.length);
     }
}
项目:lazycat    文件:ApplicationContextFacade.java   
@Override
public void declareRoles(String... roleNames) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        doPrivileged("declareRoles", new Object[] { roleNames });
    } else {
        context.declareRoles(roleNames);
    }
}
项目:tomcat7    文件:RequestFacade.java   
@Override
public HttpSession getSession(boolean create) {

    if (request == null) {
        throw new IllegalStateException(
                        sm.getString("requestFacade.nullRequest"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()){
        return AccessController.
            doPrivileged(new GetSessionPrivilegedAction(create));
    } else {
        return request.getSession(create);
    }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
@Override
public String getMimeType(String file) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (String)doPrivileged("getMimeType", new Object[]{file});
    } else {
        return context.getMimeType(file);
    }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public Set<String> getResourcePaths(String path) {
    if (SecurityUtil.isPackageProtectionEnabled()){
        return (Set<String>)doPrivileged("getResourcePaths",
                new Object[]{path});
    } else {
        return context.getResourcePaths(path);
    }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
@Override
public InputStream getResourceAsStream(String path) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (InputStream) doPrivileged("getResourceAsStream", 
                                          new Object[]{path});
    } else {
        return context.getResourceAsStream(path);
    }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
@Override
public RequestDispatcher getRequestDispatcher(final String path) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (RequestDispatcher) doPrivileged("getRequestDispatcher", 
                                                new Object[]{path});
    } else {
        return context.getRequestDispatcher(path);
    }
}
项目:lams    文件:ApplicationContextFacade.java   
public Object getAttribute(String name) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
       return doPrivileged("getAttribute", new Object[]{name});
   } else {
       return context.getAttribute(name);
   }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
/**
 * @deprecated As of Java Servlet API 2.1, with no direct replacement.
 */
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
@Deprecated
public Enumeration<Servlet> getServlets() {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (Enumeration<Servlet>) doPrivileged("getServlets", null);
    } else {
        return context.getServlets();
    }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
/**
  * @deprecated As of Java Servlet API 2.1, with no direct replacement.
  */
 @Override
 @SuppressWarnings("unchecked") // doPrivileged() returns the correct type
 @Deprecated
 public Enumeration<String> getServletNames() {
     if (SecurityUtil.isPackageProtectionEnabled()) {
         return (Enumeration<String>) doPrivileged("getServletNames", null);
     } else {
         return context.getServletNames();
     }
}
项目:tomcat7    文件:ApplicationContextFacade.java   
@Override
public void log(String msg) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        doPrivileged("log", new Object[]{msg} );
    } else {
        context.log(msg);
    }
}
项目:lazycat    文件:ApplicationContextFacade.java   
@Override
public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        doPrivileged("setSessionTrackingModes", new Object[] { sessionTrackingModes });
    } else {
        context.setSessionTrackingModes(sessionTrackingModes);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ApplicationContextFacade.java   
@Override
public void addListener(String className) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        doPrivileged("addListener",
                new Object[]{className});
    } else {
        context.addListener(className);
    }
}