请帮我解决这个问题... 我做错了什么?
09.02.2013 19:44:16 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
javax.naming.NamingException: Lookup failed for 'hello' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business interfacemain.HelloRemote [Root exception is java.rmi.AccessException: CORBA NO_PERMISSION 0 No; nested exception is:
org.omg.CORBA.NO_PERMISSION: ----------BEGIN server-side stack trace----------
org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No
CreateJDBCRealmUser类在DB oracle 10g XE中创建用户
package main;
import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class CreateJDBCRealmUser {
private static final String driver = "oracle.jdbc.driver.OracleDriver";
private static final String jdbcUrl = "jdbc:oracle:thin:@127.0.0.1:1521/XE";
private static final String userSql = "insert into users values(?, ?)";
private static final String groupSql = "insert into groups values(?, ?)";
private static final char[] HEXADECIMAL = { '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static String hashPassword(String password) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
md.reset();
byte[] bytes = md.digest(password.getBytes());
StringBuilder sb = new StringBuilder(2 * bytes.length);
for (int i = 0; i < bytes.length; i++) {
int low = (int)(bytes[i] & 0x0f);
int high = (int)((bytes[i] & 0xf0) >> 4);
sb.append(HEXADECIMAL[high]);
sb.append(HEXADECIMAL[low]);
}
return sb.toString();
}
public static void main(String args[]) throws Exception {
String dbUser = "dbuser";
String dbPassword = "dbpass";
String user = "admin";
String password = "admin";
String group = "admin";
Class.forName(driver);
String hPassword = hashPassword(password);
Connection conn = DriverManager.getConnection(
jdbcUrl, dbUser, dbPassword);
PreparedStatement userStmt = conn.prepareStatement(userSql);
userStmt.setString(1, user);
userStmt.setString(2, hPassword);
userStmt.executeUpdate();
userStmt.close();
PreparedStatement groupStmt = conn.prepareStatement(groupSql);
groupStmt.setString(1, user);
groupStmt.setString(2, group);
groupStmt.executeUpdate();
groupStmt.close();
conn.close();
}
}
HelloClient - 它是一个JAVA应用程序客户端
package main;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.sun.appserv.security.ProgrammaticLogin;
public class HelloClient {
/**
* @param args
*/
public static void main(String[] args) {
try
{
InitialContext ic = null;
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
System.setProperty("java.security.auth.login.config", "./auth.conf");
ProgrammaticLogin pl = new ProgrammaticLogin();
String spass = new String("admin");
char pass[] = new char[spass.length()];
pass = spass.toCharArray();
pl.login("admin", pass);
try {
ic = new InitialContext();
} catch (NamingException e1) {
e1.printStackTrace();
}
Object obj = ic.lookup("hello");
HelloRemote hello = (HelloRemote)obj;
/*
Call a business method, propagating the security context
*/
String result;
try {
result = hello.hello();
result = hello.helloNoPermit();
}
catch (javax.ejb.EJBException e) {
result = e.getCausedByException().getMessage();
}
/* Print the return result from the business logic */
System.out.println(result);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
HelloRemote - 客户端与EJB的远程接口,服务器端存在相同的远程接口/
package main;
import javax.ejb.Remote;
@Remote
public interface HelloRemote {
String helloNoPermit();
String hello();
}
Hello - 它是一个实现HelloRemote
package main;
import javax.annotation.Resource;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
import javax.ejb.SessionContext;
import javax.ejb.Singleton;
/**
* Session Bean implementation class Hello
*/
@Singleton(mappedName = "hello")
@DeclareRoles("admin")
public class Hello implements HelloRemote {
@Resource
private SessionContext context;
public Hello() {
}
@RolesAllowed("admin")
public String helloNoPermit(){
String name = context.getCallerPrincipal().getName();
System.out.println(name);
return name;
}
public String hello(){
String name = context.getCallerPrincipal().getName();
System.out.println(name);
return name;
}
}
auth.conf - 配置文件
default {
com.sun.enterprise.security.auth.login.ClientPasswordLoginModule required debug=false;
};
SQL DDL
create table USERS
(
USER_NAME VARCHAR2(4000),
USER_PASS VARCHAR2(4000)
)
create table GROUPS
(
GROUP_NAME VARCHAR2(4000),
USER_NAME VARCHAR2(4000)
)
和最终GF 3.1.2.2 JDBC REALM配置
Security Manager: V
Audit Logging: V
Default Realm secureRealm:
Default Principal:
Default Principal Password:
JACC: default
Audit Modules: default
Default Principal To Role Mapping: V
Mapped Principal Class:
Realm Name:secureRealm
Class Name: com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm
JAAS Context: secureRealm
JNDI: jdbc/secure
User Table:USERS
User Name Column:USER_NAME
Password Column:USER_PASS
Group Table:GROUPS
Group Table User Name Column:USER_NAME
Group Name Column:GROUP_NAME
Assign Groups:admin
Database User:
Database Password:
Digest Algorithm:MD5
Password Encryption Algorithm:MD5
Encoding:
Charset:
太阳ejb-jar.xml中
<sun-ejb-jar>
<security-role-mapping>
<role-name>admin</role-name>
<group-name>admin</group-name>
</security-role-mapping>
<enterprise-beans />
</sun-ejb-jar>