uCosminexus Application Server, Security Management Guide
EJB client applications can authenticate users by using their user names and passwords as defined in the J2EE server. After a user authenticated by the EJB client application logs in, he or she can call the Enterprise Bean method for which his or her security role is configured.
Cosminexus offers APIs to implement security in EJB client applications. The prerequisites and procedure for implementing this security are shown below. For details about the functionality and syntax of the APIs, see 4. APIs Available for EJB Client Applications, in the uCosminexus Application Server API Reference Guide.
Before implementing security, make sure that the following prerequisites are satisfied:
To implement security in an EJB client application, follow these steps:
import com.hitachi.software.ejb.security.base.authentication.* |
| LoginInfoManager lm = LoginInfoManager.getLoginInfoManager(); |
lm.login(username, password); |
lm.logout(); |
Below is a sample program for calling the getAccountID method, where the Enterprise Bean is named account.
import com.hitachi.software.ejb.security.base.authentication.*;
:
try {
LoginInfoManager lm = LoginInfoManager.getLoginInfoManager();
String userName = System.getProperty("username");
String password = System.getProperty("password");
if(lm.login(userName , password)) {
try {
System.out.println("user:" + userName + "login success");
Context ctx = new InitialContext();
java.lang.Object obj = ctx.lookup(appUnitPath + "Account");
AccountHome aHome =
(AccountHome)PortableRemoteObject.narrow(obj,AccountHome.class);
Account account = aHome.create();
account.getAccountID();
} finally {
lm.logout();
}
}
} catch(NotFoundServerException e) {
System.out.println("not found server");
} catch(InvalidUserNameException e) {
System.out.println("invalid user name");
} catch(InvalidPasswordException e) {
System.out.println("invalid password");
} catch(Exception e) {
e.printStackTrace();
}
|
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd