Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. @GET
  2.     @Produces(MediaType.APPLICATION_JSON)
  3.     public List<UserRepresentation> get(@QueryParam("search") String search,
  4.                                         @QueryParam("lastName")
  5.                                         String last,
  6.                                         @QueryParam("firstName")
  7.                                         String first,
  8.                                         @QueryParam("email")
  9.                                         String email,
  10.                                         @QueryParam("username")
  11.                                         String username,
  12.                                         @QueryParam("first")
  13.                                         Integer firstResult,
  14.                                         @QueryParam("max")
  15.                                         Integer maxResults)
  16.     {
  17.         RealmModel realm = session.getContext().getRealm();
  18.         UserModel userM = session.users().getUserByUsername("authorized", realm);
  19.         AdminPermissionEvaluator auth = AdminPermissions.evaluator(session, realm, realm, userM);
  20.        
  21.         auth.users().requireQuery();
  22.  
  23.         firstResult = firstResult != null ? firstResult : -1;
  24.         maxResults = maxResults != null ? maxResults : Constants.DEFAULT_MAX_RESULTS;
  25.  
  26.         List<UserRepresentation> results = new ArrayList<UserRepresentation>();
  27.         List<UserModel> userModels;
  28.         if (search != null) {
  29.             userModels = session.users().searchForUser(search.trim(), realm, firstResult, maxResults);
  30.         } else if (last != null || first != null || email != null || username != null) {
  31.             Map<String, String> attributes = new HashMap<String, String>();
  32.             if (last != null) {
  33.                 attributes.put(UserModel.LAST_NAME, last);
  34.             }
  35.             if (first != null) {
  36.                 attributes.put(UserModel.FIRST_NAME, first);
  37.             }
  38.             if (email != null) {
  39.                 attributes.put(UserModel.EMAIL, email);
  40.             }
  41.             if (username != null) {
  42.                 attributes.put(UserModel.USERNAME, username);
  43.             }
  44.             userModels = session.users().searchForUser(attributes, realm, firstResult, maxResults);
  45.         } else {
  46.             userModels = session.users().getUsers(realm, firstResult, maxResults, false);
  47.         }
  48.  
  49.         boolean canViewGlobal = auth.users().canView();
  50.         for (UserModel user : userModels) {
  51.             if (!canViewGlobal && !auth.users().canView(user))
  52.                 continue;
  53.             UserRepresentation userRep = ModelToRepresentation.toRepresentation(session, realm, user);
  54.             userRep.setAccess(auth.users().getAccess(user));
  55.             results.add(userRep);
  56.         }
  57.        
  58.         return results;
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement