use of org.apache.catalina.Role 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.Role in project tomcat by apache.
the class DataSourceUserDatabase method findRole.
@Override
public Role findRole(String rolename) {
dbReadLock.lock();
try {
rolesReadLock.lock();
try {
// Check local changes first
Role role = createdRoles.get(rolename);
if (role != null) {
return role;
}
role = modifiedRoles.get(rolename);
if (role != null) {
return role;
}
role = removedRoles.get(rolename);
if (role != null) {
return null;
}
if (userRoleTable != null && roleNameCol != null) {
Connection dbConnection = openConnection();
if (dbConnection == null) {
return null;
}
try {
return findRoleInternal(dbConnection, rolename);
} finally {
closeConnection(dbConnection);
}
} else {
return null;
}
} finally {
rolesReadLock.unlock();
}
} finally {
dbReadLock.unlock();
}
}
use of org.apache.catalina.Role in project tomcat by apache.
the class DataSourceUserDatabase method getRoles.
@Override
public Iterator<Role> getRoles() {
dbReadLock.lock();
try {
rolesReadLock.lock();
try {
HashMap<String, Role> roles = new HashMap<>();
roles.putAll(createdRoles);
roles.putAll(modifiedRoles);
Connection dbConnection = openConnection();
if (dbConnection != null && preparedAllRoles != null) {
try (PreparedStatement stmt = dbConnection.prepareStatement(preparedAllRoles)) {
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String roleName = rs.getString(1);
if (roleName != null) {
if (!roles.containsKey(roleName) && !removedRoles.containsKey(roleName)) {
Role role = findRoleInternal(dbConnection, roleName);
if (role != null) {
roles.put(roleName, role);
}
}
}
}
}
} catch (SQLException e) {
log.error(sm.getString("dataSourceUserDatabase.exception"), e);
} finally {
closeConnection(dbConnection);
}
}
return roles.values().iterator();
} finally {
rolesReadLock.unlock();
}
} finally {
dbReadLock.unlock();
}
}
use of org.apache.catalina.Role in project tomcat by apache.
the class DataSourceUserDatabase method createRole.
@Override
public Role createRole(String rolename, String description) {
dbReadLock.lock();
try {
rolesWriteLock.lock();
try {
Role role = new GenericRole<>(this, rolename, description);
createdRoles.put(rolename, role);
modifiedRoles.remove(rolename);
return role;
} finally {
rolesWriteLock.unlock();
}
} finally {
dbReadLock.unlock();
}
}
use of org.apache.catalina.Role 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;
}
Aggregations