All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bagri.server.hazelcast.management.RoleManager Maven / Gradle / Ivy

The newest version!
package com.bagri.server.hazelcast.management;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.management.openmbean.CompositeData;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;

import com.bagri.core.system.Permission;
import com.bagri.core.system.Role;
import com.bagri.support.util.JMXUtils;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;

@ManagedResource(description="Role Manager MBean")
public class RoleManager extends PermissionAwareManager {

	public RoleManager() {
		super();
	}

	public RoleManager(HazelcastInstance hzInstance, String roleName) {
		super(hzInstance, roleName);
	}

	@Override
	protected String getEntityType() {
		return "Role";
	}

	@ManagedAttribute(description="Returns Role name")
	public String getName() {
		return entityName;
	}
	
	@ManagedAttribute(description="Returns Role version")
	public int getVersion() {
		return super.getVersion();
	}

	@ManagedAttribute(description="Returns effective Role permissions, recursivelly")
	public CompositeData getRecursivePermissions() {
		Map xPerms = new HashMap();
		getRecursivePermissions(xPerms, entityName);
		Map pMap = new HashMap(xPerms.size());
		for (Map.Entry e: xPerms.entrySet()) {
			pMap.put(e.getKey(), e.getValue().getPermissionsAsString());
		}
		return JMXUtils.mapToComposite(entityName, "permissions", pMap);
	}
	
	@ManagedAttribute(description="Returns all Roles assigned to this one, recursivelly")
	public String[] getRecursiveRoles() {
		Set xRoles = new HashSet();
		getRecursiveRoles(xRoles, entityName);
		xRoles.remove(entityName);
		return xRoles.toArray(new String[xRoles.size()]);
	}

	@Override
	protected IMap getRoleCache() {
		return entityCache;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy