import java.io.*; import java.security.*; import java.security.acl.*; import java.util.*; import com.sun.server.realm.*; import com.sun.server.realm.util.*; public class DatabaseRealm extends Realm { private FileAclInfo aclInfo = null; public DatabaseRealm() { super(); aclInfo = new FileAclInfo(this); } public Acl getAcl() throws BadRealmException { return aclInfo.getAcl(); } public Enumeration getAclNames() throws BadRealmException { return aclInfo.getAclNames(); } public Acl getAcl(String name) throws NoSuchAclException, BadRealmException { return aclInfo.getAcl(name); } public Acl addAcl(String name, Principal owner) throws BadRealmException { return aclInfo.makeAcl(name, owner); } public void removeAcl(String name) throws NoSuchAclException, BadRealmException { aclInfo.deleteAcl(name); } public synchronized void init(Properties props) throws BadRealmException, NoSuchRealmException { try { super.init(props); // Do any database initilization here.. } catch(Exception e) { throw new BadRealmException(e.getMessage()); } } public Enumeration getGroupNames() throws BadRealmException { // Add JDBC code to get the group names here.. // Or // throw the following exception throw new BadRealmException("Not Implemented."); } public Group getGroup(String name) throws NoSuchGroupException, BadRealmException { // Return a Group object stored within database // Or // throw the following exception throw new BadRealmException("Not Implemented."); } public Group addGroup(String name) throws InUseException, BadRealmException { // Add a Group with a given name within database. // Or // throw the following exception throw new BadRealmException("Not Implemented."); } public boolean removeGroup(String name) throws InUseException, BadRealmException, NoSuchGroupException { // remove the group from within the database. // Or // throw the following exception throw new BadRealmException("Not Implemented."); } public Enumeration getUserNames() throws BadRealmException { // Query database & return a user list. // Or // throw the following exception throw new BadRealmException("Not Implemented."); } public User getUser(String name) throws NoSuchUserException, BadRealmException { // Query the database & return an object that is a subclass // of RealmUser object. // For example. // // return new DatabaseRealmUser(name, this); // Or // throw the following exception throw new BadRealmException("Not Implemented."); } public void deleteUser(String name) throws InUseException, BadRealmException, NoSuchUserException { // add code to delete user within this realm // Or // throw the following exception throw new BadRealmException("Not Implemented."); } public Principal getDefaultAclOwner() throws BadRealmException { try { // change this to reflect the default ACL owner in your // realm. return getUser("admin"); } catch(NoSuchUserException e) { throw new BadRealmException("Default Owner does not exist."); } } protected void setDefaultPolicies() throws BadRealmException { // Add default policies within this realm; // For example: // Existance of a user called "root" etc. } }