Esempio n. 1
0
func main() {
	adpt, err := mongo.InitWithDBName("localhost","acl","acl1")
	adpt.Clear()
	//defer adpt.Clear()
	adpt2, err := json.InitWithFileName("/tmp/v2")
	//adpt2.Clear()
	if err != nil {
		println(err.Error())
		return
	}
	acl := NewACL()
	if err := acl.Append("TIMERANGE", 0, "connect","host1",true, "20150307000000-20150308000000", false); err != nil {
		println(err.Error())
	}
	acl.Append("TIMERANGE", 0, "connect","host1",true, "20150308000000-20150309000000", false)
	acl.Append("TIMERANGE", 0, "connect","host1",false, "00000308000000-20150309000000", false)
	acl.SaveTo(adpt)
	acl2 := NewACL()
	acl2.LoadFrom(adpt)
	if err := acl2.SaveTo(adpt2); err != nil {
		println(err.Error())
	}
	println(acl.Decide(0, "connect","host1",time.Now())==UNDETERMINED)
	println(acl2.Decide(0, "connect","host1",time.Now())==UNDETERMINED)
}
Esempio n. 2
0
func main() {
	adpt, _ := json.InitWithFileName("/tmp/1.json")
	adpt2, _ := json.InitWithFileName("/tmp/2.json")
	acl := NewACL()
	acl.Append("BASE", 0, "read", "book", true, "", false)
	acl.Append("BASE", 0, "write", "book", true, "", false)
	if err := acl.SaveTo(adpt); err != nil {
		println(err.Error())
		return
	}
	acl2 := NewACL()
	acl2.LoadFrom(adpt)
	acl2.SaveTo(adpt2)
	println(acl.Decide(0, "read", "book", "") == PERMIT)
	println(acl2.Decide(0, "read", "book", ""))
}