/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.catalina;

import java.util.Iterator;

Abstract representation of a database of Users and Groups that can be maintained by an application, along with definitions of corresponding Roles, and referenced by a Realm for authentication and access control.
Author:Craig R. McClanahan
Since:4.1
/** * Abstract representation of a database of {@link User}s and {@link Group}s * that can be maintained by an application, along with definitions of * corresponding {@link Role}s, and referenced by a {@link Realm} for * authentication and access control. * * @author Craig R. McClanahan * @since 4.1 */
public interface UserDatabase { // ------------------------------------------------------------- Properties
Returns:the set of Groups defined in this user database.
/** * @return the set of {@link Group}s defined in this user database. */
public Iterator<Group> getGroups();
Returns:the unique global identifier of this user database.
/** * @return the unique global identifier of this user database. */
public String getId();
Returns:the set of Roles defined in this user database.
/** * @return the set of {@link Role}s defined in this user database. */
public Iterator<Role> getRoles();
Returns:the set of Users defined in this user database.
/** * @return the set of {@link User}s defined in this user database. */
public Iterator<User> getUsers(); // --------------------------------------------------------- Public Methods
Finalize access to this user database.
Throws:
  • Exception – if any exception is thrown during closing
/** * Finalize access to this user database. * * @exception Exception if any exception is thrown during closing */
public void close() throws Exception;
Create and return a new Group defined in this user database.
Params:
  • groupname – The group name of the new group (must be unique)
  • description – The description of this group
Returns:The new group
/** * Create and return a new {@link Group} defined in this user database. * * @param groupname The group name of the new group (must be unique) * @param description The description of this group * @return The new group */
public Group createGroup(String groupname, String description);
Create and return a new Role defined in this user database.
Params:
  • rolename – The role name of the new role (must be unique)
  • description – The description of this role
Returns:The new role
/** * Create and return a new {@link Role} defined in this user database. * * @param rolename The role name of the new role (must be unique) * @param description The description of this role * @return The new role */
public Role createRole(String rolename, String description);
Create and return a new User defined in this user database.
Params:
  • username – The logon username of the new user (must be unique)
  • password – The logon password of the new user
  • fullName – The full name of the new user
Returns:The new user
/** * Create and return a new {@link User} defined in this user database. * * @param username The logon username of the new user (must be unique) * @param password The logon password of the new user * @param fullName The full name of the new user * @return The new user */
public User createUser(String username, String password, String fullName);
Params:
  • groupname – Name of the group to return
Returns:the Group with the specified group name, if any; otherwise return null.
/** * @return the {@link Group} with the specified group name, if any; * otherwise return <code>null</code>. * * @param groupname Name of the group to return */
public Group findGroup(String groupname);
Params:
  • rolename – Name of the role to return
Returns:the Role with the specified role name, if any; otherwise return null.
/** * @return the {@link Role} with the specified role name, if any; otherwise * return <code>null</code>. * * @param rolename Name of the role to return */
public Role findRole(String rolename);
Params:
  • username – Name of the user to return
Returns:the User with the specified user name, if any; otherwise return null.
/** * @return the {@link User} with the specified user name, if any; otherwise * return <code>null</code>. * * @param username Name of the user to return */
public User findUser(String username);
Initialize access to this user database.
Throws:
  • Exception – if any exception is thrown during opening
/** * Initialize access to this user database. * * @exception Exception if any exception is thrown during opening */
public void open() throws Exception;
Remove the specified Group from this user database.
Params:
  • group – The group to be removed
/** * Remove the specified {@link Group} from this user database. * * @param group The group to be removed */
public void removeGroup(Group group);
Remove the specified Role from this user database.
Params:
  • role – The role to be removed
/** * Remove the specified {@link Role} from this user database. * * @param role The role to be removed */
public void removeRole(Role role);
Remove the specified User from this user database.
Params:
  • user – The user to be removed
/** * Remove the specified {@link User} from this user database. * * @param user The user to be removed */
public void removeUser(User user);
Save any updated information to the persistent storage location for this user database.
Throws:
  • Exception – if any exception is thrown during saving
/** * Save any updated information to the persistent storage location for this * user database. * * @exception Exception if any exception is thrown during saving */
public void save() throws Exception;
Perform any background processing (e.g. checking for changes in persisted storage) required for the user database.
/** * Perform any background processing (e.g. checking for changes in persisted * storage) required for the user database. */
public default void backgroundProcess() { // NO-OP by default } }