func init() {
	logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard)
	privateKeyFilePath := flag.String("rsa-private", "./dist/key.private", "RSA private key file path")
	secureKeyFilePath := flag.String("secure-key", "./dist/secureKey", "password to encrypt the secure storage")
	usersDataPath := flag.String("data-file", "./dist/data.txt", "Login information file")
	flag.Parse()

	servicePath = cr.ServicePathPrefix + cr.Version + amPrefix
	resourcePath = listener + servicePath + usersPath

	usersList := en.New()
	signKey, verifyKey := app.SetupAToken(*privateKeyFilePath)
	loginKey := ss.GetSecureKey(*secureKeyFilePath)
	en.LoadInfo(*usersDataPath, loginKey, usersList)

	stRestful = libsecurityRestful.NewLibsecurityRestful()
	stRestful.SetData(usersList, loginKey, verifyKey, signKey, nil)

	rootCookieStr, _ := app.GenerateToken(defs.RootUserName, am.SuperUserPermission, false, clientIP, signKey)
	cr.TestSetCookie(rootCookieStr)

	for _, name := range usersName {
		stRestful.UsersList.AddUser(name)
	}

	go runServer()
	time.Sleep(100 * time.Millisecond)
}
func (l LibsecurityRestful) restLoadData(request *restful.Request, response *restful.Response) {
	// old use var fileData cr.StringMessage
	var fileData cr.SecureFile

	err := request.ReadEntity(&fileData)
	if err != nil {
		l.setError(response, http.StatusNotFound, err)
		return
	}
	err = en.LoadInfo(fileData.FilePath, []byte(fileData.Secret), l.UsersList)
	if err != nil {
		l.setError(response, http.StatusInternalServerError, err)
		return
	}
	response.WriteHeaderAndEntity(http.StatusCreated, fileData.FilePath)
}
func Test_StoreLoad(t *testing.T) {
	filePath := "./try.txt"
	secret := []byte("ABCDEFGH12345678")

	el := en.New()
	for i := 0; i < 3; i++ {
		el.AddUser(fmt.Sprintf("User %d", i+1))
		resourceName := fmt.Sprintf("Disk %d", i+1)
		el.AddResource(resourceName)
		a := NewACL()
		el.AddPropertyToEntity(resourceName, defs.AclPropertyName, a)
	}

	if generateAcl(el) == false {
		t.Error("Test fail, can't generate ACL")
		t.FailNow()
	}
	el.StoreInfo(filePath, secret, false)
	entityManager1 := en.New()
	err := en.LoadInfo(filePath, secret, entityManager1)
	if err != nil {
		fmt.Println(err)
	}

	as := defs.Serializers[defs.AclPropertyName]
	for n := range el.Resources {
		tmpE, _ := el.GetPropertyAttachedToEntity(n, defs.AclPropertyName)
		a := tmpE.(*Acl)
		tmpE1, _ := entityManager1.GetPropertyAttachedToEntity(n, defs.AclPropertyName)
		a1 := tmpE1.(*Acl)
		if a.IsEqual(*a1) == false || as.IsEqualProperties(a, a1) == false {
			t.Errorf("Test fail, Stored ACL property != loaded one")
			fmt.Println("The stored ACL for resource:", n, a)
			fmt.Println("The loaded ACL for resource:", n, a1)
		}
		eq := reflect.DeepEqual(a.GetAllPermissions(), a1.GetAllPermissions())
		logger.Trace.Println("Data:", as.PrintProperties(a))
		if eq == false {
			t.Errorf("Test fail, Stored ACL permissions %v != loaded one %v", a.GetAllPermissions(), a1.GetAllPermissions())
		}
	}
}
func registerComponents(configFile string, secureKeyFilePath string, privateKeyFilePath string, usersDataPath string) {
	conf, err := readConfigFile(configFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Fatal error while reading configuration file '%v', error: %v\n", configFile, err)
		os.Exit(1)
	}
	wsContainer := restful.NewContainer()
	usersList := en.New()

	//	amUsers := am.NewAmUsersList()
	signKey, verifyKey = app.SetupAToken(privateKeyFilePath)
	loginKey = ss.GetSecureKey(secureKeyFilePath)

	st := libsecurityRestful.NewLibsecurityRestful()
	st.SetData(usersList, loginKey, verifyKey, signKey, nil)

	l := accountsRestful.NewAmRestful()
	l.SetData(st)
	if conf[amToken] == fullToken {
		l.RegisterFull(wsContainer)
	} else { // login is mandatory
		l.RegisterBasic(wsContainer)
	}

	um := enRestful.NewEnRestful()
	um.SetData(st)
	if conf[umToken] != noneToken {
		um.RegisterBasic(wsContainer)
	}

	a := aclRestful.NewAclRestful()
	a.SetData(st)
	if conf[aclToken] == basicToken || conf[appAclToken] == basicToken {
		a.RegisterBasic(wsContainer)
	}

	p := otpRestful.NewOtpRestful()
	p.SetData(st)
	if conf[otpToken] == basicToken {
		p.RegisterBasic(wsContainer)
	}

	o := ocraRestful.NewOcraRestful()
	o.SetData(st)
	if conf[ocraToken] == basicToken {
		o.RegisterBasic(wsContainer)
	}

	pwd := passwordRestful.NewPwdRestful()
	pwd.SetData(st)
	if conf[passwordToken] == basicToken {
		pwd.RegisterBasic(wsContainer)
	}

	ss := storageRestful.NewSsRestful()
	ss.SetData(st)
	if conf[secureStorageToken] == basicToken {
		ss.RegisterBasic(wsContainer)
	}

	st.RegisterBasic(wsContainer)

	err = en.LoadInfo(usersDataPath, loginKey, usersList)
	if err != nil {
		fmt.Println("Load info error:", err)
	}
	runRestAPI(wsContainer)
}