2011-05-30 97 views
2

因此,我的託管公司使用安全管理器將其服務更改爲tomcat 7,從那時起每次我收到此異常應用程序嘗試使用Hibernate連接到MySQL數據庫。我不知道該怎麼做,他們問我Tomcat的權限,但我沒有定義任何特別的東西。java.security.AccessControlException:訪問被拒絕(java.lang.RuntimePermission accessClassInPackage.sun.misc)

任何人都可以幫助我嗎?

這是我的堆棧跟蹤:

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) 
+0

這就是同樣的問題,你的軟件包ir.omicc ...(這是哪個jar?)確實有來自catalina的安全訪問。 – EricParis16 2011-05-30 11:59:58

+0

http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html – 2015-07-17 06:13:31

回答

2

看來,類ir.omicc.utilBox.PasswordService嘗試使用一些類在sun.misc包。如果這個類是你的類之一,那麼你應該重新實現它,而不訪問sun.misc類。如果不是,請詢問實施此類的開發人員/公司是否修復此問題。使用sun.misc類是一個非常糟糕的做法,一直不鼓勵。

+0

humm,我正在使用它來加密密碼,但事實並非如此,因爲我每次嘗試都會遇到這個錯誤連接到數據庫,即使沒有使用這個類 – MoienGK 2011-05-30 08:59:02

+0

我編輯了跟蹤 – MoienGK 2011-05-30 11:39:12

3

您的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; 
}; 

這是一種解決方法,但它不安全。

+0

,但它不是所有關於該jar文件,每當我嘗試連接數據庫時,發生此問題 – MoienGK 2011-05-30 11:17:43

+0

我編輯了跟蹤 – MoienGK 2011-05-30 11:38:31

+0

這一切都與你的類有關在那個jar文件中,你的jar有權限到其他資源 – EricParis16 2011-05-30 12:03:28

1

我揣測堆棧跟蹤已被編輯。您現在需要授予您的代碼庫以下權限:

java.util.PropertyPermission "hibernate.enable_specj_proprietary_syntax", "read"; 

或更可能是「hibernate。*」,「read,write」;

+0

是的,我編輯了跟蹤,但我也寫了「編輯」: - ?我認爲這會解決它,讓我試試 – MoienGK 2011-05-31 09:50:40

+0

我做了你所說的並且錯誤改變了!我現在得到這個:java.lang.NullPointerException \t org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:105) – MoienGK 2011-05-31 16:22:46

相關問題