private int create(CreateUserArgs args) { Set<String> authorizations = new HashSet<>(); if (args.authorizations != null && args.authorizations.length() > 0) { authorizations.addAll(Arrays.asList(StringUtils.split(args.authorizations, ','))); } Set<String> privileges; if (args.privileges == null) { privileges = getUserRepository().getDefaultPrivileges(); } else { privileges = Privilege.stringToPrivileges(args.privileges); } getUserRepository().findOrAddUser( args.userName, args.userName, null, args.password, privileges, authorizations ); User user = getUserRepository().findByUsername(args.userName); if (args.displayName != null) { getUserRepository().setDisplayName(user, args.displayName); } if (args.email != null) { getUserRepository().setEmailAddress(user, args.email); } printUser(getUserRepository().findById(user.getUserId())); return 0; }
protected User getUser() { if (this.user == null) { this.user = userRepository.getSystemUser(); } return this.user; }
private int delete(DeleteUserArgs args) { User user = findUser(args); getUserRepository().delete(user); System.out.println("Deleted user " + user.getUserId()); return 0; }
public User findOrAddUser( String username, String displayName, String emailAddress, String password ) { return lockRepository.lock("findOrAddUser", () -> { User user = findByUsername(username); if (user == null) { user = addUser(username, displayName, emailAddress, password); } return user; }); }
public User findUser(FindUserArgs findUserArgs) { User user = null; if (findUserArgs.userName != null) { user = getUserRepository().findByUsername(findUserArgs.userName); } else if (findUserArgs.userId != null) { user = getUserRepository().findById(findUserArgs.userId); } if (user == null) { throw new UserNotFoundException(findUserArgs); } return user; }
private int setAuthorizations(SetAuthorizationsArgs args) { Set<String> authorizations = new HashSet<>(); if (args.authorizations != null && args.authorizations.length() > 0) { authorizations.addAll(Arrays.asList(StringUtils.split(args.authorizations, ','))); } User user = findUser(args); getUserRepository().setAuthorizations(user, authorizations, getUserRepository().getSystemUser()); printUser(user); return 0; }
@Handle public JSONObject handle( @Required(name = "user-name") String userName, @Required(name = "auth") String auth, User authUser ) throws Exception { User user = userRepository.findByUsername(userName); if (user == null) { throw new VisalloResourceNotFoundException("User " + userName + " not found"); } if (!(authorizationRepository instanceof UpdatableAuthorizationRepository)) { throw new VisalloAccessDeniedException("Authorization repository does not support updating", authUser, userName); } for (String authStr : auth.split(SEPARATOR)) { ((UpdatableAuthorizationRepository) authorizationRepository).addAuthorization(user, authStr, authUser); } return userRepository.toJsonWithAuths(user); } }
@Handle public JSONObject handle( HttpServletRequest request ) throws Exception { final String username = UrlUtils.urlDecode(request.getParameter("username")).trim().toLowerCase(); User user = userRepository.findByUsername(username); if (user == null) { // For form based authentication, username and displayName will be the same String randomPassword = UserRepository.createRandomPassword(); user = userRepository.findOrAddUser( username, username, null, randomPassword ); } AuthorizationContext authorizationContext = new UserNameAuthorizationContext( username, RemoteAddressUtil.getClientIpAddr(request) ); userRepository.updateUser(user, authorizationContext); CurrentUser.set(request, user.getUserId(), user.getUsername()); auditService.auditLogin(user); JSONObject json = new JSONObject(); json.put("status", "OK"); return json; } }
private int setPrivileges(SetPrivilegesArgs args) { Set<String> privileges = Privilege.stringToPrivileges(args.privileges); User user = findUser(args); System.out.println("Assigning privileges " + privileges + " to user " + user.getUserId()); getUserRepository().setPrivileges(user, privileges, getUserRepository().getSystemUser()); user = getUserRepository().findById(user.getUserId()); printUser(user); return 0; }
users = new ArrayList<>(); for (String userId : userIds) { User u = userRepository.findById(userId); if (u == null) { LOGGER.error("User " + userId + " not found"); users = toList(userRepository.findByStatus(skip, limit, UserStatus.valueOf(status))); } else { users = toList(userRepository.find(query)); Map<String, String> workspaceNames = getWorkspaceNames(workspaceIds, user); return userRepository.toClientApi(users, workspaceNames);
private int setDisplayNameAndOrEmail(SetDisplayNameEmailArgs args) { if (args.displayName == null && args.email == null) { System.out.println("no display name or e-mail address provided"); return -2; } User user = findUser(args); if (args.displayName != null) { getUserRepository().setDisplayName(user, args.displayName); } if (args.email != null) { getUserRepository().setEmailAddress(user, args.email); } printUser(getUserRepository().findById(user.getUserId())); return 0; }
@Override public void before() throws Exception { super.before(); user = getUserRepository().findOrAddUser("base-junit", "Base Junit", "base-junit@visallo.com", "password"); User systemUser = getUserRepository().getSystemUser(); Authorizations authorizations = getAuthorizationRepository().getGraphAuthorizations(systemUser); thingConcept = getOntologyRepository().getEntityConcept(PUBLIC); List<Concept> things = Collections.singletonList(thingConcept); Relationship hasEntityRel = getOntologyRepository().getOrCreateRelationshipType(null, things, things, "has-entity-iri", true, systemUser, PUBLIC); hasEntityRel.addIntent("entityHasImage", user, authorizations); getOntologyRepository().getOrCreateConcept(thingConcept, JUNIT_CONCEPT_TYPE, "Junit Concept", null, systemUser, PUBLIC); getOntologyRepository().getOrCreateRelationshipType(null, things, things, JUNIT_EDGE_LABEL, true, systemUser, PUBLIC); OntologyPropertyDefinition propertyDefinition = new OntologyPropertyDefinition(things, JUNIT_PROPERTY_NAME, "Junit Property", PropertyType.STRING); propertyDefinition.setTextIndexHints(Collections.singleton(TextIndexHint.EXACT_MATCH)); propertyDefinition.setUserVisible(true); getOntologyRepository().getOrCreateProperty(propertyDefinition, systemUser, PUBLIC); getOntologyRepository().clearCache(); workspace = getWorkspaceRepository().add("ws1", "workspace 1", user); workspaceAuthorizations = getAuthorizationRepository().getGraphAuthorizations(user, workspace.getWorkspaceId()); }
private void ensureUser() { if (proxiedUser == null) { proxiedUser = userRepository.findById(userId); } }
@Handle public ClientApiSuccess handle( @Required(name = "user-name") String userName ) throws Exception { User user = userRepository.findByUsername(userName); if (user == null) { throw new VisalloResourceNotFoundException("Could find user: " + userName); } LOGGER.info("deleting user %s", user.getUserId()); userRepository.delete(user); this.graph.flush(); return VisalloResponse.SUCCESS; } }
private void switchWorkspace(String authUserId, String workspaceId) { if (!workspaceId.equals(userRepository.getCurrentWorkspaceId(authUserId))) { User authUser = userRepository.findById(authUserId); Workspace workspace = workspaceRepository.findById(workspaceId, authUser); userRepository.setCurrentWorkspace(authUserId, workspace.getWorkspaceId()); workQueueRepository.pushUserCurrentWorkspaceChange(authUser, workspace.getWorkspaceId()); LOGGER.debug("User %s switched current workspace to %s", authUserId, workspaceId); } }
@Handle public ClientApiUser handle( @Required(name = "user-name") String userName ) throws Exception { User user = userRepository.findByUsername(userName); if (user == null) { throw new VisalloResourceNotFoundException("user not found"); } Authorizations authorizations = authorizationRepository.getGraphAuthorizations(user); ClientApiUser clientApiUser = userRepository.toClientApiPrivate(user); Iterable<Workspace> workspaces = workspaceRepository.findAllForUser(user); for (Workspace workspace : workspaces) { clientApiUser.getWorkspaces().add(workspaceRepository.toClientApi(workspace, user, authorizations)); } return clientApiUser; } }
private List<User> loadUsers(UserStatus filter) { List<User> allUsers = new ArrayList<>(); int limit = 100; for (int skip = 0; ; skip += limit) { Iterable<User> usersIterable = (filter == null) ? getUserRepository().find(skip, limit) : getUserRepository().findByStatus(skip, limit, filter); List<User> userPage = toList(usersIterable); if (userPage.size() == 0) { break; } allUsers.addAll(userPage); } return allUsers; }
@Handle public ClientApiSuccess handle( @Required(name = "workspaceId") String workspaceId, @Required(name = "user-name") String userName, User me ) throws Exception { User user = userRepository.findByUsername(userName); if (user == null) { throw new VisalloResourceNotFoundException("Could not find user: " + userName); } Workspace workspace = workspaceRepository.findById(workspaceId, user); if (workspace == null) { throw new VisalloResourceNotFoundException("Could not find workspace: " + workspaceId); } workspaceRepository.updateUserOnWorkspace(workspace, me.getUserId(), WorkspaceAccess.WRITE, user); return VisalloResponse.SUCCESS; } }
@Before public void before() throws Exception { super.before(); authorizations = getGraph().createAuthorizations(); user = getUserRepository().findOrAddUser("junit", "Junit", "junit@visallo.com", "password"); Workspace workspace = getWorkspaceRepository().add(workspaceId, "Junit Workspace", user); if (getPrivilegeRepository().hasPrivilege(user, Privilege.ADMIN)) { fail("User shouldn't have admin"); } adminUser = getUserRepository().findOrAddUser("junit-admin", "Junit Admin", "junit-admin@visallo.com", "password"); Set<String> privileges = Privilege.ALL_BUILT_IN.stream().map(Privilege::getName).collect(Collectors.toSet()); setPrivileges(adminUser, privileges); getWorkspaceRepository().updateUserOnWorkspace(workspace, adminUser.getUserId(), WorkspaceAccess.WRITE, systemUser); }
private void setStatus(AtmosphereResource resource, UserStatus status) { broadcaster = resource.getBroadcaster(); try { String authUserId = CurrentUser.getUserId(resource.getRequest()); checkNotNull(authUserId, "Could not find user in session"); User authUser = userRepository.findById(authUserId); checkNotNull(authUser, "Could not find user with id: " + authUserId); if (authUser.getUserStatus() != status) { LOGGER.debug("Setting user %s status to %s", authUserId, status.toString()); userRepository.setStatus(authUserId, status); this.workQueueRepository.pushUserStatusChange(authUser, status); } } catch (Exception ex) { LOGGER.error("Could not update status", ex); } finally { // TODO session is held open by getAppSession // session.close(); } }