如何解决java.security.AccessControlException:访问被拒绝java.lang.RuntimePermission accessClassInPackage.sun.misc
| 因此,我的托管公司使用安全管理器将其服务更改为tomcat 7,从那时起,每次我的应用程序尝试使用Hibernate连接到MysqL数据库时,我都会收到此异常。我不知道该怎么办,他们向我询问我的Tomcat权限,但是我没有定义任何特殊的内容。 谁能帮我? 这是我的堆栈跟踪:org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
sun.reflect.GeneratedMethodAccessor134.invoke(UnkNown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
root cause
javax.servlet.servletexception: java.lang.ExceptionInInitializerError
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:71)
org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:778)
java.security.AccessController.doPrivileged(Native Method)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
org.apache.jsp.news_jsp._jspService(news_jsp.java:285)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
sun.reflect.GeneratedMethodAccessor134.invoke(UnkNown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
root cause
java.lang.ExceptionInInitializerError
ir.omicc.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
ir.omicc.hibernate.util.HibernateUtil.getSessionFactory(HibernateUtil.java:24)
ir.omicc.classes.Publisher.getNews(Publisher.java:126)
org.apache.jsp.news_jsp._jspService(news_jsp.java:221)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
sun.reflect.GeneratedMethodAccessor134.invoke(UnkNown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
root cause
java.security.AccessControlException: access denied (java.util.PropertyPermission hibernate.enable_specj_proprietary_Syntax read)
java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
java.security.AccessController.checkPermission(AccessController.java:546)
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
java.lang.System.getProperty(System.java:650)
org.hibernate.cfg.Configuration.reset(Configuration.java:362)
org.hibernate.cfg.Configuration.<init>(Configuration.java:296)
org.hibernate.cfg.Configuration.<init>(Configuration.java:300)
ir.omicc.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:12)
ir.omicc.hibernate.util.HibernateUtil.getSessionFactory(HibernateUtil.java:24)
ir.omicc.classes.Publisher.getNews(Publisher.java:126)
org.apache.jsp.news_jsp._jspService(news_jsp.java:221)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
sun.reflect.GeneratedMethodAccessor134.invoke(UnkNown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
解决方法
您的tomcat安全性配置存在问题。
检查$ {catalina.home} /conf/catalina.policy中是否存在
以下几行:
grant {
// Precompiled JSPs need access to this package.
permission java.lang.RuntimePermission \"accessClassInPackage.sun.misc\";
permission java.lang.RuntimePermission \"accessClassInPackage.sun.misc.*\";
};
并添加$ {catalina.home} /conf/policy.d/03.catalina.policy
// The permissions granted to your jar (ir.omicc ??)
grant codeBase \"file:/path/to/the/ir.omicc.utilBox/your.jar\" {
permission java.security.AllPermission;
};
这是一种解决方法,但并不安全。
, 看来类ir.omicc.utilBox.PasswordService
尝试使用sun.misc
包中的某个类。如果该类是您的类之一,则应在不访问sun.misc类的情况下重新实现它。如果不是,则请实施此类的开发人员/公司对其进行修复。使用sun.misc
类是非常糟糕的做法,一直不鼓励这样做。
, 我假设堆栈跟踪已被编辑。现在,您需要向您的代码库授予以下权限:
java.util.PropertyPermission \"hibernate.enable_specj_proprietary_syntax\",\"read\";
或更可能是“休眠” *,“读,写”;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。