Examples of OUser


Examples of com.orientechnologies.orient.core.metadata.security.OUser

    }

    json.writeAttribute(1, false, "currentUser", db.getUser().getName());

    json.beginCollection(1, false, "users");
    OUser user;
    for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
      user = new OUser(doc);
      json.beginObject(2, true, null);
      json.writeAttribute(3, false, "name", user.getName());
      json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
      json.endObject(2, false);
    }
    json.endCollection(1, true);

    json.beginCollection(1, true, "roles");
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

     }

     json.writeAttribute(1, false, "currentUser", db.getUser().getName());

     json.beginCollection(1, false, "users");
     OUser user;
     for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
       user = new OUser(doc);
       json.beginObject(2, true, null);
       json.writeAttribute(3, false, "name", user.getName());
       json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
       json.endObject(2, false);
     }
     json.endCollection(1, true);

     json.beginCollection(1, true, "roles");
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

    Http.Context.current.set(ctx);
   
    if (Logger.isDebugEnabled()) Logger.debug("CheckAdminRole for resource " + Http.Context.current().request());
    if (Logger.isDebugEnabled()) Logger.debug("CheckAdminRole user: " + ctx.args.get("username"));
   
    OUser user=DbHelper.getConnection().getUser();
    Set<ORole> roles=user.getRoles();
   
    F.Promise<SimpleResult> result=null;
    if (roles.contains(RoleDao.getRole(DefaultRoles.ADMIN.toString()))){
      result = delegate.call(ctx);
    }else result=F.Promise.<SimpleResult>pure(forbidden("User " + ctx.args.get("username") + " is not an administrator"));
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

          break;
        }
      }
      ORole oldORole=RoleDao.getRole(oldRole);
      //TODO: update role
      OUser ouser=DbHelper.getConnection().getMetadata().getSecurity().getUser(username);
      ouser.getRoles().remove(oldORole);
      ouser.addRole(newORole);
      ouser.save();
      profile.save();
      profile.reload();

      return profile;
    }catch (OSerializationException e){
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

    ORole role = getUserRole(userName);
    return RoleService.roleCanByPassRestrictedAccess(role.getName());
  }

  public static ORole getUserRole(String username){
    OUser ouser = getOUserByUsername(username);
    for (ORole r: ouser.getRoles()){
      if (!r.getName().startsWith(FriendShipService.FRIEND_ROLE_NAME)) return r;
    }
    return null;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

            String appcode = (String) ctx().args.get("appcode");
            String username = (String) ctx().args.get("username");
            String password = (String) ctx().args.get("password");
            try {
                DbHelper.open(appcode, username, password);
                OUser user = DbHelper.getConnection().getUser();
                Set<ORole> roles = user.getRoles();
                if (!roles.contains(RoleDao.getRole(DefaultRoles.ADMIN.toString()))) {
                    return forbidden("Logs can only be read by administrators");
                }
            } catch (InvalidAppCodeException e) {
                return badRequest(e.getMessage());
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

    Object[] veryNewParams = ArrayUtils.addAll(newParams, params);
    return veryNewParams;
  }

    public static List<ODocument> getFollowing(String username,QueryParams criteria) throws SqlInjectionException {
        OUser me = UserService.getOUserByUsername(username);
        Set<ORole> roles = me.getRoles();
        List<String> usernames = roles.parallelStream().map(ORole::getName)
                .filter((x) -> x.startsWith(RoleDao.FRIENDS_OF_ROLE))
                .map((m) -> StringUtils.difference(RoleDao.FRIENDS_OF_ROLE, m))
                .collect(Collectors.toList());
        if (username.isEmpty()){
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

    UserDao udao= UserDao.getInstance();
    return udao.getCount(criteria);
  }

    public static boolean unfollow(String from,String to) throws UserNotFoundException,Exception{
        OUser fromUser = UserService.getOUserByUsername(from);
        if (fromUser == null){
            throw new UserNotFoundException("User "+from+" does not exists");
        }
        if (!UserService.exists(to)){
            throw new UserToFollowNotExistsException("User "+to+" does not exists");
        }
        String friendshipName = RoleDao.FRIENDS_OF_ROLE+to;
        boolean areFriends = RoleService.hasRole(fromUser.getName(),friendshipName);
        if (areFriends) {
            UserService.removeUserFromRole(fromUser.getName(),friendshipName);
            return true;
        } else {
            return false;
        }
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

        }

        if (Objects.equals(from, to)){
            throw new IllegalArgumentException("User cannot follow himself");
        }
        OUser fromUser = UserService.getOUserByUsername(from);
        if (fromUser == null) {
             throw new UserNotFoundException("User " + from + " does not exists.");
        }

        boolean exists = UserService.exists(to);
        if (!exists){
            throw new UserToFollowNotExistsException("User "+to+" does not exists.");
        }

        String friendshipRoleName = RoleDao.FRIENDS_OF_ROLE+to;
        boolean isFriend = RoleService.hasRole(from,friendshipRoleName);
        if (isFriend){
            throw new AlreadyFriendsException("User "+fromUser.getName()+ " is already a friend of "+to);
        }
        UserService.addUserToRole(fromUser.getName(),friendshipRoleName);
        ODocument toUser = UserService.getUserProfilebyUsername(to);
        return toUser;
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.security.OUser

      if (doc==null) throw new FileNotFoundException(id);
      return PermissionsHelper.revoke(doc, permission, role);
   
   
    public static ODocument grantPermissionToUser(String id, Permissions permission, String username) throws UserNotFoundException, RoleNotFoundException, FileNotFoundException, SqlInjectionException, IllegalArgumentException, InvalidModelException  {
      OUser user=UserService.getOUserByUsername(username);
      if (user==null) throw new UserNotFoundException(username);
      ODocument doc = getById(id);
      if (doc==null) throw new FileNotFoundException(id);
      return PermissionsHelper.grant(doc, permission, user);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.