BIEE用户自助修改密码

浏览: 1662

参考How it's done: Password change functionality in OBIEE

思路:

  1. 理解域运行时 MBean: myrealmDefaultAuthenticator的changeUserPassword操作 ;
  2. 创建Web Service并发布;
  3. 创建共享操作链接。

关键代码:

package userselfhelp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.PrintStream;

import java.net.MalformedURLException;

import java.util.Hashtable;

import javax.jws.WebMethod;
import javax.jws.WebService;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import javax.naming.Context;

@WebService
public class ChgUsrPswd {
private static JMXConnector cctor;
private static MBeanServerConnection mbsc;

//初始化连接
@WebMethod(exclude = true)
@SuppressWarnings("unchecked")
public static void InlCctn(String hostname, String portString, String username, String password) throws IOException,
MalformedURLException {
String protocol = "t3";
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.domainruntime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver);

Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
cctor = JMXConnectorFactory.connect(serviceURL, h);
mbsc = cctor.getMBeanServerConnection();
}
// 下面方法用于重置密码及验证
@WebMethod(exclude = true)
public String changeUserPassword(String usrID, String oldPswd, String newPswd, String cfrmPswd) throws Exception {
ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefaultAuthenticator");
Object objUser[] = new Object[] { (usrID), (oldPswd), (newPswd) };
String objStr[] = new String[] { ("java.lang.String"), ("java.lang.String"), ("java.lang.String") };
try {
if (cfrmPswd.equals(newPswd)) {
mbsc.invoke(securityMBeanName, "changeUserPassword", objUser, objStr);
return "重置密码成功";
} else {
return "新密码不匹配";
}
} catch (Exception e) {
if (e.getCause()
.getMessage()
.contains("Validation of old password failed"))
return "旧密码验证失败";
else if (e.getCause()
.getMessage()
.contains("must Be Eight Chars"))
return "密码长度必须为8位字符";
else if (e.getCause()
.getMessage()
.contains("missing Special Chars"))
return "密码至少包含1个数字或特殊字符";
else
return "未能重置密码,请联系管理员";
}
}

public String ChgPswd(String usrID, String oldPswd, String newPswd, String cfrmPswd) throws Exception {
ChgUsrPswd c = new ChgUsrPswd();
InlCctn("ip", "port", "Admin-user", "Admin-password");
String result = c.changeUserPassword(usrID, oldPswd, newPswd, cfrmPswd);
cctor.close();
return result;
}
}

建议使用JDeveloper Studio,可以一键部署。

推荐 0
本文由 wffger 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册