public String index(Request req, Response res) throws Exception { Collection<User> allUsers = userService.allUsers(); HashMap<Username, RolesConfig> usersToRolesMap = roleConfigService.getRolesForUser(allUsers.stream().map(User::getUsername).collect(Collectors.toCollection(ArrayList::new))); List<UserToRepresent> users = allUsers.stream().map((User user) -> getUserToRepresent(user, usersToRolesMap)).collect(Collectors.toList()); return writerForTopLevelObject(req, res, writer -> UsersRepresenter.toJSON(writer, users)); }
public Collection<String> allRoleNames() { return allRoleNames(goConfigService.cruiseConfig()); }
public Collection<String> allRoleNames(CruiseConfig cruiseConfig) { List<String> roles = new ArrayList<>(); for (Role role : allRoles(cruiseConfig)) { roles.add(CaseInsensitiveString.str(role.getName())); } return roles; }
public long disabledUserCount() { return allUsersForDisplay().size() - enabledUserCount(); }
public void addUserIfDoesNotExist(User user) { synchronized (enableUserMutex) { if (!(user.isAnonymous() || userExists(user))) { assertUnknownUsersAreAllowedToLogin(user.getUsername()); userDao.saveOrUpdate(user); } } }
public String update(Request req, Response res) { User user = userService.findUserByName(currentUserLoginName().toString()); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); Map map = readRequestBodyAsJSON(req); String checkinAliases = null; if (map.containsKey("checkin_aliases")) { Object newAliases = map.get("checkin_aliases"); if (newAliases instanceof Collection) { checkinAliases = StringUtils.join((Collection) newAliases, ", "); } else if (newAliases instanceof String) { checkinAliases = (String) newAliases; } } TriState emailMe = TriState.from(String.valueOf(map.get("email_me"))); String email = (String) map.get("email"); User serializedUser = userService.save(user, TriState.from(null), emailMe, email, checkinAliases, result); String json = jsonizeAsTopLevelObject(req, writer -> UserRepresenter.toJSON(writer, serializedUser)); String etag = etagFor(json); setEtagHeader(res, etag); return json; } }
public String show(Request req, Response res) throws Exception { User user = userService.findUserByName(req.params("login_name")); if (user.equals(new NullUser())) { throw new RecordNotFoundException(); } UserToRepresent toRepresent = getUserToRepresent(user, roleConfigService.getRolesForUser(Collections.singletonList(user.getUsername()))); return writerForTopLevelObject(req, res, writer -> UserRepresenter.toJSON(writer, toRepresent)); }
private User getUser(HttpServletRequest request) { Long userId = SessionUtils.getUserId(request); if (userId == null) { final GoUserPrinciple currentUser = SessionUtils.getCurrentUser(); Username userName = new Username(currentUser.getUsername()); if (userName.isAnonymous() || userName.isGoAgentUser()) { return new NullUser(); } return userService.findUserByName(CaseInsensitiveString.str(userName.getUsername())); } else { return userService.load(userId); } } }
public List<UserModel> allUsersForDisplay(SortableColumn column, SortDirection direction) { List<UserModel> userModels = allUsersForDisplay(); Comparator<UserModel> userModelComparator = direction.forColumn(column); userModels.sort(userModelComparator); return userModels; }
public Set<String> usersThatCanOperateOnStage(CruiseConfig cruiseConfig, PipelineConfig pipelineConfig) { SortedSet<String> users = new TreeSet<>(); PipelineConfigs group = cruiseConfig.findGroupOfPipeline(pipelineConfig); if (group.hasAuthorizationDefined()) { if (group.hasOperationPermissionDefined()) { users.addAll(group.getOperateUserNames()); List<String> roles = group.getOperateRoleNames(); for (Role role : cruiseConfig.server().security().getRoles()) { if (roles.contains(CaseInsensitiveString.str(role.getName()))) { users.addAll(role.usersOfRole()); } } } } else { users.addAll(allUsernames()); } return users; }
userService.addUserIfDoesNotExist(toDomainUser(user));
private String saveUserAndRenderResult(Request req, Response res, HttpLocalizedOperationResult result, User userToOperate, User userFromRequest, String username) throws IOException { userService.save(userToOperate, TriState.from(userFromRequest.isEnabled()), TriState.from(userFromRequest.isEmailMe()), userFromRequest.getEmail(), userFromRequest.getMatcher(), result); boolean isSaved = result.isSuccessful(); if (isSaved) { return writerForTopLevelObject(req, res, writer -> UserRepresenter.toJSON(writer, getUserToRepresent(userService.findUserByName(username), roleConfigService.getRolesForUser(Collections.singletonList(new Username(username)))))); } else { return renderHTTPOperationResult(result, req, res); } }
public String create(Request req, Response res) throws Exception { HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); User user = buildUserEntityFromRequestBody(req, false); if (!userService.findUserByName(user.getName()).equals(new NullUser())) { throw haltBecauseEntityAlreadyExists(jsonWriter(user, new HashMap<>()), "User", user.getName()); } return saveUserAndRenderResult(req, res, result, user, user, user.getName()); }
public Set<String> allUsernames() { List<UserModel> userModels = allUsersForDisplay(); Set<String> users = new HashSet<>(); for (UserModel model : userModels) { users.add(model.getUser().getName()); } return users; }
public String show(Request req, Response res) { User user = userService.findUserByName(currentUserLoginName().toString()); String json = jsonizeAsTopLevelObject(req, writer -> UserRepresenter.toJSON(writer, user)); String etag = etagFor(json); if (fresh(req, etag)) { return notModified(res); } setEtagHeader(res, etag); return json; }
private List<UserModel> allUsersForDisplay() { Collection<User> users = allUsers(); ArrayList<UserModel> userModels = new ArrayList<>(); for (User user : users) { String userName = user.getName(); ArrayList<String> roles = new ArrayList<>(); for (Role role : goConfigService.rolesForUser(new CaseInsensitiveString(userName))) { roles.add(CaseInsensitiveString.str(role.getName())); } userModels.add(new UserModel(user, roles, securityService.isUserAdmin(new Username(new CaseInsensitiveString(userName))))); } return userModels; }
public Set<String> rolesThatCanOperateOnStage(CruiseConfig cruiseConfig, PipelineConfig pipelineConfig) { PipelineConfigs group = cruiseConfig.findGroupOfPipeline(pipelineConfig); SortedSet<String> roles = new TreeSet<>(); if (group.hasAuthorizationDefined()) { if (group.hasOperationPermissionDefined()) { roles.addAll(group.getOperateRoleNames()); } } else { roles.addAll(allRoleNames(cruiseConfig)); } return roles; }
public String patchUser(Request req, Response res) throws Exception { String username = req.params("login_name"); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); User userFromRequest = buildUserEntityFromRequestBody(req, true); User existingUser = userService.findUserByName(username); if (existingUser.equals(new NullUser())) { throw haltBecauseNotFound(); } if (isRenameAttempted(req, userFromRequest)) { throw haltBecauseRenameOfEntityIsNotSupported("User"); } return saveUserAndRenderResult(req, res, result, existingUser, userFromRequest, username); }