📄 accountserver.java
字号:
/**
* AccountServer.java Created on 2003-12-8
*
*/
package com.liuyang.jmx.account;
import java.util.Collection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.liuyang.ejb.cmp.account.AccountLocal;
import com.liuyang.ejb.cmp.account.AccountLocalHome;
/**
* @author liuyang
* @jmx.mbean name=":service=AccountServer"
*
*/
public class AccountServer implements AccountServerMBean {
AccountLocalHome home = null;
/**
* @jmx.managed-operation
*/
public boolean authenticate(String username, String password) {
try {
if(home==null){
Context iniCtx = new InitialContext();
Object objRef = iniCtx.lookup("cmp/AccountHomeLocal");
home = (AccountLocalHome)PortableRemoteObject.narrow(objRef, AccountLocalHome.class);
}
Collection users = home.findByUsername(username);
if((users!=null)&&(!users.isEmpty())){
AccountLocal account = (AccountLocal) users.iterator().next();
return password.equalsIgnoreCase(account.getPassword());
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
*
*
* @jmx.managed-operation
*/
public String createAccount(String username, String password) {
try {
System.out.println("username : "+ username+" password : "+password);
if(home==null){
Context iniCtx = new InitialContext();
Object objRef = iniCtx.lookup("cmp/AccountHomeLocal");
home = (AccountLocalHome)PortableRemoteObject.narrow(objRef, AccountLocalHome.class);
}
Collection users = home.findByUsername(username);
if((users!=null)&&(!users.isEmpty())){
AccountLocal account = (AccountLocal) users.iterator().next();
account.remove();
}
home.create(username,password);
return username;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -