Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public List<UserRepresentation> get(@QueryParam("search") String search,
- @QueryParam("lastName")
- String last,
- @QueryParam("firstName")
- String first,
- @QueryParam("email")
- String email,
- @QueryParam("username")
- String username,
- @QueryParam("first")
- Integer firstResult,
- @QueryParam("max")
- Integer maxResults)
- {
- RealmModel realm = session.getContext().getRealm();
- UserModel userM = session.users().getUserByUsername("authorized", realm);
- AdminPermissionEvaluator auth = AdminPermissions.evaluator(session, realm, realm, userM);
- auth.users().requireQuery();
- firstResult = firstResult != null ? firstResult : -1;
- maxResults = maxResults != null ? maxResults : Constants.DEFAULT_MAX_RESULTS;
- List<UserRepresentation> results = new ArrayList<UserRepresentation>();
- List<UserModel> userModels;
- if (search != null) {
- userModels = session.users().searchForUser(search.trim(), realm, firstResult, maxResults);
- } else if (last != null || first != null || email != null || username != null) {
- Map<String, String> attributes = new HashMap<String, String>();
- if (last != null) {
- attributes.put(UserModel.LAST_NAME, last);
- }
- if (first != null) {
- attributes.put(UserModel.FIRST_NAME, first);
- }
- if (email != null) {
- attributes.put(UserModel.EMAIL, email);
- }
- if (username != null) {
- attributes.put(UserModel.USERNAME, username);
- }
- userModels = session.users().searchForUser(attributes, realm, firstResult, maxResults);
- } else {
- userModels = session.users().getUsers(realm, firstResult, maxResults, false);
- }
- boolean canViewGlobal = auth.users().canView();
- for (UserModel user : userModels) {
- if (!canViewGlobal && !auth.users().canView(user))
- continue;
- UserRepresentation userRep = ModelToRepresentation.toRepresentation(session, realm, user);
- userRep.setAccess(auth.users().getAccess(user));
- results.add(userRep);
- }
- return results;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement