// GetPropertyData : extract the property data from the relevant module
func GetPropertyData(userName string, propertyName string, usersList *en.EntityManager) (interface{}, error) {
	data, err := usersList.GetPropertyAttachedToEntity(userName, propertyName)
	if err != nil {
		return nil, err
	}
	return data, err
}
func generateAcl(el *en.EntityManager) bool {
	for n := range el.Resources {
		tmpE, _ := el.GetPropertyAttachedToEntity(n, defs.AclPropertyName)
		a, ok := tmpE.(*Acl)
		if ok == false {
			return false
		}
		for name := range el.Users {
			a.AddPermissionToEntity(el, name, en.Permission("uP"+n))
		}
	}
	return true
}
Ejemplo n.º 3
0
// GetUserPermissions : Get all the permissions of a given user to a given resource-
// return the user's list of permissions to the given resource
// The permissions may be listed as the user's permissions, permissions to groups
// in which the user is a member or permissions that are given to 'all'
func GetUserPermissions(el *en.EntityManager, userName string, resourceName string) (PermissionsMap, error) {
	lock.Lock()
	defer lock.Unlock()

	if el == nil {
		return nil, fmt.Errorf("entityManager is nil")
	}
	err := en.IsEntityNameValid(userName)
	if err != nil {
		return nil, err
	}
	err = en.IsEntityNameValid(resourceName)
	if err != nil {
		return nil, err
	}
	if el.IsEntityInList(userName) == false {
		return nil, fmt.Errorf("Entity %q is not in the entity manager", userName)
	}
	permissions := make(PermissionsMap)
	data, err := el.GetPropertyAttachedToEntity(resourceName, defs.AclPropertyName)
	if err != nil {
		return nil, fmt.Errorf("Resource '%v' does not have an ACL property", resourceName)
	}
	acl, ok := data.(*Acl)
	if ok == false {
		return nil, fmt.Errorf("Resource '%v' ACL property is in the wrong type", resourceName)
	}
	for name, p := range acl.Permissions {
		if name == userName || name == defs.AclAllEntryName || el.IsUserPartOfAGroup(name, userName) {
			for permission := range p.Permissions {
				permissions[permission] = ""
			}
		}
	}
	logger.Trace.Println("The permissions of:", userName, "are:", permissions)
	return permissions, nil
}
Ejemplo n.º 4
0
// GetWhoUseAPermission : Return all the users that have the given permission to the given resource
func GetWhoUseAPermission(el *en.EntityManager, resourceName string, permission string) PermissionSet {
	if el == nil {
		return nil
	}
	err := en.IsEntityNameValid(resourceName)
	if err != nil {
		return nil
	}
	data, err := el.GetPropertyAttachedToEntity(resourceName, defs.AclPropertyName)
	if err != nil {
		return nil
	}
	p := make(PermissionSet)

	acl, ok := data.(*Acl)
	if ok == false {
		return p
	}
	for name := range acl.Permissions {
		pVec, _ := GetUserPermissions(el, name, resourceName)
		for v := range pVec {
			if string(v) == permission {
				p[name] = ""
				break
			}
		}
	}
	for name := range p {
		groupMembers := el.GetGroupUsers(name)
		for _, name1 := range groupMembers {
			p[name1] = true
		}
	}
	logger.Trace.Println("Who uses permission:", permission, "results:", p)
	return p
}