知识大全 用JAAS 实现in Struts Web App(一)
Posted 文件
篇首语:历览千载书,时时见遗烈。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 用JAAS 实现in Struts Web App(一)相关的知识,希望对你有一定的参考价值。
用JAAS 实现in Struts Web App(一) 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
JAAS参考资料中流行的文章是扩展JAAS实现类实例级授权 但它是基于JDK 与目前的JDK JDK 不兼容 例如其中的配置如下 The following assumes you are using JDK and the files were extracted to the d:\\JaasExample directory You will save some work by extracting the files to this directory otherwise you will have to modify the policy and the ResourceSecurity xml policy files with the correct path names ) Copy the jaas jar and the jaasmod jar to your JDK jre\\lib\\ext directory (i e D:\\JDK \\jre\\lib\\ext) ) Add the following to the end of the java security file located in JDK s jre\\lib\\security directory (i e D:\\JDK \\jre\\lib\\security): auth policy provider= ibm resource security auth XMLPolicyFile ) Execute the run bat file 以后为policy provider=PolicyFile 而且需要修改java security文件 我经过 天的呕血奋战实现了不改变java VM环境和Web server环境 在struts下实现JAAS 步骤如下 wele jsp index jsp struts config xml <%@ taglib uri= /tags/struts logic prefix= logic %> <logic:redirect forward= index /> <% wele jspRedirect default requests to Wele global ActionForward By using a redirect the user agent will change address to match the path of our Wele ActionForward %> index jsp <%@ page contentType= text/; charset=UTF %> <%@ taglib uri= /tags/struts bean prefix= bean %> <%@ taglib uri= /tags/struts prefix= %> <%@ taglib uri= /tags/struts logic prefix= logic %> <:> <Title>Logon </Title> <body><:form action= /LoginAction do > <p>User ID: <input type= text name= userID value= tyrone /> <br> Passord: <input type= password name= password value= password /> <br> <:submit /> </p> </:form> </body> </:> struts config xml <?xml version= encoding= ISO ?> <!DOCTYPE struts config PUBLIC //Apache Sofare Foundation//DTD Struts Configuration //EN config_ _ dtd > <struts config> <! ================================================ Form Bean Definitions > <form beans> <! Login formbean > <form bean name= LoginForm type= limas web form LoginForm /> </form beans> <global forwards> <! Default forward to Wele action > <! Demonstrates using index jsp to forward > <forward name= index path= /index do /> </global forwards><! =========================================== Action Mapping Definitions > <action mappings> <! Default Wele action > <! Forwards to Wele jsp > <action path= /index type= limas web action StartupServlet > <forward name= success path= /pages/index jsp /> </action> <! Login > <action path= /LoginAction type= limas web action LoginAction name= LoginForm scope= request input= /pages/indexcon jsp validate= true > <forward name= success path= /pages/index jsp /> <forward name= failure path= /pages/index jsp /> </action> </action mappings></struts config> 实现limas web action StartupServlet用来初始化JAAS需要的系统属性 public class StartupServlet extends Action public ActionForward execute(ActionMapping mapping ActionForm form HttpServletRequest request HttpServletResponse response) throws Exception // Initialization of the log //LoggerFactory setFactory(new EPricerLogFactory ()); // (this Startup of Settings application ); initJAAS(); return mapping findForward( success ); //初始化JAAS需要的系统属性 private void initJAAS() //set env variable //用于认证JAASConstants接口内保存nfig文件地址 System setProperty( java secnfig JAASConstants AUTH_SECURITY_LOGINFILE); public interface JAASConstants String AUTH_SECURITY_POLICYXMLFILE= D:\\\\MyProject\\\\colimas\\\\clms web\\\\colimas\\\\security policy xml ; String AUTH_SECURITY_LOGINFILE= D:\\\\MyProject\\\\colimas\\\\clms web\\\\colimas\\\\nfig ; String AUTH_SECURITY_MODULENAME= ColimasLogin ; nfig文件内容 ColimasLogin limas security auth ColimasLoginModule required debug=true; ; 实现ColimasLoginModule登录模块 /* * Created on / / * * TODO To change the template for this generated file go to * Window Preferences Java Code Style Code Templates */package limas security auth;import java util *; import javax security auth *;import javax security auth callback *; import javax security auth login *; import javax security auth spi LoginModule;//import java security *; //import w c dom traversal *; import w c dom *;//import apache xpath *; /** * @author tyrone * * TODO To change the template for this generated type ment go to * Window Preferences Java Code Style Code Templates */public class ColimasLoginModule implements LoginModule private Subject subject; private CallbackHandler callbackHandler; private boolean debug = false; private boolean succeeded = false; private boolean mitSucceeded = false; private String username; private char[] password; /** * Initializes the <code>LoginModule</code> * * @param subject the <code>Subject</code> to be authenticated * * @param callbackHandler a <code>CallbackHandler</code> for * prompting and retrieving the userid and password from the user * * @param sharedState shared <code>LoginModule</code> state * * @param options options specified in the login configuration * file for this <code>LoginModule</code> */ public void initialize(Subject subject CallbackHandler callbackHandler Map sharedState Map options) this subject = subject; this callbackHandler = callbackHandler; // initialize configuration options debug = true equalsIgnoreCase((String) options get( debug )); /** * Prompts the user for a userid and password * * @return true if the authentication succeeded * or false if this LoginModule should be ignored * * @exception FailedLoginException if the authentication fails * * @exception LoginException if the <code>LoginModule< /code> * is unable to authenticate */ public boolean login() throws LoginException if (callbackHandler == null) throw new LoginException( Error: CallbackHandler cannot be null ); Callback[] callbacks = new Callback[ ]; callbacks[ ] = new NameCallback( userid: ); callbacks[ ] = new PasswordCallback( password: false); try callbackHandler handle(callbacks); username = ((NameCallback) callbacks[ ]) getName(); char[] tmpPassword = ((PasswordCallback) callbacks[ ]) getPassword(); if (tmpPassword == null) // treat a NULL password as an empty cha138/Article/program/Java/ky/201311/28702相关参考
知识大全 Web App struts框架里实现Filter
WebAppstruts框架里实现Filter 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! w
知识大全 用struts+spring+hibernate组装web应用
其实就算用Java建造一个不是很烦琐的web应用程序也不是件轻松的事情当为一个应用程序建造一个构架时有许多事情需要考虑从高层来说开发者需要考虑怎样建立用户接口(userinterfaces)?在哪
知识大全 spring在web.xml中和在struts中的不同配置
Spring中WebApplicationContext的研究 ApplicationContext是Spring的核心Context我们通常解释为上下文环境我想用容器来表述它更容易理解一些Ap
Struts配置讲解Web应用 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! Web应用的发布描
Struts2中访问web元素 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 取得Map类型re
为Web服务构建Struts应用程序 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 当您要将企业
Struts开发指南之其他Web构架介绍 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! Stru
WEB开发中Struts常见错误及原因分析 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 
知识大全 Web框架对比: Wicket vs Struts
Web框架对比:WicketvsStruts 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!一概貌W
教你如何配置Struts2web.xml文件 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! St