麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

用JAAS 實現in Struts Web App(一)

2019-11-18 12:54:44
字體:
來源:轉載
供稿:網友

  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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产乱子视频 | 午夜久久视频 | 蜜桃网在线 | 9191色| 中国女警察一级毛片视频 | 2023av在线视频 | 一级黄色毛片子 | 最新黄色电影网站 | 久久国产精品二国产精品中国洋人 | 国产精品久久久久久久久久久久久久久久 | 精品一区二区三区网站 | 91精品国产91久久久久久 | 欧美日韩国产成人在线观看 | 国产免费专区 | 日韩av有码在线 | 欧美亚洲国产成人综合在线 | 欧美xxxx精品另类 | 超污视频在线看 | 黄色影院在线看 | 福利一区二区三区视频在线观看 | 男人天堂新地址 | 国产真实孩交 | 艹男人的日日夜夜 | 99国产精品欲a | 久久久久免费精品 | 成人在线观看一区二区 | xnxx18日本 | 国内精品免费一区二区2001 | 国产成人高清在线观看 | 刘亦菲一区二区三区免费看 | 2018亚洲男人天堂 | 免费久久久 | 国产午夜精品理论片a级探花 | 欧美成人精品一区二区三区 | 亚洲片在线 | 一级免费特黄视频 | 性欧美xxxx极品摘花 | 国产激情网| 性高跟鞋xxxxhd4kvideos | 一级毛片真人免费播放视频 | 性高湖久久久久久久久aaaaa |