use of org.apache.catalina.Group in project tomcat70 by apache.
the class GroupMBean method addRole.
// ------------------------------------------------------------- Operations
/**
* Add a new {@link Role} to those this group belongs to.
*
* @param rolename Role name of the new role
*/
public void addRole(String rolename) {
Group group = (Group) this.resource;
if (group == null) {
return;
}
Role role = group.getUserDatabase().findRole(rolename);
if (role == null) {
throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
}
group.addRole(role);
}
use of org.apache.catalina.Group in project tomcat by apache.
the class MemoryUserCreationFactory method removeRole.
/**
* Remove the specified {@link Role} from this user database.
*
* @param role The role to be removed
*/
@Override
public void removeRole(Role role) {
readLock.lock();
try {
Iterator<Group> groups = getGroups();
while (groups.hasNext()) {
Group group = groups.next();
group.removeRole(role);
}
Iterator<User> users = getUsers();
while (users.hasNext()) {
User user = users.next();
user.removeRole(role);
}
roles.remove(role.getRolename());
} finally {
readLock.unlock();
}
}
use of org.apache.catalina.Group in project tomcat by apache.
the class DataSourceUserDatabase method findGroupInternal.
public Group findGroupInternal(Connection dbConnection, String groupName) {
Group group = null;
try (PreparedStatement stmt = dbConnection.prepareStatement(preparedGroup)) {
stmt.setString(1, groupName);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
if (rs.getString(1) != null) {
String description = (roleAndGroupDescriptionCol != null) ? rs.getString(2) : null;
ArrayList<Role> groupRoles = new ArrayList<>();
if (groupName != null) {
groupName = groupName.trim();
try (PreparedStatement stmt2 = dbConnection.prepareStatement(preparedGroupRoles)) {
stmt2.setString(1, groupName);
try (ResultSet rs2 = stmt2.executeQuery()) {
while (rs2.next()) {
String roleName = rs2.getString(1);
if (roleName != null) {
Role groupRole = findRoleInternal(dbConnection, roleName);
if (groupRole != null) {
groupRoles.add(groupRole);
}
}
}
}
} catch (SQLException e) {
log.error(sm.getString("dataSourceUserDatabase.exception"), e);
}
}
group = new GenericGroup<>(this, groupName, description, groupRoles);
}
}
}
} catch (SQLException e) {
log.error(sm.getString("dataSourceUserDatabase.exception"), e);
}
return group;
}
use of org.apache.catalina.Group in project tomcat by apache.
the class DataSourceUserDatabase method findUserInternal.
public User findUserInternal(Connection dbConnection, String userName) {
String dbCredentials = null;
String fullName = null;
try (PreparedStatement stmt = dbConnection.prepareStatement(preparedUser)) {
stmt.setString(1, userName);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
dbCredentials = rs.getString(1);
if (userFullNameCol != null) {
fullName = rs.getString(2);
}
}
dbCredentials = (dbCredentials != null) ? dbCredentials.trim() : null;
}
} catch (SQLException e) {
log.error(sm.getString("dataSourceUserDatabase.exception"), e);
}
// Lookup groups
ArrayList<Group> groups = new ArrayList<>();
if (isGroupStoreDefined()) {
try (PreparedStatement stmt = dbConnection.prepareStatement(preparedUserGroups)) {
stmt.setString(1, userName);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String groupName = rs.getString(1);
if (groupName != null) {
Group group = findGroupInternal(dbConnection, groupName);
if (group != null) {
groups.add(group);
}
}
}
}
} catch (SQLException e) {
log.error(sm.getString("dataSourceUserDatabase.exception"), e);
}
}
ArrayList<Role> roles = new ArrayList<>();
if (userRoleTable != null && roleNameCol != null) {
try (PreparedStatement stmt = dbConnection.prepareStatement(preparedUserRoles)) {
stmt.setString(1, userName);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String roleName = rs.getString(1);
if (roleName != null) {
Role role = findRoleInternal(dbConnection, roleName);
if (role != null) {
roles.add(role);
}
}
}
}
} catch (SQLException e) {
log.error(sm.getString("dataSourceUserDatabase.exception"), e);
}
}
User user = new GenericUser<>(this, userName, dbCredentials, fullName, groups, roles);
return user;
}
use of org.apache.catalina.Group in project tomcat by apache.
the class DataSourceUserDatabase method createGroup.
@Override
public Group createGroup(String groupname, String description) {
dbReadLock.lock();
try {
groupsWriteLock.lock();
try {
Group group = new GenericGroup<>(this, groupname, description, null);
createdGroups.put(groupname, group);
modifiedGroups.remove(groupname);
return group;
} finally {
groupsWriteLock.unlock();
}
} finally {
dbReadLock.unlock();
}
}
Aggregations