Examples of PermissionBean


Examples of org.wso2.carbon.registry.resource.beans.PermissionBean

    public static PermissionBean getPermissions(UserRegistry userRegistry, String path) throws Exception {

        ResourcePath resourcePath = new ResourcePath(path);
        String userName = userRegistry.getUserName();
        PermissionBean permissionsBean = new PermissionBean();
        permissionsBean.setPathWithVersion(resourcePath.getPathWithVersion());
        permissionsBean.setVersionView(!resourcePath.isCurrentVersion());

        UserRealm userRealm = userRegistry.getUserRealm();

        String[] userNames = userRealm.getUserStoreManager().listUsers("*", 100);

        // remove the admin and system
        ArrayList<String> filteredUserNames = new ArrayList<String>();

        RealmConfiguration realmConfig = userRealm.getRealmConfiguration();
        String systemUserName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
        String adminUserName = realmConfig.getAdminUserName();
        for (String userN: userNames) {
            if (userN.equals(adminUserName) ||
                    userN.equals(systemUserName)) {
                continue;
            }
            filteredUserNames.add(userN);
        }

        userNames = filteredUserNames.toArray(new String[filteredUserNames.size()]);

        permissionsBean.setUserNames(userNames);

        String[] roleNames = userRealm.getUserStoreManager().getRoleNames();
        // remove the admin role
        ArrayList<String> filteredRoleNames = new ArrayList<String>();

        String adminRoleName = realmConfig.getAdminRoleName();
        for (String roleN: roleNames) {
            if (roleN.equals(adminRoleName)) {
                continue;
            }
            filteredRoleNames.add(roleN);
        }

        roleNames = filteredRoleNames.toArray(new String[filteredRoleNames.size()]);
        permissionsBean.setRoleNames(roleNames);

        String authorizationPath = path;
        if (path.indexOf("?") > 0) {
            authorizationPath = path.split("\\?")[0];
        } else if (path.indexOf(RegistryConstants.URL_SEPARATOR) > 0) {
            authorizationPath = path.split("\\;")[0];
        }

        if (UserUtil.isPutAllowed(userName, authorizationPath, userRegistry)) {
            permissionsBean.setPutAllowed(true);
        } else {
            permissionsBean.setPutAllowed(false);
        }

        if (UserUtil.isDeleteAllowed(userName, authorizationPath, userRegistry)) {
            permissionsBean.setDeleteAllowed(true);
        } else {
            permissionsBean.setDeleteAllowed(false);
        }

        if (UserUtil.isAuthorizeAllowed(userName, authorizationPath, userRegistry)) {
            permissionsBean.setAuthorizeAllowed(true);
        } else {
            permissionsBean.setAuthorizeAllowed(false);
        }

        permissionsBean.setUserPermissions(getUserPermissions(userRealm, path));
        permissionsBean.setRolePermissions(getRolePermissions(userRealm, path));

        return permissionsBean;
    }
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.