我正在尝试使用 Jaas、Java Authentication and Autorisation 服务。服务器是 App Engine,因此无法编辑 web.xml。我正在使用一个 servlet 过滤器,例如:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
try {
LoginContext lc = new LoginContext("JaasSample", new AuthenticationCallbackHandler());
lc.login();
chain.doFilter(request, response);
lc.logout();
} catch (LoginException e) { /* lc.login() fails */}
}
对 LoginContext 的调用会检查策略并引发以下异常:
java.security.AccessControlException:
access denied (javax.security.auth.AuthPermission createLoginContext.JaasSample)
我使用的代码来自Oracle 参考。他们解释说,在存在安全管理器的情况下,有必要以这种方式授予一些权限:
grant {
permission javax.security.auth.AuthPermission "createLoginContext.JaasSample";
}
我只是不明白为什么要在 JAR 中制作。
我可以在运行配置中使用 -D--enable_all_permissions=true 绕过此检查。(但这要解决进入 prod)然后,在 System.getProperty("user.home")/.java.login.config 中搜索 Jaas 配置文件。难道不是在项目资源中吗?这如何在本地/生产中工作?
配置文件如下:
JaasSample {
com.sun.security.auth.module.Krb5LoginModule required;
};
非常感谢。
附言。Spring Security 可以与 Jaas 一起使用并在 App Engine 上工作。pps。无法使用 Spring Security,因为它会启动 Spring 上下文,这会减慢 App Engine 的启动速度。并且一直在这个环境下启动。