2012-01-12 73 views
1

iam試圖遵循weblogic的mbeans文檔並創建一個web應用程序 來訪問在服務器中部署的另一個應用程序中運行的已經創建的定製bean。 IAM使用此代碼部署在weblogic上的mBeans Client會產生安全異常?

InitialContext ctx = new InitialContext(); 
    MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime"); 
    String serverName = System.getProperty("weblogic.Name"); 



     ObjectName on =new ObjectName("com.myCompanyName:Name=MyCutomBean,Type=MyCutomBean"); 
     boolean boolresult=(Boolean)server.invoke(on, "myMethod", 
     new Object[]{"a","b","c"} 
     ,new String[]{"java.lang.String","java.lang.String","java.lang.String"}); //throw exception 
      out.print(result); 
     out.print(boolresult); 

當我試圖訪問我們的定製豆類我得到這個異常:不允許受

訪問:校長= [],上的ResourceType:名稱操作:執行,目標:myMethod

可能是什麼問題?

回答

2

我終於找到一個解決方案 避免這種例外u需要使用來驗證您的語境下:

Hashtable props = new Hashtable(); 
     props.put(Context.INITIAL_CONTEXT_FACTORY, 
       "weblogic.jndi.WLInitialContextFactory"); 

     props.put(Context.SECURITY_PRINCIPAL, "<userName>"); 
     props.put(Context.SECURITY_CREDENTIALS, "<password>"); 
     Context ctx = new InitialContext(props); MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime"); 

希望這會幫助別人