<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
       ::  ::  :: 聯系 :: 聚合  :: 管理

    WebLogic JNDI 使用方法簡介

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

    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的訪問加入權限限制.

        1: 在 http://localhost:7001/console/ 中設置
        Security--->ACLs   Create a new ACL...
        Name=weblogic.jndi.myapp  // 這個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);
                    }
                }
            }
        }

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


    評論

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

    2011-04-26 11:54 by zcq87642231
    このやろう。 それは日本に向けのプロージェックトじゃん。
    主站蜘蛛池模板: 亚洲熟妇无码八V在线播放| 亚洲国产成人久久笫一页| 亚洲国产天堂在线观看| 十八禁在线观看视频播放免费| 无遮挡呻吟娇喘视频免费播放| 国产精品免费观看调教网| 久久亚洲精品中文字幕三区| 亚洲人成www在线播放| 黄瓜视频影院在线观看免费| 亚洲男人在线无码视频| 一级毛片免费观看不收费| 亚洲欧洲日产国码一级毛片| 亚洲一卡二卡三卡| 99在线热播精品免费99热| 亚洲精品tv久久久久久久久| 国产免费一区二区视频| 亚洲精品自在线拍| 国语成本人片免费av无码 | 爱情岛亚洲论坛在线观看 | 精品国产污污免费网站入口| 国产国拍亚洲精品福利 | 亚洲AV无码一区二区三区在线观看| 久久精品国产亚洲AV无码偷窥| 成人a毛片免费视频观看| 最近最新MV在线观看免费高清| 亚洲AV日韩精品久久久久久久| 九九全国免费视频| 亚洲精品综合一二三区在线| 久青草国产免费观看| 国产亚洲一区二区精品| 嫖丰满老熟妇AAAA片免费看| 亚洲AV网一区二区三区| 亚洲国产精品无码久久一线 | 青娱乐在线视频免费观看| 亚洲日韩精品A∨片无码| 阿v免费在线观看| 全部免费a级毛片| 亚洲第一成年网站视频| 无码免费午夜福利片在线| 特级aaaaaaaaa毛片免费视频| 国产在线观看免费不卡|