<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
    このやろう?!·饯欷先毡兢讼颏堡违抓愆`ジェックトじゃん。
    主站蜘蛛池模板: 亚洲女同成av人片在线观看 | 免费福利电影在线观看| 日本xxwwxxww在线视频免费| 亚洲一区二区三区免费在线观看| 久久www免费人成看片| 亚洲精品国产电影午夜| 99在线视频免费观看视频 | 又长又大又粗又硬3p免费视频| 国产黄色片在线免费观看| 亚洲AV无码一区二区三区电影 | 亚洲日韩精品无码专区网址 | 丁香花在线视频观看免费 | 亚洲国产精品无码一线岛国| 91免费福利视频| 亚洲国产综合精品中文第一区| 午夜精品免费在线观看| 亚洲春色另类小说| 天天看片天天爽_免费播放| 99亚洲乱人伦aⅴ精品| 亚洲免费视频一区二区三区| 少妇性饥渴无码A区免费 | 亚洲一区精品视频在线| 免费观看的a级毛片的网站| 色九月亚洲综合网| 亚洲人成人77777网站| 久久精品毛片免费观看| 亚洲国产精品综合久久20| 国产乱子伦精品免费女| 中文字幕免费不卡二区| 亚洲一级毛片免费看| 免费一级国产生活片| 免费无码一区二区三区蜜桃| 亚洲一区二区三区在线网站| 免费人成年轻人电影| 99久久精品免费精品国产| 亚洲av永久无码天堂网| 亚洲精品无码Av人在线观看国产| 日本XXX黄区免费看| 人碰人碰人成人免费视频| 久久久久久亚洲Av无码精品专口| 免费看a级黄色片|