use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class Util method retrievePaginatedFlaggedName.
public static PaginatedNamesBean retrievePaginatedFlaggedName(int pageNumber, String[] names) {
List<FlaggedName> list = new ArrayList<>();
FlaggedName flaggedName;
for (String name : names) {
flaggedName = new FlaggedName();
flaggedName.setItemName(name);
list.add(flaggedName);
}
return retrievePaginatedFlaggedName(pageNumber, list);
}
use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class UserAndRoleManagementServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String category = request.getParameter(CATEGORY);
HttpSession session = request.getSession();
if (USERS.equals(category)) {
boolean error = false;
boolean newFilter = false;
boolean doUserList = true;
boolean showFilterMessage = false;
boolean multipleUserStores = false;
String forwardTo = "user-mgt.jsp";
FlaggedName[] datas = null;
FlaggedName exceededDomains = null;
String[] claimUris = null;
FlaggedName[] users = null;
String[] domainNames = null;
int pageNumber = 0;
int cachePages = 3;
int noOfPageLinksToDisplay = 5;
int numberOfPages = 0;
Map<Integer, PaginatedNamesBean> flaggedNameMap = null;
String BUNDLE = "org.wso2.carbon.userstore.ui.i18n.Resources";
ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE, request.getLocale());
// remove session data
session.removeAttribute("userBean");
session.removeAttribute(UserAdminUIConstants.USER_DISPLAY_NAME);
session.removeAttribute(UserAdminUIConstants.USER_LIST_UNASSIGNED_ROLE_CACHE);
session.removeAttribute(UserAdminUIConstants.USER_LIST_UNASSIGNED_ROLE_CACHE_EXCEEDED);
session.removeAttribute(UserAdminUIConstants.USER_LIST_ASSIGNED_ROLE_CACHE);
session.removeAttribute(UserAdminUIConstants.USER_LIST_ASSIGNED_ROLE_CACHE_EXCEEDED);
session.removeAttribute(UserAdminUIConstants.USER_LIST_ADD_USER_ROLE_CACHE);
session.removeAttribute(UserAdminUIConstants.USER_LIST_ADD_USER_ROLE_CACHE_EXCEEDED);
session.removeAttribute(UserAdminUIConstants.USER_LIST_ASSIGN_ROLE_FILTER);
session.removeAttribute(UserAdminUIConstants.USER_LIST_UNASSIGNED_ROLE_FILTER);
session.removeAttribute(UserAdminUIConstants.USER_LIST_VIEW_ROLE_FILTER);
session.removeAttribute(UserAdminUIConstants.USER_LIST_CACHE);
// retrieve session attributes
UserRealmInfo userRealmInfo = (UserRealmInfo) session.getAttribute(UserAdminUIConstants.USER_STORE_INFO);
if (userRealmInfo != null) {
multipleUserStores = userRealmInfo.getMultipleUserStore();
}
java.lang.String errorAttribute = (java.lang.String) session.getAttribute(UserAdminUIConstants.DO_USER_LIST);
String claimUri = request.getParameter("claimUri");
if (claimUri == null || claimUri.length() == 0) {
claimUri = (java.lang.String) session.getAttribute(UserAdminUIConstants.USER_CLAIM_FILTER);
}
session.setAttribute(UserAdminUIConstants.USER_CLAIM_FILTER, claimUri);
exceededDomains = (FlaggedName) session.getAttribute(UserAdminUIConstants.USER_LIST_CACHE_EXCEEDED);
// search filter
String selectedDomain = request.getParameter(DOMAIN);
if (selectedDomain == null || selectedDomain.trim().length() == 0) {
selectedDomain = (String) session.getAttribute(UserAdminUIConstants.USER_LIST_DOMAIN_FILTER);
if (selectedDomain == null || selectedDomain.trim().length() == 0) {
selectedDomain = UserAdminUIConstants.ALL_DOMAINS;
}
} else {
newFilter = true;
}
session.setAttribute(UserAdminUIConstants.USER_LIST_DOMAIN_FILTER, selectedDomain.trim());
String filter = request.getParameter(UserAdminUIConstants.USER_LIST_FILTER);
if (filter == null || filter.trim().length() == 0) {
/*filter = (java.lang.String) session.getAttribute(UserAdminUIConstants.USER_LIST_FILTER);
if (filter == null || filter.trim().length() == 0) {
filter = "*";
}*/
filter = "*";
} else {
if (filter.contains(UserAdminUIConstants.DOMAIN_SEPARATOR)) {
selectedDomain = UserAdminUIConstants.ALL_DOMAINS;
session.removeAttribute(UserAdminUIConstants.USER_LIST_DOMAIN_FILTER);
}
newFilter = true;
}
String userDomainSelector;
String modifiedFilter = filter.trim();
if (!UserAdminUIConstants.ALL_DOMAINS.equalsIgnoreCase(selectedDomain)) {
modifiedFilter = selectedDomain + UserAdminUIConstants.DOMAIN_SEPARATOR + filter;
modifiedFilter = modifiedFilter.trim();
userDomainSelector = selectedDomain + UserAdminUIConstants.DOMAIN_SEPARATOR + "*";
} else {
userDomainSelector = "*";
}
session.setAttribute(UserAdminUIConstants.USER_LIST_FILTER, filter.trim());
// check page number
String pageNumberStr = request.getParameter("pageNumber");
if (pageNumberStr == null) {
pageNumberStr = "0";
}
if (userRealmInfo != null) {
claimUris = userRealmInfo.getRequiredUserClaims();
}
try {
pageNumber = Integer.parseInt(pageNumberStr);
} catch (NumberFormatException ignored) {
// page number format exception
}
flaggedNameMap = (Map<Integer, PaginatedNamesBean>) session.getAttribute(UserAdminUIConstants.USER_LIST_CACHE);
if (flaggedNameMap != null) {
PaginatedNamesBean bean = flaggedNameMap.get(pageNumber);
if (bean != null) {
users = bean.getNames();
if (users != null && users.length > 0) {
numberOfPages = bean.getNumberOfPages();
doUserList = false;
}
}
}
if (errorAttribute != null) {
error = true;
session.removeAttribute(UserAdminUIConstants.DO_USER_LIST);
}
if ((doUserList || newFilter) && !error) {
// don't call the back end if some kind of message is showing
try {
java.lang.String cookie = (java.lang.String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
java.lang.String backendServerURL = CarbonUIUtil.getServerURL(getServletConfig().getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) getServletConfig().getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
UserAdminClient client = new UserAdminClient(cookie, backendServerURL, configContext);
if (userRealmInfo == null) {
userRealmInfo = client.getUserRealmInfo();
session.setAttribute(UserAdminUIConstants.USER_STORE_INFO, userRealmInfo);
}
if (userRealmInfo != null) {
claimUris = userRealmInfo.getRequiredUserClaims();
}
if (filter.length() > 0) {
if (claimUri != null && !"select".equalsIgnoreCase(claimUri)) {
ClaimValue claimValue = new ClaimValue();
claimValue.setClaimURI(claimUri);
claimValue.setValue(modifiedFilter);
datas = client.listUserByClaimWithPermission(claimValue, userDomainSelector, PERMISSION_VIEWTASKS, -1);
} else {
datas = client.listAllUsersWithPermission(modifiedFilter, PERMISSION_VIEWTASKS, -1);
}
List<FlaggedName> dataList = new ArrayList<>(Arrays.asList(datas));
exceededDomains = dataList.remove(dataList.size() - 1);
session.setAttribute(UserAdminUIConstants.USER_LIST_CACHE_EXCEEDED, exceededDomains);
if (dataList.size() == 0) {
session.removeAttribute(UserAdminUIConstants.USER_LIST_FILTER);
showFilterMessage = true;
}
flaggedNameMap = new HashMap<>();
int max = pageNumber + cachePages;
for (int i = (pageNumber - cachePages); i < max; i++) {
if (i < 0) {
max++;
continue;
}
PaginatedNamesBean bean = Util.retrievePaginatedFlaggedName(i, dataList);
flaggedNameMap.put(i, bean);
if (bean.getNumberOfPages() == i + 1) {
break;
}
}
users = flaggedNameMap.get(pageNumber).getNames();
numberOfPages = flaggedNameMap.get(pageNumber).getNumberOfPages();
session.setAttribute(UserAdminUIConstants.USER_LIST_CACHE, flaggedNameMap);
}
} catch (Exception e) {
String message = MessageFormat.format(resourceBundle.getString("error.while.user.filtered"), e.getMessage());
}
String resp = "";
if (users != null) {
UserBean[] userList = new UserBean[users.length];
for (int i = 0; i < users.length; i++) {
FlaggedName flaggedName = users[i];
UserBean user = new UserBean();
user.setUsername(flaggedName.getItemName());
userList[i] = user;
}
UserSearchResult userSearchResult = new UserSearchResult();
userSearchResult.setPageNumber(pageNumber);
userSearchResult.setNumberOfPages(numberOfPages);
userSearchResult.setNoOfPageLinksToDisplay(noOfPageLinksToDisplay);
userSearchResult.setUserBeans(userList);
Gson gson = new Gson();
resp = gson.toJson(userSearchResult);
}
response.setContentType("application/json");
response.getWriter().write(resp);
}
} else if (ROLES.equals(category)) {
boolean error = false;
boolean newFilter = false;
boolean doRoleList = true;
boolean showFilterMessage = false;
boolean multipleUserStores = false;
List<FlaggedName> datasList = null;
FlaggedName[] roles = null;
FlaggedName exceededDomains = null;
String[] domainNames = null;
int pageNumber = 0;
int cachePages = 3;
int noOfPageLinksToDisplay = 5;
int numberOfPages = 0;
Map<Integer, PaginatedNamesBean> flaggedNameMap = null;
UserRealmInfo userRealmInfo = null;
// clear session data
session.removeAttribute("roleBean");
session.removeAttribute(UserAdminUIConstants.ROLE_READ_ONLY);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_UNASSIGNED_USER_CACHE);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_UNASSIGNED_USER_CACHE_EXCEEDED);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_ASSIGNED_USER_CACHE);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_ASSIGNED_USER_CACHE_EXCEEDED);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_ADD_ROLE_USER_CACHE);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_ADD_ROLE_USER_CACHE_EXCEEDED);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_ASSIGN_USER_FILTER);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_UNASSIGNED_USER_FILTER);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_VIEW_USER_FILTER);
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_CACHE);
session.removeAttribute(PREVIOUS_ROLE);
// search filter
String selectedDomain = request.getParameter(DOMAIN);
if (StringUtils.isBlank(selectedDomain)) {
selectedDomain = (String) session.getAttribute(UserAdminUIConstants.ROLE_LIST_DOMAIN_FILTER);
if (selectedDomain == null || selectedDomain.trim().length() == 0) {
selectedDomain = UserAdminUIConstants.ALL_DOMAINS;
}
} else {
newFilter = true;
}
session.setAttribute(UserAdminUIConstants.ROLE_LIST_DOMAIN_FILTER, selectedDomain.trim());
String filter = request.getParameter(UserAdminUIConstants.ROLE_LIST_FILTER);
if (filter == null || filter.trim().length() == 0) {
filter = (String) session.getAttribute(UserAdminUIConstants.ROLE_LIST_FILTER);
if (filter == null || filter.trim().length() == 0) {
filter = "*";
}
} else {
if (filter.contains(UserAdminUIConstants.DOMAIN_SEPARATOR)) {
selectedDomain = UserAdminUIConstants.ALL_DOMAINS;
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_DOMAIN_FILTER);
}
newFilter = true;
}
String modifiedFilter = filter.trim();
if (!UserAdminUIConstants.ALL_DOMAINS.equalsIgnoreCase(selectedDomain)) {
modifiedFilter = selectedDomain + UserAdminUIConstants.DOMAIN_SEPARATOR + filter;
modifiedFilter = modifiedFilter.trim();
}
session.setAttribute(UserAdminUIConstants.ROLE_LIST_FILTER, filter.trim());
userRealmInfo = (UserRealmInfo) session.getAttribute(UserAdminUIConstants.USER_STORE_INFO);
if (userRealmInfo != null) {
multipleUserStores = userRealmInfo.getMultipleUserStore();
}
String errorAttribute = (String) session.getAttribute(UserAdminUIConstants.DO_ROLE_LIST);
exceededDomains = (FlaggedName) session.getAttribute(UserAdminUIConstants.ROLE_LIST_CACHE_EXCEEDED);
// check page number
String pageNumberStr = request.getParameter("pageNumber");
if (pageNumberStr == null) {
pageNumberStr = "0";
}
try {
pageNumber = Integer.parseInt(pageNumberStr);
} catch (NumberFormatException ignored) {
// page number format exception
}
flaggedNameMap = (Map<Integer, PaginatedNamesBean>) session.getAttribute(UserAdminUIConstants.ROLE_LIST_CACHE);
if (flaggedNameMap != null) {
PaginatedNamesBean bean = flaggedNameMap.get(pageNumber);
if (bean != null) {
roles = bean.getNames();
if (roles != null && roles.length > 0) {
numberOfPages = bean.getNumberOfPages();
doRoleList = false;
}
}
}
if (errorAttribute != null) {
error = true;
session.removeAttribute(UserAdminUIConstants.DO_ROLE_LIST);
}
if ((doRoleList || newFilter) && !error) {
try {
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
String backendServerURL = CarbonUIUtil.getServerURL(getServletConfig().getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) getServletConfig().getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
UserAdminClient client = new UserAdminClient(cookie, backendServerURL, configContext);
boolean sharedRoleEnabled = client.isSharedRolesEnabled();
session.setAttribute(UserAdminUIConstants.SHARED_ROLE_ENABLED, sharedRoleEnabled);
if (filter.length() > 0) {
FlaggedName[] datas = client.getAllPermittedRoleNames(modifiedFilter, PERMISSION_VIEWTASKS, -1);
datasList = new ArrayList<FlaggedName>(Arrays.asList(datas));
exceededDomains = datasList.remove(datasList.size() - 1);
session.setAttribute(UserAdminUIConstants.ROLE_LIST_CACHE_EXCEEDED, exceededDomains);
datas = datasList.toArray(new FlaggedName[datasList.size()]);
if (datas == null || datas.length == 0) {
session.removeAttribute(UserAdminUIConstants.ROLE_LIST_FILTER);
showFilterMessage = true;
}
}
if (userRealmInfo == null) {
userRealmInfo = client.getUserRealmInfo();
session.setAttribute(UserAdminUIConstants.USER_STORE_INFO, userRealmInfo);
}
if (datasList != null) {
flaggedNameMap = new HashMap<Integer, PaginatedNamesBean>();
int max = pageNumber + cachePages;
for (int i = (pageNumber - cachePages); i < max; i++) {
if (i < 0) {
max++;
continue;
}
PaginatedNamesBean bean = Util.retrievePaginatedFlaggedName(i, datasList);
flaggedNameMap.put(i, bean);
if (bean.getNumberOfPages() == i + 1) {
break;
}
}
roles = flaggedNameMap.get(pageNumber).getNames();
numberOfPages = flaggedNameMap.get(pageNumber).getNumberOfPages();
session.setAttribute(UserAdminUIConstants.ROLE_LIST_CACHE, flaggedNameMap);
}
} catch (Exception e) {
}
String resp = "";
if (roles != null) {
RoleBean[] roleList = new RoleBean[roles.length];
for (int i = 0; i < roles.length; i++) {
FlaggedName flaggedName = roles[i];
RoleBean role = new RoleBean();
role.setRoleName(flaggedName.getItemName());
roleList[i] = role;
}
RoleSearchResult roleSearchResult = new RoleSearchResult();
roleSearchResult.setPageNumber(pageNumber);
roleSearchResult.setNumberOfPages(numberOfPages);
roleSearchResult.setNoOfPageLinksToDisplay(noOfPageLinksToDisplay);
roleSearchResult.setRoleBeans(roleList);
Gson gson = new Gson();
resp = gson.toJson(roleSearchResult);
}
response.setContentType("application/json");
response.getWriter().write(resp);
}
}
}
use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class UserAdmin method getAllPermittedRoleNames.
/**
* Get list of roles which have given permission
*
* @param filter filter to check
* @param permission permission to check
* @param limit
* @return
* @throws UserAdminException
*/
public FlaggedName[] getAllPermittedRoleNames(String filter, String permission, int limit) throws UserAdminException {
FlaggedName[] roles = getUserAdminProxy().getAllRolesNames(filter, limit);
List<FlaggedName> permittedRoles = new ArrayList<>();
try {
org.wso2.carbon.user.api.UserRealm realm = UserMgtDSComponent.getRealmService().getTenantUserRealm(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
AuthorizationManager authorizationManager = realm.getAuthorizationManager();
for (int i = 0; i < roles.length - 1; i++) {
if (authorizationManager.isRoleAuthorized(roles[i].getItemName(), permission, UserMgtConstants.EXECUTE_ACTION)) {
permittedRoles.add(roles[i]);
}
}
permittedRoles.add(roles[roles.length - 1]);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new UserAdminException("Error while filtering authorized roles.", e);
}
FlaggedName[] permittedRolesArray = new FlaggedName[permittedRoles.size()];
return permittedRoles.toArray(permittedRolesArray);
}
use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class UserAdminClient method listUserByClaimWithPermission.
public FlaggedName[] listUserByClaimWithPermission(ClaimValue claimValue, String filter, String permission, int limit) throws AxisFault {
try {
org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue newClaimValue = new org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue();
newClaimValue.setClaimURI(newClaimValue.getClaimURI());
newClaimValue.setValue(newClaimValue.getValue());
return stub.listUserByClaimWithPermission(newClaimValue, filter, permission, limit);
} catch (Exception e) {
handleException(e);
}
return new FlaggedName[0];
}
use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class UserRealmProxy method getUsersOfRole.
public FlaggedName[] getUsersOfRole(String roleName, String filter, int limit) throws UserAdminException {
try {
int index = roleName != null ? roleName.indexOf(CarbonConstants.DOMAIN_SEPARATOR) : -1;
boolean domainProvided = index > 0;
String domain = domainProvided ? roleName.substring(0, index) : null;
if (domain != null && filter != null && !filter.toLowerCase().startsWith(domain.toLowerCase()) && !(UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(domain) || UserMgtConstants.APPLICATION_DOMAIN.equalsIgnoreCase(domain))) {
filter = domain + CarbonConstants.DOMAIN_SEPARATOR + filter;
}
UserStoreManager usMan = realm.getUserStoreManager();
String[] usersOfRole;
boolean canLimitAndFilterUsersFromUMLevel = canLimitAndFilterUsersFromUMLevel(roleName, usMan);
if (domain == null && limit != 0) {
if (filter != null) {
filter = CarbonConstants.DOMAIN_SEPARATOR + filter;
} else {
filter = "/*";
}
}
/*
With the fix delivered for https://github.com/wso2/product-is/issues/6511, limiting and filtering from
the JDBC UserStoreManager is possible thus making the in-memory filtering and limiting logic in here
irrelevant for JDBC UM. But still, Read Only LDAP UM does not supports DB level limiting and filtering
(refer to https://github.com/wso2/product-is/issues/6573) thus the logic is kept as it is.
*/
if (canLimitAndFilterUsersFromUMLevel) {
int userCountLimit = getUserCountLimit(limit);
String domainFreeFilter = getDomainFreeFilter(filter);
AbstractUserStoreManager abstractUsMan = (AbstractUserStoreManager) usMan;
usersOfRole = abstractUsMan.getUserListOfRole(roleName, domainFreeFilter, userCountLimit);
} else {
usersOfRole = usMan.getUserListOfRole(roleName);
}
Arrays.sort(usersOfRole);
Map<String, Integer> userCount = new HashMap<String, Integer>();
if (limit == 0) {
filter = filter.replace("*", ".*");
Pattern pattern = Pattern.compile(filter, Pattern.CASE_INSENSITIVE);
List<FlaggedName> flaggedNames = new ArrayList<FlaggedName>();
for (String anUsersOfRole : usersOfRole) {
// check if display name is present in the user name
int combinerIndex = anUsersOfRole.indexOf(UserCoreConstants.NAME_COMBINER);
Matcher matcher;
if (combinerIndex > 0) {
matcher = pattern.matcher(anUsersOfRole.substring(combinerIndex + UserCoreConstants.NAME_COMBINER.length()));
} else {
matcher = pattern.matcher(anUsersOfRole);
}
if (!matcher.matches()) {
continue;
}
FlaggedName fName = new FlaggedName();
fName.setSelected(true);
if (combinerIndex > 0) {
// if display name is appended
fName.setItemName(anUsersOfRole.substring(0, combinerIndex));
fName.setItemDisplayName(anUsersOfRole.substring(combinerIndex + UserCoreConstants.NAME_COMBINER.length()));
} else {
// if only user name is present
fName.setItemName(anUsersOfRole);
fName.setItemDisplayName(anUsersOfRole);
}
if (domain != null && !(UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(domain) || UserMgtConstants.APPLICATION_DOMAIN.equalsIgnoreCase(domain))) {
if (usMan.getSecondaryUserStoreManager(domain) != null && (usMan.getSecondaryUserStoreManager(domain).isReadOnly() || FALSE.equals(usMan.getSecondaryUserStoreManager(domain).getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.WRITE_GROUPS_ENABLED)))) {
fName.setEditable(false);
} else {
fName.setEditable(true);
}
} else {
if (usMan.isReadOnly() || (usMan.getSecondaryUserStoreManager(domain) != null && FALSE.equals(usMan.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.WRITE_GROUPS_ENABLED)))) {
fName.setEditable(false);
} else {
fName.setEditable(true);
}
}
if (domain != null) {
if (userCount.containsKey(domain)) {
userCount.put(domain, userCount.get(domain) + 1);
} else {
userCount.put(domain, 1);
}
} else {
if (userCount.containsKey(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)) {
userCount.put(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, userCount.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME) + 1);
} else {
userCount.put(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, 1);
}
}
flaggedNames.add(fName);
}
String exceededDomains = "";
boolean isPrimaryExceeding = false;
Map<String, Integer> maxUserListCount = ((AbstractUserStoreManager) realm.getUserStoreManager()).getMaxListCount(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST);
String[] domains = userCount.keySet().toArray(new String[userCount.keySet().size()]);
for (int i = 0; i < domains.length; i++) {
if (UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME.equals(domains[i])) {
if (userCount.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME).equals(maxUserListCount.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME))) {
isPrimaryExceeding = true;
}
continue;
}
if (userCount.get(domains[i]).equals(maxUserListCount.get(domains[i].toUpperCase()))) {
exceededDomains += domains[i];
if (i != domains.length - 1) {
exceededDomains += ":";
}
}
}
FlaggedName flaggedName = new FlaggedName();
if (isPrimaryExceeding) {
flaggedName.setItemName("true");
} else {
flaggedName.setItemName(FALSE);
}
flaggedName.setItemDisplayName(exceededDomains);
flaggedNames.add(flaggedName);
return flaggedNames.toArray(new FlaggedName[flaggedNames.size()]);
}
String[] userNames = usMan.listUsers(filter, limit);
FlaggedName[] flaggedNames = new FlaggedName[userNames.length + 1];
for (int i = 0; i < userNames.length; i++) {
FlaggedName fName = new FlaggedName();
fName.setItemName(userNames[i]);
if (Arrays.binarySearch(usersOfRole, userNames[i]) > -1) {
fName.setSelected(true);
}
// check if display name is present in the user name
int combinerIndex = userNames[i].indexOf(UserCoreConstants.NAME_COMBINER);
if (combinerIndex > 0) {
// if display name is appended
fName.setItemName(userNames[i].substring(0, combinerIndex));
fName.setItemDisplayName(userNames[i].substring(combinerIndex + UserCoreConstants.NAME_COMBINER.length()));
} else {
// if only user name is present
fName.setItemName(userNames[i]);
}
if (domain != null && !(UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(domain) || UserMgtConstants.APPLICATION_DOMAIN.equalsIgnoreCase(domain))) {
if (usMan.getSecondaryUserStoreManager(domain) != null && (usMan.getSecondaryUserStoreManager(domain).isReadOnly() || FALSE.equals(usMan.getSecondaryUserStoreManager(domain).getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.WRITE_GROUPS_ENABLED)))) {
fName.setEditable(false);
} else {
fName.setEditable(true);
}
} else {
if (usMan.isReadOnly() || (usMan.getSecondaryUserStoreManager(domain) != null && FALSE.equals(usMan.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.WRITE_GROUPS_ENABLED)))) {
fName.setEditable(false);
} else {
fName.setEditable(true);
}
}
if (domain != null) {
if (userCount.containsKey(domain)) {
userCount.put(domain, userCount.get(domain) + 1);
} else {
userCount.put(domain, 1);
}
} else {
if (userCount.containsKey(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)) {
userCount.put(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, userCount.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME) + 1);
} else {
userCount.put(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, 1);
}
}
flaggedNames[i] = fName;
}
String exceededDomains = "";
boolean isPrimaryExceeding = false;
Map<String, Integer> maxUserListCount = ((AbstractUserStoreManager) realm.getUserStoreManager()).getMaxListCount(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST);
String[] domains = userCount.keySet().toArray(new String[userCount.keySet().size()]);
for (int i = 0; i < domains.length; i++) {
if (UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME.equals(domains[i])) {
if (userCount.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME).equals(maxUserListCount.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME))) {
isPrimaryExceeding = true;
}
continue;
}
if (userCount.get(domains[i]).equals(maxUserListCount.get(domains[i].toUpperCase()))) {
exceededDomains += domains[i];
if (i != domains.length - 1) {
exceededDomains += ":";
}
}
}
FlaggedName flaggedName = new FlaggedName();
if (isPrimaryExceeding) {
flaggedName.setItemName("true");
} else {
flaggedName.setItemName(FALSE);
}
flaggedName.setItemDisplayName(exceededDomains);
flaggedNames[flaggedNames.length - 1] = flaggedName;
return flaggedNames;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new UserAdminException(e.getMessage(), e);
}
}
Aggregations