为什么我得到java.security.AccessControlException?

时间:2012-07-20 22:39:23

标签: eclipse google-app-engine permissions runtimeexception accesscontrolexception

我正在使用谷歌应用引擎。当我从我的网站发送ajax请求时。我得到以下例外:

 Uncaught exception from servlet
 java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:355)
at java.security.AccessController.checkPermission(AccessController.java:567)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:56)
at java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1679)
at java.lang.Class.checkMemberAccess(Class.java:2174)
at java.lang.Class.getDeclaredMethods(Class.java:1807)
at javax.servlet.http.HttpServlet.getAllDeclaredMethods(HttpServlet.java:426)
at javax.servlet.http.HttpServlet.doOptions(HttpServlet.java:477)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:249)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:477)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:449)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:695)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:453)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:679)

我正在使用带有JDK 1.6.6的谷歌应用引擎插件的eclipse。对于持久性我使用以下类:      公共课PMF {

private static final PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory("transactions-optional");

private PMF(){}

public static PersistenceManagerFactory get(){
    return pmfInstance;
}
 }

并且在代码中我持久存在如下对象:

 user.setEmail(userEmail);
 user.setAddress(address);
 user.setFirstName(fName);
 user.setLastName(lName);
 user.setPassword(pwd);
 pm.makePersistent(user);     

我的用户类代码如下:

 @PersistenceCapable
 public class User{

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private String userEmail;

@Persistent
private String fName;

    @Persistent
private String lName;

    @Persistent
private String address;

    @Persistent
private String pwd;

    public User(){}

    // getters and setters for all

 }  

我正在使用简单的java Servlets。

本地一切都运行正常但是当我在谷歌appengine上传我的网络应用程序时,这个例外来了。任何人都可以知道它为什么会发生,我该如何解决?提前谢谢。

1 个答案:

答案 0 :(得分:0)

由于App Engine的沙盒环境,您遇到了问题。这在其他similar postsRuntime documentation中进行了讨论。

这些错误通常只会在生产中出现,因为本地环境与生产环境相似但不完全相同。

修改

话虽如此,下面的代码在本地和生产中都可以正常工作。它基于您共享的代码,因此我不完全确定错误是什么。

我的用户类:

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class User{

  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private String userEmail;

  @Persistent
  private String fName;

  @Persistent
  private String lName;

  @Persistent
  private String address;

  @Persistent
  private String pwd;

  public User(){}

  public String getUserEmail() {
    return userEmail;
  }

  public void setUserEmail(String userEmail) {
    this.userEmail = userEmail;
  }

  public String getfName() {
    return fName;
  }

  public void setfName(String fName) {
    this.fName = fName;
  }

  public String getlName() {
    return lName;
  }

  public void setlName(String lName) {
    this.lName = lName;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getPwd() {
    return pwd;
  }

  public void setPwd(String pwd) {
    this.pwd = pwd;
  }
}

我的servlet:

public class MyTestServlet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    resp.setContentType("text/plain");
    resp.getWriter().println("Hello, world");

    User user = new User();
    user.setUserEmail("email");
    user.setAddress("address");
    user.setfName("first");
    user.setlName("last");
    user.setPwd("password");
    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.makePersistent(user);
  }
}

我唯一能想到的是你可能正在使用不正确的注释。你能确认你的注释与我的相符吗?