Exemplo n.º 1
0
func (a *aclRestful) addAclToResource(request *restful.Request, response *restful.Response, name string) error {
	a1 := acl.NewACL()
	err := a.st.UsersList.AddPropertyToEntity(name, stc.AclPropertyName, a1)
	if err != nil {
		a.setError(response, http.StatusNotFound, err)
		return err
	}
	return nil
}
Exemplo n.º 2
0
func initState() {
	a := acl.NewACL()
	for _, name := range resourcesName {
		stRestful.UsersList.AddResource(name)
		stRestful.UsersList.AddPropertyToEntity(name, stc.AclPropertyName, a)
	}
	for _, name := range usersName {
		stRestful.UsersList.AddUser(name)
	}
}
Exemplo n.º 3
0
func (a *aclRestful) restAddAclToResource(request *restful.Request, response *restful.Response) {
	var a1 *acl.Acl
	resourceName := request.PathParameter(resourceNameParam)

	err := request.ReadEntity(&a1)
	if err != nil {
		a1 = acl.NewACL()
	}
	if a.addAclToResource(request, response, resourceName, a1) == false {
		return
	}
	response.WriteHeader(http.StatusCreated)
	response.WriteEntity(a.getUrlPath(request, resourceToken, resourceName))
}
Exemplo n.º 4
0
func initEntityManager() *en.EntityManager {
	entityManager := en.NewEntityManager()
	for _, name := range usersName {
		entityManager.AddUser(name)
	}
	entityManager.AddGroup(groupName)
	for _, name := range groupUsersName {
		entityManager.AddUser(name)
		entityManager.AddUserToGroup(groupName, name)
	}
	entityManager.AddResource(resourceName)
	a := acl.NewACL()
	entityManager.AddPropertyToEntity(resourceName, stc.AclPropertyName, a)
	return entityManager
}
Exemplo n.º 5
0
func generateAcl() (string, *acl.Acl, error) {
	stRestful.UsersList.AddResource(resourceName1)
	stRestful.UsersList.AddGroup(groupName)
	for _, name := range usersName {
		stRestful.UsersList.AddUser(name)
		stRestful.UsersList.AddUserToGroup(groupName, name)
	}
	aclData := acl.NewACL()
	for _, name := range usersName {
		for _, p := range usersPermissions {
			aclData.AddPermissionToResource(stRestful.UsersList, name, acl.Permission(p))
		}
	}
	aclData.AddPermissionToResource(stRestful.UsersList, stc.AclAllEntryName, perAll)
	stRestful.UsersList.AddPropertyToEntity(resourceName1, stc.AclPropertyName, aclData)
	data, _ := json.Marshal(aclData)
	return string(data), aclData, nil
}
Exemplo n.º 6
0
func (a aclRestful) restSetPermission(request *restful.Request, response *restful.Response) {
	a1, aclInfo, err := a.getResourceAclData(request, response)
	if err != nil {
		a.setError(response, http.StatusNotFound, err)
		return
	}
	if a1 == nil {
		eAcl := acl.NewACL()
		a.addAclToResource(request, response, aclInfo.ResourceName, eAcl)
		a1, aclInfo, err = a.getResourceAclData(request, response)
		if err != nil {
			a.setError(response, http.StatusInternalServerError, err)
			return
		}
	}
	err = a1.AddPermissionToResource(a.st.UsersList, aclInfo.UserName, acl.Permission(aclInfo.Permission))
	if err != nil {
		a.setError(response, http.StatusNotFound, err)
	} else {
		response.WriteHeader(http.StatusCreated)
		response.WriteEntity(a.getUrlPath(request, entityToken, fmt.Sprintf("%v/%v/%v/%v/%v", aclInfo.UserName, resourceToken, aclInfo.ResourceName, permissionsToken, aclInfo.Permission)))
	}
}
Exemplo n.º 7
0
func Test_AddCheckRemoveACLUserProperty(t *testing.T) {
	moduleData := acl.NewACL()

	testAddCheckRemoveUserProperty(t, stc.AclPropertyName, moduleData)
}