private VertexiumUser createFromVertex(Vertex user) { if (user == null) { return null; } String[] authorizations = toArray(getAuthorizations(user), String.class); SimpleOrmContext simpleOrmContext = getSimpleOrmContext(authorizations); LOGGER.debug( "Creating user from UserRow. username: %s", UserVisalloProperties.USERNAME.getPropertyValue(user)); return new VertexiumUser(user, simpleOrmContext); }
@Override public User findByUsername(String username) { username = formatUsername(username); Iterable<Vertex> vertices = graph .query(authorizations) .has(UserVisalloProperties.USERNAME.getPropertyName(), username) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), userConceptId) .vertices(); Vertex userVertex = singleOrDefault(vertices, null); if (userVertex == null) { return null; } userVertexCache.put(userVertex.getId(), userVertex); return createFromVertex(userVertex); }
@Override protected User addUser( String username, String displayName, String emailAddress, String password, String[] userAuthorizations) { username = formatUsername(username); displayName = displayName.trim(); String authorizationsString = StringUtils.join(userAuthorizations, ","); byte[] salt = UserPasswordUtil.getSalt(); byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt); String id = GRAPH_USER_ID_PREFIX + graph.getIdGenerator().nextId(); VertexBuilder userBuilder = graph.prepareVertex(id, VISIBILITY.getVisibility()); VisalloProperties.CONCEPT_TYPE.setProperty( userBuilder, userConceptId, VISIBILITY.getVisibility()); UserVisalloProperties.USERNAME.setProperty(userBuilder, username, VISIBILITY.getVisibility()); UserVisalloProperties.DISPLAY_NAME.setProperty( userBuilder, displayName, VISIBILITY.getVisibility()); UserVisalloProperties.CREATE_DATE.setProperty( userBuilder, new Date(), VISIBILITY.getVisibility()); UserVisalloProperties.PASSWORD_SALT.setProperty(userBuilder, salt, VISIBILITY.getVisibility()); UserVisalloProperties.PASSWORD_HASH.setProperty( userBuilder, passwordHash, VISIBILITY.getVisibility()); UserVisalloProperties.STATUS.setProperty( userBuilder, UserStatus.OFFLINE.toString(), VISIBILITY.getVisibility()); UserVisalloProperties.AUTHORIZATIONS.setProperty( userBuilder, authorizationsString, VISIBILITY.getVisibility()); UserVisalloProperties.PRIVILEGES.setProperty( userBuilder, Privilege.toString(getDefaultPrivileges()), VISIBILITY.getVisibility()); if (emailAddress != null) { UserVisalloProperties.EMAIL_ADDRESS.setProperty( userBuilder, emailAddress, VISIBILITY.getVisibility()); } User user = createFromVertex(userBuilder.save(this.authorizations)); graph.flush(); afterNewUserAdded(user); return user; }