How do remove roles programatically?

How can I remove role assigned to a user programmatically?

Collection<RoleAssignment> roles = roleAssignmentRepository.getAssignmentsByUsername(user.getUsername());
                        for (RoleAssignment rl : roles) {
                            dataManager.remove(rl);
                        }

Above code gives error that meta class for RoleAssignment is not present.

Thanks and regards.

Hi Umesh,

If you want to remove role assignments from the database, you need RoleAssignmentEntity instead.

List<RoleAssignmentEntity> assignments = dataManager.load(RoleAssignmentEntity.class)
        .query("select e from sec_RoleAssignmentEntity e where e.username = :username")
        .parameter("username", username)
        .list();
for (RoleAssignmentEntity assignment : assignments) {
    dataManager.remove(assignment);
}

Regards,
Sergey.