<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 56, comments - 54, trackbacks - 0, articles - 4
       ::  ::  :: 聯(lián)系 :: 聚合  :: 管理

    WebLogic JNDI 使用方法簡介

    Posted on 2005-11-16 10:37 Terry的Blog 閱讀(5037) 評論(1)  編輯  收藏 所屬分類: Java應(yīng)用服務(wù)器

    WebLogic JNDI 使用方法簡介
     
    參考資料
    1: http://www.weblogic.com/docs/classdocs/API_jndi.html
    2: BeaHOME\wlserver6.1\samples\examples\jndi

    public static void main(String[] args) {
        // Use weblogic test JNDI
        // project include BeaHOME\wlserver6.1\lib\weblogic.jar
        String bindingkey = "UserAccount";
        Context initialContext = null;
        try {
            // 1 Create a Properties object and set properties appropriately
            Properties props = new Properties();
            // Take a look at BeaHOME\wlserver6.1\samples\examples\jndi
            // 1.1
            props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            // 1.2   
            props.put(Context.PROVIDER_URL, "t3://localhost:7001");

            // 2 Create the initial context from the properties we just created
            initialContext = new InitialContext(props);

            HashMap lst = new HashMap();
            lst.put("enterprise_code", "600000");
            lst.put("username", "S02888");
            lst.put("password", "sysmex");

            // Sometimes bind twice will cause NamingException  
            //initialContext.unbind(bindingkey);
            try {
                // binding is copy obj's value to server
                initialContext.bind(bindingkey, lst);
            } catch (NameAlreadyBoundException e) {
                initialContext.rebind(bindingkey, lst);
            }

            // Look up the object. copy obj's value from server
            Object obj = initialContext.lookup(bindingkey);

            if (bindingkey.equals("")) {
                System.out.println("Looked up the initial context");
            } else {
                System.out.println(bindingkey + " is bound to: " + obj);
            }
        } catch (NamingException e) {
            System.out.println("NamingException msg = " + e.getMessage());
        } finally {
            if (initialContext != null) {
                try {
                    initialContext.close();
                } catch (NamingException e) {
                    System.out.println("Failed to close context due to: " + e);
                }
            }
        }
    }
     
    用ACLs限制JNDI訪問
     
        給JNDI的訪問加入權(quán)限限制.

        1: 在 http://localhost:7001/console/ 中設(shè)置
        Security--->ACLs   Create a new ACL...
        Name=weblogic.jndi.myapp  // 這個(gè)myapp就是要限制的JNDI路徑.
        Permissions=lookup (first time)
        Permissions=modify (secend time)
        User=user1
         if there is a error system has not "modify" permission
         please add one line in filerealm.properties
         acl.modify.weblogic.admin=Administrators


        2: 代碼中訪問JNDI是要輸入用戶名 密碼

        static final String JNDI_PATH = "myapp";

        public void bindUserData(
            String sessid,
            String enterpriseCode,
            String userId,
            String password) {

            // Use weblogic test JNDI
            // project include BeaHOME\wlserver6.1\lib\weblogic.jar
            String bindingkey = sessid;
            Context initialContext = null;
            try {
                // 1 Create a Properties object and set properties appropriately
                Properties props = new Properties();
                // Take a look at BeaHOME\wlserver6.1\samples\examples\jndi
                props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
                props.put(Context.PROVIDER_URL, "t3://localhost:7001");
                // ユーザおよびパスワードを T3User にパッケージ化して、
                // パスワードを確実に暗號化する
                props.put(Context.SECURITY_CREDENTIALS, new T3User("user1", "psw1")); 
               
                // 2 Create the initial context from the properties we just created
                initialContext = new InitialContext(props);

                HashMap lst = new HashMap();
                //lst.put("enterprise_code", "600000");
                //lst.put("username", "S02888");
                //lst.put("password", "sysmex");

                lst.put("enterprise_code", enterpriseCode);
                lst.put("username", userId);
                lst.put("password", password);

                try {
                    initialContext.createSubcontext(JNDI_PATH);
                    System.out.println("Subcontext 'myapp' created");
                } catch (NameAlreadyBoundException e) {
                    // サブコンテキストがすでに存在している。
                    // 名前が同じオブジェクトにすでにバインドされている場合、
                    // WebLogic のコンテキストの実裝で、この例外は送出されない。
                    System.out.println("Subcontext 'myapp' already exists;" + " continuing with existing subcontext");
                }

                initialContext.unbind(JNDI_PATH + "." + bindingkey);
                // bind is copy obj's value to server
                initialContext.bind(JNDI_PATH + "." + bindingkey, lst);

                // Look up the object. copy obj's value from server
                Object obj = initialContext.lookup(JNDI_PATH + "." + bindingkey);

                if (bindingkey.equals("")) {
                    System.out.println("Looked up the initial context");
                } else {
                    System.out.println(
                        JNDI_PATH + "." + bindingkey + " is bound to: " + obj);
                }

            } catch (NamingException e) {
                System.out.println("NamingException msg = " + e.getMessage());
            } finally {
                if (initialContext != null) {
                    try {
                        initialContext.close();
                    } catch (NamingException e) {
                        System.out.println("Failed to close context due to: " + e);
                    }
                }
            }
        }

    // 補(bǔ)充:遍歷所有元素
    NamingEnumeration ne = initialContext.list("."); // 用句號表示根目錄
    while (ne.hasMoreElements()){
        System.out.println(ne.next());  
    }
     
     


    評論

    # re: WebLogic JNDI 使用方法簡介  回復(fù)  更多評論   

    2011-04-26 11:54 by zcq87642231
    このやろう?!·饯欷先毡兢讼颏堡违抓愆`ジェックトじゃん。
    主站蜘蛛池模板: 亚洲精品无码MV在线观看| 免费福利视频导航| eeuss影院www天堂免费| 国产成人亚洲精品蜜芽影院| 亚洲av无码成人精品国产| 亚洲一日韩欧美中文字幕在线| 亚洲一卡二卡三卡四卡无卡麻豆| 亚洲丰满熟女一区二区v| 亚洲国产av高清无码| 久久精品国产亚洲av麻豆蜜芽| 亚洲综合区图片小说区| 亚洲人成网站18禁止久久影院| 亚洲永久中文字幕在线| 亚洲国产福利精品一区二区| 精品亚洲AV无码一区二区三区 | 1000部国产成人免费视频| 777成影片免费观看| 国产成人精品久久免费动漫| 四虎精品视频在线永久免费观看| 中文字幕免费在线看线人| 成年人免费观看视频网站| 手机看片久久国产免费| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲最新永久在线观看| 亚洲精品美女在线观看| 久久亚洲国产成人影院| 特级aa**毛片免费观看| 中文在线观看国语高清免费| 国产一区二区免费| 蜜臀AV免费一区二区三区| 无人影院手机版在线观看免费| 日韩成人在线免费视频| 亚洲国模精品一区| 久久久久久亚洲av成人无码国产| 亚洲男女性高爱潮网站| 亚洲狠狠婷婷综合久久| 污污污视频在线免费观看| 日本一道本不卡免费| 拨牐拨牐x8免费| 久久久久一级精品亚洲国产成人综合AV区 | 777成影片免费观看|