如何覆盖j_security_check在GlassFish中? [英] How to override j_security_check in glassfish?

查看:153
本文介绍了如何覆盖j_security_check在GlassFish中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 FORM 基于认证GlassFish中V2.1进行用户登录,并能正常工作。我想切换到 ProgrammaticLogin ,我希望能够得到最初请求的URL(即重定向到登录页面之前),并在我的编程登录code使用这样,用户被认证之后重定向回请求的网页。

I'm currently using FORM based authentication in glassfish v2.1 to log users in and it works fine. I want to switch to ProgrammaticLogin and I want to be able to get the initially requested URL (i.e. before redirecting to login page) and use it in my programmatic login code so that the user is redirected back to the requested page after authentication.

我见过的源$ C ​​$ C为 j_security_check - 在我的情况下,这是 FormAuthenticator (卡特琳娜codeBase类),并将其保存在会话中的 SavedRequest 对象的初始请求,但该次会议是一个 StandardSession 而比的HttpSession 所以有访问它没有直接的方法。

I've seen the source code for j_security_check - in my case that's FormAuthenticator (catalina codebase) and it saves the initial request in a SavedRequest object in the session but that session is a StandardSession rather than HttpSession so there's no direct way to access it.

或者我应该从 FORM 认证机制更改为其他?

Or should I change the authentication mechanism from FORM to something else?

谢谢!

推荐答案

好吧,我找到了答案。所以在这里,它是:

Ok, I found the answer. So here it is:

基本上我试图实现是实现在GlassFish中的基于OpenID的认证机制。这样做的一个方法是使用 ProgrammaticLogin 但是这有一些缺点 - 重定向回请求的URL和规划的权威性没有简单的方法意味着程序员更多的工作。所以,阅读了有关情况后,我发现了更好的方法实现我的目标 - 服务器的身份验证模块或地对空导弹。这是 JSR-196 描述的标准过程的一部分,提供了一个用于创建GlassFish的可插拔模块权威性的方式(即比标准不同的 FORM 基本等)。这种方法可以让你在servlet容器中插入新的身份验证模块,同时保持你声明的安全模型。

Basically what I was trying to achieve was to implement an openid-based authentication mechanism in glassfish. One way of doing that is to use ProgrammaticLogin but this has a few drawbacks - no easy way of redirecting back to requested URL and programmatic auth means more work for the programmer. So after reading around I found the better way to achieve my goal - Server Authentication Modules or SAMs. This is part of a standard process described in JSR-196 and provides a way for creating pluggable auth modules for glassfish (ie. different than the standard FORM, BASIC etc.). This method allows you to plug new auth modules in the servlet container while keeping your declarative security model.

因此​​,所有我需要做的就是写我自己的自定义SAM。这里有一个快速操作方法:

So all I need to do is write my own custom SAM. Here's a quick how-to:


  1. 实施ServerAuthModule接口,主要归结为以下方法:

  1. Implement the ServerAuthModule interface which mostly boils down to the following method:

AuthStatus validateRequest(MessageInfo messageInfo,security.auth.Subject
clientSubject,security.auth.Subject serviceSubject)抛出AuthException

打包您的SAM在一个罐子,然后将你的罐子在GlassFish lib目录下。

Package your SAM in a jar, and place your jar in the glassfish lib directory.

配置SAM与您的应用程序使用。这两个步骤完成:

Configure the SAM for use with your application. This is done in 2 steps:


  • 定义您的SAM在domain.xml中信息安全提供商。

  • 绑定SAM与您的应用程序使用。您可以在您的应用程序的阳光网络app.xml中定义的HttpServlet安全提供商属性做到这一点。将属性分配给您的SAM步骤1中的name的值。

有关更多信息由Ron Monzillo阅读这个伟大的教程。

For more info read this great tutorial by Ron Monzillo.

更新:还有一个更简单,更优雅的解决这个问题叫做的 AuthenticRoast 。这是一个Java库由艾克索默写,让你写你自己的可插入式验证器。

UPDATE: There is a simpler and more elegant solution to this problem called AuthenticRoast. This is a Java library written by Aike Sommer which allows you to write your own pluggable authenticators.

这篇关于如何覆盖j_security_check在GlassFish中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆