我想为我的Web服务实现HTTP基本身份验证,但我也想使用ObjectDB来存储凭据。有没有办法做到这一点?我想我需要一个自定义的领域,而且,之前有人已经这样做了,所以如果是的话,请举手。否则,请帮助我执行。我已经检查了制作自定义领域的基础知识。是否有可能以某种方式使其与JDBCRealm一起工作,或者更直接地,是否可以在使用ObjectDB服务器的GlassFish中创建JDBC资源?ObjectDB的自定义领域,使用ObjectDB与HTTP基本身份验证
我做什么迄今已是Realm
的基础:
package objectdbrealm;
import com.sun.appserv.security.AppservRealm;
import com.sun.enterprise.security.auth.realm.BadRealmException;
import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException;
import java.util.Enumeration;
import java.util.Properties;
public class ObjectDbRealm extends AppservRealm {
@Override
public void init(Properties properties) throws BadRealmException, NoSuchRealmException {
//initialize the realm
}
@Override
public String getAuthType() {
return "ObjectDB Realm";
}
@Override
public Enumeration getGroupNames(String string) throws InvalidOperationException, NoSuchUserException {
throw new UnsupportedOperationException("Not supported yet.");
}
}
,并LoginModule
:
package objectdbrealm;
import com.sun.appserv.security.AppservPasswordLoginModule;
import com.sun.enterprise.security.auth.login.common.LoginException;
public class ObjectDbLoginModule extends AppservPasswordLoginModule {
@Override
protected void authenticateUser() throws LoginException {
if (!authenticate(_username, _passwd)) {
//Login fails
throw new LoginException((new StringBuilder()).append("Login Failed for:").append(_username).toString());
}
String[] groups = getGroupNames(_username);
commitUserAuthentication(groups);
}
private boolean authenticate(String username, char[] password) {
/*
Check the credentials against the authentication source,
return true if authenticated, return false otherwise
*/
return true;
}
private String[] getGroupNames(String username) {
// Return the list of groups this user belongs to.
return new String[0];
}
}
UPDATE
可悲it turned out即不存在用于JDBC驱动程序ObjectDB呢。不过随意提出建议!
在此先感谢!