Search in sources :

Example 1 with IntObjectHashMap

use of com.generallycloud.baseio.collection.IntObjectHashMap in project baseio by generallycloud.

the class RoleManager method initialize.

@Override
public void initialize(ApplicationContext context, Configuration config) throws Exception {
    ApplicationConfigurationLoader acLoader = context.getAcLoader();
    PermissionConfiguration permissionConfiguration = acLoader.loadPermissionConfiguration(getClass().getClassLoader());
    List<Configuration> permissionConfigurations = permissionConfiguration.getPermissions();
    List<Configuration> roleConfigurations = permissionConfiguration.getRoles();
    if (permissionConfigurations == null || permissionConfigurations.size() == 0 || roleConfigurations == null || roleConfigurations.size() == 0) {
        throw new Error("没有加载到角色配置");
    }
    IntObjectHashMap<Permission> permissions = new IntObjectHashMap<>();
    for (Configuration c : permissionConfigurations) {
        Permission p = new Permission();
        p.setDescription(c.getParameter("description"));
        p.setFrequency(c.getIntegerParameter("frequency"));
        p.setPermissionAPI(c.getParameter("permissionAPI"));
        p.setPermissionId(c.getIntegerParameter("permissionId"));
        permissions.put(p.getPermissionId(), p);
    }
    IntObjectHashMap<Role> roles = new IntObjectHashMap<>();
    List<Role> roleList = new ArrayList<>();
    for (Configuration c : roleConfigurations) {
        Role r = new Role();
        r.setDescription(c.getParameter("description"));
        r.setRoleId(c.getIntegerParameter("roleId"));
        r.setRoleName(c.getParameter("roleName"));
        JSONArray array = c.getJSONArray("children");
        if (array != null && !array.isEmpty()) {
            List<Integer> _children = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                _children.add(array.getInteger(i));
            }
            r.setChildren(_children);
        }
        array = c.getJSONArray("permissions");
        if (array != null && !array.isEmpty()) {
            List<Integer> _permissions = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                _permissions.add(array.getInteger(i));
            }
            r.setPermissions(_permissions);
        }
        roles.put(r.getRoleId(), r);
        roleList.add(r);
    }
    reflectPermission(roleList, roles, permissions);
}
Also used : PermissionConfiguration(com.generallycloud.baseio.container.configuration.PermissionConfiguration) Configuration(com.generallycloud.baseio.container.configuration.Configuration) IntObjectHashMap(com.generallycloud.baseio.collection.IntObjectHashMap) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) PermissionConfiguration(com.generallycloud.baseio.container.configuration.PermissionConfiguration) ApplicationConfigurationLoader(com.generallycloud.baseio.container.configuration.ApplicationConfigurationLoader)

Aggregations

JSONArray (com.alibaba.fastjson.JSONArray)1 IntObjectHashMap (com.generallycloud.baseio.collection.IntObjectHashMap)1 ApplicationConfigurationLoader (com.generallycloud.baseio.container.configuration.ApplicationConfigurationLoader)1 Configuration (com.generallycloud.baseio.container.configuration.Configuration)1 PermissionConfiguration (com.generallycloud.baseio.container.configuration.PermissionConfiguration)1 ArrayList (java.util.ArrayList)1