Reputation: 1589
iam trying to follow the documentation of the mbeans for weblogic and create a web application to access an already created custom beans running in another application deployed in the server . iam using this code
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);
when i try to access our custom beans i got this exception :
Access not allowed for subject: principals=[], on ResourceType: Name Action: execute, Target: myMethod
what could be the problem ?
Upvotes: 1
Views: 483
Reputation: 1589
i finally find a solution to avoid this exception u need to authenticate your Context using the following :
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");
Hope this will help someone
Upvotes: 2