我想爲我的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呢。不過隨意提出建議!
在此先感謝!