Example #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
}
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)
	}
}
Example #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))
}
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
}
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
}
Example #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)))
	}
}
func Test_AddCheckRemoveACLUserProperty(t *testing.T) {
	moduleData := acl.NewACL()

	testAddCheckRemoveUserProperty(t, stc.AclPropertyName, moduleData)
}