Package com.orientechnologies.orient.core.metadata.security

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


  }//update indices
 
  private void recreateDefaultRoles(){
    Logger.info("Ricreating default roles");
    Logger.info("reader");
    ORole anonymRole = RoleDao.getRole("anonymoususer");
    ORole reader = RoleDao.createRole(DefaultRoles.BASE_READER.toString(), anonymRole.getMode(),anonymRole.getRules());
   
    reader.getDocument().field(RoleService.FIELD_INTERNAL,true);
    reader.getDocument().field(RoleService.FIELD_MODIFIABLE,false);
    reader.getDocument().field(RoleService.FIELD_DESCRIPTION,DefaultRoles.BASE_READER.getDescription())
    reader.getDocument().field(RoleService.FIELD_ASSIGNABLE,DefaultRoles.BASE_READER.isAssignable());
    reader.save();
   
    Logger.info("writer");;
    ORole regRole = RoleDao.getRole("registereduser");
    ORole writer = RoleDao.createRole(DefaultRoles.BASE_WRITER.toString(), regRole.getMode(),regRole.getRules());
    writer.getDocument().field(RoleService.FIELD_INTERNAL,true);
    writer.getDocument().field(RoleService.FIELD_MODIFIABLE,false);
    writer.getDocument().field(RoleService.FIELD_DESCRIPTION,DefaultRoles.BASE_WRITER.getDescription())
    writer.getDocument().field(RoleService.FIELD_ASSIGNABLE,DefaultRoles.BASE_WRITER.isAssignable());
    writer.save();
  }
View Full Code Here


    OrientGraph db = DbHelper.getOrientGraphConnection();
    if (existsUserName(username)) throw new UserAlreadyExistsException("User " + username + " already exists");
    OUser user=null;
    if (role==null) user=db.getRawGraph().getMetadata().getSecurity().createUser(username,password,new String[]{DefaultRoles.REGISTERED_USER.toString()});
    else {
      ORole orole = RoleDao.getRole(role);
      if (orole==null) throw new InvalidParameterException("Role " + role + " does not exists");
      user=db.getRawGraph().getMetadata().getSecurity().createUser(username,password,new String[]{role});
    }
   
    ODocument doc = new ODocument(this.MODEL_NAME);
View Full Code Here

  }
 
  private void updateOldRoles(){
    Logger.info("Updating old roles");
    Logger.info("anonymoususer");
    ORole anonymRole = RoleDao.getRole("anonymoususer");
    anonymRole.getDocument().field(RoleService.FIELD_INTERNAL,true);
    anonymRole.getDocument().field(RoleService.FIELD_MODIFIABLE,false);
    anonymRole.getDocument().field(RoleService.FIELD_DESCRIPTION,DefaultRoles.ANONYMOUS_USER.getDescription())
    anonymRole.getDocument().field(RoleService.FIELD_ASSIGNABLE,DefaultRoles.ANONYMOUS_USER.isAssignable());
    anonymRole.getDocument().field(RoleDao.FIELD_INHERITED,RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.getInheritsFrom()).getDocument().getRecord());
    anonymRole.getDocument().field("name",DefaultRoles.ANONYMOUS_USER.toString());
    anonymRole.save();
    anonymRole=null;
   
    Logger.info("registered");
    ORole regRole = RoleDao.getRole("registereduser");
    regRole.getDocument().field(RoleService.FIELD_INTERNAL,true);
    regRole.getDocument().field(RoleService.FIELD_MODIFIABLE,false);
    regRole.getDocument().field(RoleService.FIELD_DESCRIPTION,DefaultRoles.REGISTERED_USER.getDescription())
    regRole.getDocument().field(RoleService.FIELD_ASSIGNABLE,DefaultRoles.REGISTERED_USER.isAssignable());
    regRole.getDocument().field(RoleDao.FIELD_INHERITED,RoleDao.getRole(DefaultRoles.REGISTERED_USER.getInheritsFrom()).getDocument().getRecord());
    regRole.getDocument().field("name",DefaultRoles.REGISTERED_USER.toString());
    regRole.save();
    regRole=null;
   
    Logger.info("backofficeuser");
    ORole backRole = RoleDao.getRole("backofficeuser");
    backRole.getDocument().field(RoleService.FIELD_INTERNAL,true);
    backRole.getDocument().field(RoleService.FIELD_MODIFIABLE,false);
    backRole.getDocument().field(RoleService.FIELD_DESCRIPTION,DefaultRoles.BACKOFFICE_USER.getDescription())
    backRole.getDocument().field(RoleService.FIELD_ASSIGNABLE,DefaultRoles.BACKOFFICE_USER.isAssignable());
    backRole.getDocument().field(RoleDao.FIELD_INHERITED,RoleDao.getRole(DefaultRoles.BACKOFFICE_USER.getInheritsFrom()).getDocument().getRecord());
    backRole.addRule(ODatabaseSecurityResources.BYPASS_RESTRICTED, ORole.PERMISSION_ALL);
    backRole.getDocument().field("name",DefaultRoles.BACKOFFICE_USER.toString());
    backRole.save();
    backRole=null;
   
    Logger.info("administrator");
    //retrieves the "old" admin role
    ORole oldAdminRole = RoleDao.getRole("admin");
    //duplicates it
    ORole adminRole = RoleDao.createRole(DefaultRoles.BASE_ADMIN+"_".toString(), oldAdminRole.getMode(),oldAdminRole.getRules());

   
    //now the old one must become the new one
    oldAdminRole.getDocument().field(RoleService.FIELD_INTERNAL,true);
    oldAdminRole.getDocument().field(RoleService.FIELD_MODIFIABLE,false);
    oldAdminRole.getDocument().field(RoleService.FIELD_DESCRIPTION,DefaultRoles.ADMIN.getDescription())
    oldAdminRole.getDocument().field(RoleService.FIELD_ASSIGNABLE,DefaultRoles.ADMIN.isAssignable());
    oldAdminRole.addRule(ODatabaseSecurityResources.BYPASS_RESTRICTED, ORole.PERMISSION_ALL);
    oldAdminRole.getDocument().field("name",DefaultRoles.ADMIN.toString()+"1");

    //the new one must become the old one
    adminRole.getDocument().field(RoleService.FIELD_INTERNAL,true);
    adminRole.getDocument().field(RoleService.FIELD_MODIFIABLE,false);
    adminRole.getDocument().field(RoleService.FIELD_DESCRIPTION,DefaultRoles.BASE_ADMIN.getDescription())
    adminRole.getDocument().field(RoleService.FIELD_ASSIGNABLE,DefaultRoles.BASE_ADMIN.isAssignable());
    adminRole.getDocument().field(RoleDao.FIELD_INHERITED,(ORecord)null);
    oldAdminRole.addRule(ODatabaseSecurityResources.BYPASS_RESTRICTED, ORole.PERMISSION_ALL);
    adminRole.getDocument().field("name",DefaultRoles.BASE_ADMIN.toString());

    oldAdminRole.save();
    adminRole.save();
    oldAdminRole.getDocument().field(RoleDao.FIELD_INHERITED,adminRole.getDocument().getRecord());
    oldAdminRole.getDocument().field("name",DefaultRoles.ADMIN.toString());
    oldAdminRole.save();
   
    //update the "friend_of" roles
   
View Full Code Here

            return db.getMetadata().getSecurity().getRole(name);
        }

    public static ORole createRole(String name,String inheritedRoleName){
      ODatabaseRecordTx db = DbHelper.getConnection();
      ORole inheritedRole = db.getMetadata().getSecurity().getRole(inheritedRoleName);
      final ORole role =  db.getMetadata().getSecurity().createRole(name,inheritedRole.getMode());
      role.getDocument().field(FIELD_INHERITED,inheritedRole.getDocument().getRecord());
      role.save();
          return role;
    }
View Full Code Here

          return role;
    }
   
    public static ORole createRole(String name,ORole.ALLOW_MODES mode,Map rules){
      ODatabaseRecordTx db = DbHelper.getConnection();
      final ORole role =  db.getMetadata().getSecurity().createRole(name,mode);
      role.getDocument().field("rules",rules);
      role.save();
          return role;
    }
View Full Code Here

    public static boolean exists(String roleName) {
      return (DbHelper.getConnection().getMetadata().getSecurity().getRole(roleName)!=null);
    }

    public static void delete(String name) {
      ORole role = getRole(name);
      role.getDocument().delete();
     
    }
View Full Code Here

      RoleNotFoundException e = new RoleNotFoundException(inheritedRole + " role does not exist!");
      e.setInehrited(true);
      throw e;
    }
    if (RoleDao.exists(name)) throw new RoleAlreadyExistsException(name + " role already exists!");
    ORole newRole = RoleDao.createRole(name, inheritedRole);
    newRole.getDocument().field(FIELD_INTERNAL,false);
    newRole.getDocument().field(FIELD_MODIFIABLE,true);
    newRole.getDocument().field(FIELD_DESCRIPTION,description);
    newRole.getDocument().field(FIELD_ASSIGNABLE,true);
    newRole.save();
  }
View Full Code Here

    newRole.save();
  }
 
  public static void createInternalRoles(){
    for (DefaultRoles r : DefaultRoles.values()){
      ORole newRole;
      if (Logger.isDebugEnabled()) Logger.debug("creating " + r.toString() + "...");
      if (!r.isOrientRole()){ //creates the new baasbox role
        newRole = RoleDao.createRole(r.toString(), r.getInheritsFrom());
      }else//retrieve the existing OrientDB role
        newRole=r.getORole();
        newRole.reload();
      }
      newRole.getDocument().field(FIELD_INTERNAL,true);
      newRole.getDocument().field(FIELD_MODIFIABLE,false);
      newRole.getDocument().field(FIELD_DESCRIPTION,r.getDescription())
      newRole.getDocument().field(FIELD_ASSIGNABLE,r.isAssignable());
      if (r==DefaultRoles.BACKOFFICE_USER) newRole.addRule(ODatabaseSecurityResources.BYPASS_RESTRICTED, ORole.PERMISSION_ALL);
      if (r==DefaultRoles.ADMIN) newRole.addRule(ODatabaseSecurityResources.BYPASS_RESTRICTED, ORole.PERMISSION_ALL);
      newRole.save();
    }

  }
View Full Code Here

   */
  public static void editRole(String name, String inheritedRole,
      String description, String newName) throws RoleNotFoundException, RoleNotModifiableException {

    if (!RoleDao.exists(name)) throw new RoleNotFoundException(name + " role does not exist!");
    ORole role = RoleDao.getRole(name);
    ODocument roleDoc=role.getDocument();
    if (roleDoc.field(FIELD_MODIFIABLE)==Boolean.FALSE) throw new RoleNotModifiableException(name + " role is not modifiable");
    if (!StringUtils.isEmpty(inheritedRole)) {
      if (!RoleDao.exists(inheritedRole)) {
        RoleNotFoundException e = new RoleNotFoundException(inheritedRole + " role does not exist!");
        e.setInehrited(true);
        throw e;
      }
      ORole roleIn=RoleDao.getRole(inheritedRole);
      roleDoc.field(RoleDao.FIELD_INHERITED,roleIn.getDocument().getRecord());
    }
   
    if (!StringUtils.isEmpty(newName)) roleDoc.field("name",newName);
    if (description!=null) roleDoc.field(FIELD_DESCRIPTION,description);
    roleDoc.save();
View Full Code Here

    roleDoc.save();
  }

  public static void delete(String name) throws RoleNotFoundException, RoleNotModifiableException {
    if (!RoleDao.exists(name)) throw new RoleNotFoundException(name + " role does not exist!");
    ORole role = RoleDao.getRole(name);
    if (role.getDocument().field(FIELD_INTERNAL)==Boolean.TRUE) throw new RoleNotModifiableException("Role " + name + " cannot be deleted. It is declared like 'internal'");
    //retrieve the users belonging to that role
    UserService.moveUsersToRole(name,DefaultRoles.REGISTERED_USER.toString());
    //delete the role
    RoleDao.delete(name);
  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.metadata.security.ORole

Copyright © 2018 www.massapicom. 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.