windows下ITIM admin API开发环境配置,部署至tomcat

开发环境构建
1. ibm_sdk50 java.security.
 
A. 下载/opt/IBM/itim/extensions/5.1/examples/apps/bin/jaas_login_was.conf 至D:/jaas_login_was.conf
B.修改 java.security文件( D:\IBM\eclipseDevelopmentPackage\ibm_sdk50\jre\lib\security\ java.security ),尾部添加如下
login.config.url.1=file:///D:/jaas_login_was.conf

2.添加依赖的jar包列表至WEB-INF/lib及其它配置:
APP_SRV_TOP=/opt/IBM/WebSphere/AppServer/profiles/AppSrv01
ITIM_HOME=/opt/IBM/itim

$ITIM_HOME/lib/api_ejb.jar
$ITIM_HOME/lib/itim_api.jar
$ITIM_HOME/lib/itim_common.jar
$ITIM_HOME/lib/itim_server_api.jar
$ITIM_HOME/lib/jlog.jar
$APP_SRV_TOP/runtime/com.ibm.ws.admin.client_6.1.0.jar
$APP_SRV_TOP/plugins/com.ibm.ws.ejbportable_6.1.0.jar

下载$ITIM_HOME/data/tmsMessages.properties

C:\WINDOWS\system32\drivers\etc\hosts中 添加域名映射如下
192.168.2.12 

      itim

4.项目的目录结构图如下:
windows下ITIM admin API开发环境配置,部署至tomcat_第1张图片


5.部署至apache-tomcat-6.0.18服务器中
A.配置apache-tomcat-6.0.18运行jre
在apache-tomcat-6.0.18/bin/setclasspath.bat中添加JRE_HOME:
set JRE_HOME="D:\IBM\eclipseDevelopmentPackage\ibm_sdk50\jre"
B.拷贝$APP_SRV_TOP/runtime/com.ibm.ws.admin.client_6.1.0.jar到apache-tomcat-6.0.18/lib中

附录代码
PersonMgr.java
package com.likegene.demo;

import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Hashtable;
import java.util.ResourceBundle;

import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

import com.ibm.itim.apps.ApplicationException;
import com.ibm.itim.apps.InitialPlatformContext;
import com.ibm.itim.apps.PlatformContext;
import com.ibm.itim.apps.Request;
import com.ibm.itim.apps.identity.PersonMO;
import com.ibm.itim.apps.identity.PersonManager;
import com.ibm.itim.apps.jaas.callback.PlatformCallbackHandler;
import com.ibm.itim.apps.provisioning.PasswordManager;


public class PersonMgr {

    static ResourceBundle rb = ResourceBundle.getBundle("context");

    public Subject getSubject(PlatformContext platform) {

        String itimManager = rb.getString("itimManager");
        String itimManagerPwd = rb.getString("itimManagerPwd");
        Subject subject = null;
        try {
            PlatformCallbackHandler handler = new PlatformCallbackHandler(
                    itimManager, itimManagerPwd);
            handler.setPlatformContext(platform);
            LoginContext lc = new LoginContext("ITIM", handler);
            lc.login();
            subject = lc.getSubject();
        }

        catch (LoginException e) {
            e.printStackTrace();
        }

        return subject;
    }

    public PlatformContext getPlatform() {

        String platformContextFactory = rb.getString("contextFactory");
        String ejbUser = rb.getString("ejbUser");
        String appServerURL = rb.getString("appServerURL");
        String ejbPwd = rb.getString("ejbPwd");

        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(InitialPlatformContext.CONTEXT_FACTORY, platformContextFactory);
        env.put(PlatformContext.PLATFORM_URL, appServerURL);
        env.put(PlatformContext.PLATFORM_PRINCIPAL, ejbUser);
        env.put(PlatformContext.PLATFORM_CREDENTIALS, ejbPwd);
        PlatformContext platform = null;

        try {
            platform = new InitialPlatformContext(env);
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (ApplicationException e) {
            e.printStackTrace();
        }
        return platform;
    }

    public String updatePersonPwd(String uid, String newPwd) {
        PlatformContext platform = getPlatform();
        Subject subject = getSubject(platform);

        PersonManager mgr = new PersonManager(platform, subject);

        // find user
        Collection people;
        try {
            people = mgr.getPeople("uid", uid, null);

            if (people.size() == 0) {
                System.out.print("用户不存在 :" + uid);
                return null;
            }

            PersonMO personMO = (PersonMO) people.iterator().next();

            PasswordManager pManager = new PasswordManager(platform, subject);
            Request request = pManager.synchPasswords(personMO, newPwd, null);
            String requestID = String.valueOf(request.getID());
            System.out.print("修改用户密码请求已提交. 处理 request ID:" + requestID);
            return requestID;
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (ApplicationException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        PersonMgr pm = new PersonMgr();
        pm.updatePersonPwd("asmsith", "admin1234567");
    }
}

ChangePwdServlet.java
package com.likegene.demo;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ChangePwdServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public ChangePwdServlet() {
        super();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String newpassword = request.getParameter("newPwd");
        String userid = request.getParameter("uid");

        PersonMgr pm = new PersonMgr();
        if (pm.updatePersonPwd(userid, newpassword) != null) {
            request.setAttribute("msg", "change password successfully!");
        } else {
            request.setAttribute("msg", userid + " not exist!");
        }
        request.getRequestDispatcher("./result.jsp").forward(request, response);
    }
}
context.properties
appServerURL=iiop://itim:2809
contextFactory=com.ibm.itim.apps.impl.websphere.WebSpherePlatformContextFactory
itimManager=itim manager
itimManagerPwd=object00
ejbUser=wasadmin
ejbPwd=object00
rootdn=ou=xyz,o=xyz

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <servlet-name>ChangePwdServlet</servlet-name>
    <servlet-class>com.likegene.demo.ChangePwdServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>ChangePwdServlet</servlet-name>
    <url-pattern>/ChangePwdServlet</url-pattern>
  </servlet-mapping>
       
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>


index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <meta http-equiv=Content-Type content="text/html; charset=UTF-8">
  </head>
  <body>
      <form method="post" action="./ChangePwdServlet">
          <table>
            <tr>
            <td>修改密码:</td>
            <td>UID:</td>
            <td><input type="text" name="uid"/></td>
            <td>新密码:</td>
            <td>
            <input type="text"  name="newPwd"/></td>
            <td>
            <input type="submit" value="修改" />
            </td>
            </tr>
        </table>
    </form>
  </body>
</html>

result.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>result</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   
  </head>
  <body>
    ${msg}
  </body>
</html>

你可能感兴趣的:(IBM,Tim)