weblogic与portal用户同步
程序员文章站
2022-04-16 23:33:08
...
String url = "t3://localhost:8001"; String username = "weblogic"; String password = "weblogic"; String serverNm = "portalServer"; Connection con = getConnection(); try { CommoMBeanServer cmbs = Config.getMBeanServer(serverNm, url, username, password); DefaultAuthenticatorMBean dbean = (DefaultAuthenticatorMBean) cmbs.getMBean(new ObjectName( "Security:Name=myrealmDefaultAuthenticator")); ResultSet rs = null; PreparedStatement stmt = null; String sqlStr = " SELECT username, nvl(password,'123456') FROM tbl_um_user where username != 'weblogic'"; stmt = con.prepareStatement(sqlStr); rs = stmt.executeQuery(); while (rs.next()) { try { if(dbean.userExists(rs.getString(1))) { dbean.resetUserPassword(rs.getString(1),rs.getString(2)); } else { dbean.createUser(rs.getString(1),rs.getString(2),""); } } catch(Exception e) { e.printStackTrace(); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InvalidParameterException e) { e.printStackTrace(); } catch (JMException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }