throws Exception {
CoreUtil.clearFlow(request);
ShowAvailableRolesForm showAvailableRolesForm = ((ShowAvailableRolesForm) form);
try {
UserDatabase userDatabase = UserDatabaseManager.getInstance().getUserDatabase(getSessionInfo(request).getUser().getRealm());
Role[] roles = null;
try {
String filterText = showAvailableRolesForm.getFilterText();
int maxRoleResults = userDatabase.getMaxRoleResults();
String filter = Util.isNullOrTrimmedBlank(filterText) ? UserDatabase.WILDCARD_SEARCH : filterText;
roles = userDatabase.listAllRoles(filter, maxRoleResults);
if (roles.length > maxRoleResults) {
int newLength = roles.length - 1;
Role[] copy = new Role[newLength];
System.arraycopy(roles, 0, copy, 0, newLength);
roles = copy;
saveMessage(request, "availableRoles.match.limited", maxRoleResults);
}
} catch (Exception e) {
log.error("Failed to get available roles.", e);
ActionMessages errs = new ActionMessages();
errs.add(Globals.ERROR_KEY, new ActionMessage("availableRoles.cannotListRoles", Util.getExceptionMessageChain(e)));
saveErrors(request, errs);
roles = new Role[0];
}
showAvailableRolesForm.initialize(roles, request.getSession());
ActionMessages msgs = new ActionMessages();
if (!userDatabase.supportsAccountCreation()) {
msgs.add(Globals.MESSAGE_KEY, new ActionMessage("availableRoles.noRoleCreation.text"));
}
if (msgs.size() > 0) {
saveMessages(request, msgs);
}