动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息

本月文章推荐
.[JAVA100例]028、图片的处理.
.Sun,IBM策划Java Portal标准.
.unshift 方法.
.SCJP 中文大纲.
.什么是 Enterprise JavaBeans 组.
.[JAVA100例]034、读写文件(字符操.
.基于Java技术的Web应用校验工具.
.关于常见的Java/J2EE中文问题解决.
.Digester 解析 XML 文档 Sample.
.Apache的完全安装转载.
.fromCharCode 方法.
.有感Javaisnotplatform-independ.
.如何在Microsoft.NET中自定义配置.
.如何编写Enterprise bean的客户端.
.在实际开发中教您NetBeans的使用.
.与垃圾收集器(Garbage Collecto.
.Aspectwerkz 2.0开发企业AOP快速.
.防止到String类的不恰当的类型转.
.手机上实现任意角度翻转算法[适用.
.EJB 3.0的三大类型详解.

用JAAS 实现in Struts Web App(一)

发表日期:2008-1-5 |



  JAAS参考资料中流行的文章是扩展JAAS实现类实例级授权
  
  但它是基于JDK1.3,与目前的JDK1.4,JDK1.5不兼容,例如其中的配置如下:
  
  The following assumes you are using JDK 1.3 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.
  
  1) Copy the jaas.jar and the jaasmod.jar to your JDK jre\lib\ext directory
  (i.e. D:\JDK1.3\jre\lib\ext).
  
  2) Add the following to the end of the Java.security file located in JDK's
  jre\lib\security directory (i.e. D:\JDK1.3\jre\lib\security):
  auth.policy.provider=com.ibm.resource.security.auth.XMLPolicyFile
  
  3) Execute the run.bat file.
  
  1.4以后为policy.provider=PolicyFile。而且需要修改java.security文件
  
  我经过2天的呕血奋战实现了不改变java VM环境和Web server环境,在struts下实现JAAS。
  
  步骤如下:
  
  1. welcome.jsp, index.jsp, struts-config.xml
  
  <%@ taglib uri="/tags/struts-logic" prefix="logic" %>
  <logic:redirect forward="index"/>
  <%-- welcome.jspRedirect default requests to Welcome global ActionForward.By using a redirect, the user-agent will change address to match the path of our Welcome ActionForward. --%>
  
  index.jsp
  
  <%@ page contentType="text/Html; charset=UTF-8"%>
  <%@ taglib uri="/tags/struts-bean" prefix="bean"%>
  <%@ taglib uri="/tags/struts-html" prefix="html"%>
  <%@ taglib uri="/tags/struts-logic" prefix="logic"%>
  <html:html>
  <Title>Logon
  </Title>
  <body><html:form action="/LoginAction.do">
  <p>User ID:
  <input type="text" name="userID" value="tyrone" />
  <br>
  Passord: <input type="passWord" name="password" value="password"/>
  <br>
  <html:submit />
  </p>
  </html:form>
  </body>
  </html:html>
  
  struts-config.xml
  
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  <!DOCTYPE struts-config PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
  "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
  <struts-config>
  <!-- ================================================ Form Bean Definitions -->
  <form-beans>
  <!--2 Login formbean-->
  <form-bean
  name="LoginForm"
  type="com.nova.colimas.web.form.LoginForm"/>
  </form-beans>
  <global-forwards>
  <!-- Default forward to "Welcome" action -->
  <!-- Demonstrates using index.jsp to forward -->
  <forward
  name="index"
  path="/index.do"/>
  </global-forwards><!-- =========================================== Action Mapping Definitions -->  <action-mappings>
  <!-- Default "Welcome" action -->
  <!-- Forwards to Welcome.jsp -->
  <action path="/index"
  type="com.nova.colimas.web.action.StartupServlet">
  <forward name="sUCcess" path="/pages/index.jsp"/>
  </action>
  <!-- 2 Login -->
  <action
  path="/LoginAction"
  type="com.nova.colimas.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>
  
  2. 实现com.nova.colimas.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 ());
  //Log.info (this, "Startup of Settings application");
  initJAAS();   return mapping.findForward("success");
  }  //初始化JAAS需要的系统属性  private void initJAAS(){
  //set env variable  //用于认证JAASConstants接口内保存login.config文件地址
  System.setProperty("java.security.auth.login.config",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\\login.config";
  String AUTH_SECURITY_MODULENAME="ColimasLogin";}
  
  Login.config文件内容:
  
  ColimasLogin
  {
  com.nova.colimas.security.auth.ColimasLoginModule required debug=true;
  };
  
  3.实现ColimasLoginModule登录模块
  
  /*
  * Created on 2005/07/01
  *
  * TODO To change the template for this generated file go to
  * Window - Preferences - Java - Code Style - Code Templates
  */package com.nova.colimas.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 org.w3c.dom.traversal.*;
  import org.w3c.dom.*;//import org.apache.XPath.*;
  /**
  * @author tyrone
  *
  * TODO To change the template for this generated type comment 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 commitSucceeded = 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[2];
  callbacks[0] = new NameCallback("userid: ");
  callbacks[1] = new PasswordCallback("password: ", false);
  try {
  callbackHandler.handle(callbacks);
  username = ((NameCallback) callbacks[0]).getName();
  char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
  if (tmpPassword == null)
  {
  // treat a NULL password as an empty
上一篇:Struts Menu中基于角色的权限管理 人气:1698
下一篇:用JAAS 实现in Struts Web App(二) 人气:492
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-9-4 LPLY CMS 网站管理系统 v5.0
2008-9-4 缤纷互动视频交友 v3.01.902
2008-9-4 ADN视频收藏专家 v3.0 bulid 080
2008-9-4 天空网络电影系统SKYUC v2.5.6 简
2008-9-4 Web Wiz Rich Text Editor(文本编
2008-9-4 幻影动漫网视频系统(Ppdong) v1.
2008-9-4 乐维电脑在线DIY配置系统
2008-9-4 老樊文章管理系统SQL版
2008-9-4 ASP.NET 2.53 缩略图水印组件源码
2008-8-23 Mini WinMount V0.4
2008-8-23 Vista优化大师3.11正式版
2008-8-23 Wine 1.13
2008-8-23 KlipFolio 5.0 Build 5899-80
2008-8-23 Windows Sysinternals Desktops
2008-8-23 OneTap Movies1.2破解版
2008-8-23 AnnotaterPDF阅读1.1.503 破解版
2008-8-23 SoundMeter分贝测量仪 v1.0汉化破
2008-8-23 iDrum音乐节拍1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | Html转换js | js/vbs加密 | md5加密 | 进制转换
实用工具:汉字翻译拼音 | 符号对照表 | 个税计算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵