如何用Java代码来动态创建和配置WS的模块和属性
请教各位大大,如何用Java代码来动态创建和配置WS的一些模块和属性。我想用Java代码实现动态添加一个自定义的JAAS Login Module(这个Module已经打成jar包放在libext文件夹下了)到WS的Security->Secure administration, applications, and infrastructure->JAAS->Login Module。我现在的问题是,代码能更改WS相应的security.xml并在Console中会显示出来新加的Login Module,但是调用该Login Module时WS会抛出找不到该类的异常,只有再重启服务器之后才能找到该Login Module。以下是我的Java代码,各位大大帮忙看看,谢谢!!
public void run(String[] args) throws Exception {
try {
// Initialize the AdminClient.
Properties adminProps = new Properties();
adminProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_RMI);
adminProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost");
adminProps.setProperty(AdminClient.CONNECTOR_PORT, "2809");
adminProps.setProperty(AdminClient.USERNAME, "supeipei307");
adminProps.setProperty(AdminClient.PASSWORD, "rollandsupeipei");
AdminClient adminClient = AdminClientFactory.createAdminClient(adminProps);
// Get the ConfigService implementation.
com.ibm.websphere.management.configservice.ConfigServiceProxy configService =
new com.ibm.websphere.management.configservice.ConfigServiceProxy(adminClient);
Session session = new Session();
// Use this group to add to the node scoped resource.xml.
ObjectName node1 = ConfigServiceHelper.createObjectName(null, "Node", null);
ObjectName[] matches = configService.queryConfigObjects(session, null, node1, null);
node1 = matches[0];
// Use this group to add to the server1 scoped resource.xml.
ObjectName server1 = ConfigServiceHelper.createObjectName(null, "Server", "server1");
matches = configService.queryConfigObjects(session, null, server1, null);
server1 = matches[0];
// Use this group to add to the server1 scoped resource.xml.
ObjectName jaasCfgs = ConfigServiceHelper.createObjectName(null, "JAASConfiguration", null);
matches = configService.queryConfigObjects(session, null, jaasCfgs, null);
ObjectName jaasCfg = matches[0];
// Create an attribute list and add attributes to it
AttributeList provAttrs = new AttributeList();
provAttrs.add(new Attribute("alias", "Oracle"));
ObjectName jdbcProv = configService.createConfigData(session,jaasCfg,"entries",
"JAASConfigurationEntry",provAttrs);
AttributeList lmAttrs = new AttributeList();
lmAttrs.add(new Attribute("moduleClassName", "test.jaas.OracleLoginModule_WebSphere"));
lmAttrs.add(new Attribute("authenticationStrategy","REQUIRED"));
ObjectName jaasLM = configService.createConfigData(session,jdbcProv,"loginModules",
"JAASLoginModule",lmAttrs);
AttributeList customAttrs = new AttributeList();
customAttrs.add(new Attribute("name", "tableName"));
customAttrs.add(new Attribute("value", "PAUL.MYUSER"));
ObjectName jaasAttrs = configService.createConfigData(session, jaasLM, "options",
"Property", customAttrs);
// Save the session
configService.save(session, true);
}
catch(Exception ex) {
ex.printStackTrace(System.out);
throw ex;
}
}
[ 本帖最后由 supeipei307 于 2008-12-23 12:59 编辑 ]