Java Code Examples for org.wso2.carbon.user.api.UserStoreManager#listUsers()
The following examples show how to use
org.wso2.carbon.user.api.UserStoreManager#listUsers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
/** * This method returns the count of users using UserStoreManager. * * @return user count */ private Response getUserCountViaUserStoreManager() { if (log.isDebugEnabled()) { log.debug("Getting the user count"); } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); int userCount = userStoreManager.listUsers("*", -1).length; BasicUserInfoList result = new BasicUserInfoList(); result.setCount(userCount); return Response.status(Response.Status.OK).entity(result).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving the user count."; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }
Example 2
Source File: UserManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
/** * This method returns the count of users using UserStoreManager. * * @return user count */ private Response getUserCountViaUserStoreManager() { if (log.isDebugEnabled()) { log.debug("Getting the user count"); } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); int userCount = userStoreManager.listUsers("*", -1).length; BasicUserInfoList result = new BasicUserInfoList(); result.setCount(userCount); return Response.status(Response.Status.OK).entity(result).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving the user count."; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }
Example 3
Source File: UserManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
@GET @Path("/search/usernames") @Override public Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain, @HeaderParam("If-Modified-Since") String timestamp, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { if (log.isDebugEnabled()) { log.debug("Getting the list of users with all user-related information using the filter : " + filter); } String userStoreDomain = Constants.PRIMARY_USER_STORE; if (domain != null && !domain.isEmpty()) { userStoreDomain = domain; } if (limit == 0){ //If there is no limit is passed, then return all. limit = -1; } List<UserInfo> userList; try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); String[] users = userStoreManager.listUsers(userStoreDomain + "/" + filter + "*", limit); userList = new ArrayList<>(); UserInfo user; for (String username : users) { user = new UserInfo(); user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); userList.add(user); } return Response.status(Response.Status.OK).entity(userList).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving the list of users using the filter : " + filter; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }
Example 4
Source File: UserManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
@GET @Path("/search/usernames") @Override public Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain, @HeaderParam("If-Modified-Since") String timestamp, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { if (log.isDebugEnabled()) { log.debug("Getting the list of users with all user-related information using the filter : " + filter); } String userStoreDomain = Constants.PRIMARY_USER_STORE; if (domain != null && !domain.isEmpty()) { userStoreDomain = domain; } if (limit == 0){ //If there is no limit is passed, then return all. limit = -1; } List<UserInfo> userList; try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); String[] users = userStoreManager.listUsers(userStoreDomain + "/" + filter + "*", limit); userList = new ArrayList<>(); UserInfo user; for (String username : users) { user = new UserInfo(); user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); userList.add(user); } return Response.status(Response.Status.OK).entity(userList).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving the list of users using the filter : " + filter; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }
Example 5
Source File: StratosUserManagerUtils.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * Get a List of usernames and associated Roles as a UserInfoBean * * @param userStoreManager UserStoreManager * @return List<UserInfoBean> * @throws UserManagerException */ public static List<UserInfoBean> getAllUsers(UserStoreManager userStoreManager) throws UserManagerException { String[] users; List<UserInfoBean> userList = new ArrayList<UserInfoBean>(); try { users = userStoreManager.listUsers(GET_ALL_USERS_WILD_CARD, -1); } catch (UserStoreException e) { String msg = "Error in listing the users in User Store"; log.error(msg, e); throw new UserManagerException(msg, e); } //Iterate through the list of users and retrieve their roles for (String user : users) { UserInfoBean userInfoBean = new UserInfoBean(); userInfoBean.setUserName(user); String[] refinedListOfRolesOfUser = getRefinedListOfRolesOfUser(userStoreManager, user); //TODO : Should support multiple roles for user if (refinedListOfRolesOfUser.length != 0) { userInfoBean.setRole(getRefinedListOfRolesOfUser(userStoreManager, user)[0]); } else { userInfoBean.setRole(INTERNAL_EVERYONE_ROLE); } userList.add(userInfoBean); } return userList; }
Example 6
Source File: UserManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 4 votes |
@GET @Override public Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { if (log.isDebugEnabled()) { log.debug("Getting the list of users with all user-related information"); } RequestValidationUtil.validatePaginationParameters(offset, limit); if (limit == 0) { limit = Constants.DEFAULT_PAGE_LIMIT; } List<BasicUserInfo> userList, offsetList; String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter + "*"); // to get whole set of users, appliedLimit is set to -1 // by default, this whole set is limited to 100 - MaxUserNameListLength of user-mgt.xml int appliedLimit = -1; try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); //As the listUsers function accepts limit only to accommodate offset we are passing offset + limit String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit); userList = new ArrayList<>(users.length); BasicUserInfo user; for (String username : users) { user = new BasicUserInfo(); user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); userList.add(user); } int toIndex = offset + limit; int listSize = userList.size(); int lastIndex = listSize - 1; if (offset <= lastIndex) { if (toIndex <= listSize) { offsetList = userList.subList(offset, toIndex); } else { offsetList = userList.subList(offset, listSize); } } else { offsetList = new ArrayList<>(); } BasicUserInfoList result = new BasicUserInfoList(); result.setList(offsetList); result.setCount(users.length); return Response.status(Response.Status.OK).entity(result).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving the list of users."; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }
Example 7
Source File: UserManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 4 votes |
@GET @Override public Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { if (log.isDebugEnabled()) { log.debug("Getting the list of users with all user-related information"); } RequestValidationUtil.validatePaginationParameters(offset, limit); if (limit == 0) { limit = Constants.DEFAULT_PAGE_LIMIT; } List<BasicUserInfo> userList, offsetList; String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter + "*"); // to get whole set of users, appliedLimit is set to -1 // by default, this whole set is limited to 100 - MaxUserNameListLength of user-mgt.xml int appliedLimit = -1; try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); //As the listUsers function accepts limit only to accommodate offset we are passing offset + limit String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit); userList = new ArrayList<>(users.length); BasicUserInfo user; for (String username : users) { user = new BasicUserInfo(); user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); userList.add(user); } int toIndex = offset + limit; int listSize = userList.size(); int lastIndex = listSize - 1; if (offset <= lastIndex) { if (toIndex <= listSize) { offsetList = userList.subList(offset, toIndex); } else { offsetList = userList.subList(offset, listSize); } } else { offsetList = new ArrayList<>(); } BasicUserInfoList result = new BasicUserInfoList(); result.setList(offsetList); result.setCount(users.length); return Response.status(Response.Status.OK).entity(result).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving the list of users."; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }