/* Copyright 2012-2013 Claudio Tesoriero - c.tesoriero-at-baasbox.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package com.baasbox.enumerations; import java.util.ArrayList; import com.baasbox.dao.RoleDao; import com.orientechnologies.orient.core.metadata.security.ORole; public enum DefaultRoles { ADMIN ("administrator","admin","Administrative role, users belonging to this role are Gods",true,false) , ANONYMOUS_USER ("anonymous" ,"writer","Role used internally to access to the internal db with low privileges",false,false), REGISTERED_USER ("registered","anonymous","Default role for new registered users",true,false) , BACKOFFICE_USER ("backoffice","writer","Preconfigured role to give users belonging to it the grants to access the contents generated by the registered users",true,false), /*Internal pre-configured OrientDB roles, other ones inherit from them */ BASE_READER ("reader",null,"Internal low-privileges role, used basically to inherited privileges for other custom roles",false,true), BASE_WRITER ("writer",null,"Internal medium-privileges role, used basically to inherited privileges for other custom roles",false,true), BASE_ADMIN ("admin" ,null,"Internal high-privileges role, used basically to inherited privileges for other custom adminstrative roles",false,true); private String role; private String description; private boolean assignable; private boolean orientRole; private String inheritsFrom; private ORole orole; private DefaultRoles(String role,String inheritsFrom,String descrition,boolean assignable,boolean isOrientRole){ this.role=role; this.description=descrition; this.assignable=assignable; this.orientRole=isOrientRole; this.inheritsFrom=inheritsFrom; } public String toString(){ return role; } public boolean isAssignable(){ return assignable; } public boolean isOrientRole(){ return orientRole; } public String getInheritsFrom(){ return inheritsFrom; } public String getDescription(){ return description; } public ORole getORole(){ if (orole==null) orole=RoleDao.getRole(role); return orole; } public static ORole[] getORoles(){ ArrayList<ORole> oroles=new ArrayList<ORole>(); for (DefaultRoles r : DefaultRoles.values()){ oroles.add(r.getORole()); } return (ORole[]) oroles.toArray(new ORole[DefaultRoles.values().length]); } }