Exemplo n.º 1
0
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.TokenSetUp(*privateKeyFilePath)
	loginKey := ss.GetSecureKey(*secureKeyFilePath)
	en.LoadInfo(*usersDataPath, loginKey, usersList)

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

	rootCookieStr, _ := app.GenerateToken(stc.RootUserName, am.SuperUserPermission, clientIP, signKey)
	cr.SetCookie(rootCookieStr)

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

	go runServer()
	time.Sleep(100 * time.Millisecond)
}
Exemplo n.º 2
0
func init() {
	jwtUniqId = generateJwt(jwtLen)

	usersList = en.New()

	usersList.AddGroup(stc.SuperUserGroupName)
	usersList.AddGroup(stc.AdminGroupName)
	usersList.AddGroup(stc.UsersGroupName)

	usersList.AddUserToGroup(stc.AdminGroupName, stc.SuperUserGroupName)
	usersList.AddUserToGroup(stc.UsersGroupName, stc.SuperUserGroupName)
	usersList.AddUserToGroup(stc.UsersGroupName, stc.AdminGroupName)
	usersList.AddUserToGroup(stc.SuperUserGroupName, stc.RootUserName)
}
Exemplo n.º 3
0
func init() {
	logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard)

	usersList := en.New()
	stRestful = libsecurity_restful.NewLibsecurityRestful()
	stRestful.SetData(usersList, nil, nil, nil, nil)
	stRestful.SetToFilterFlag(false)

	ServicePath = cr.ServicePathPrefix + cr.Version + AclPrefix
	resourcePath = listener + ServicePath

	go runServer()
	time.Sleep(100 * time.Millisecond)
}
Exemplo n.º 4
0
// Verify that get property from undefined user returns an error
// Verify that get property from user before setting the OTP property, returns an error
// Verify that get property from user after setting the property returns the same property as was setted to the user
// Verify that get property from user after removing the OTP property returns an error
// Verify that get property from user after readding the OTP property returns OK
// Verify that get property from user that was removed after OTP property was set, returns an error
// Verify that Add a property to user, remove the user, generate a new user with the same name and try to get the property returns an error
func testAddCheckRemoveUserProperty(t *testing.T, propertyName string, moduleData interface{}) {
	name := "name1"
	usersList := en.New()
	_, err := usersList.GetPropertyAttachedToEntity(name, propertyName)
	if err == nil {
		t.Errorf("Test fail, Recived module '%v' of undefined user '%v'", propertyName, name)
	}

	usersList.AddResource(name)
	_, err = usersList.GetPropertyAttachedToEntity(name, propertyName)
	if err == nil {
		t.Errorf("Test fail, Recived module '%v' of not registered yet module for user '%v'", propertyName, name)
	}

	usersList.AddPropertyToEntity(name, propertyName, moduleData)
	tmp, err := usersList.GetPropertyAttachedToEntity(name, propertyName)
	if err != nil {
		t.Errorf("Test fail, Error while feteching module '%v' from user '%v', error: %v", propertyName, name, err)
	}
	if moduleData != tmp {
		t.Errorf("Test fail, Added '%v' property '%v' is not equal to the fetched one '%v'", propertyName, moduleData, tmp)
	}

	usersList.RemovePropertyFromEntity(name, propertyName)
	_, err = usersList.GetPropertyAttachedToEntity(name, propertyName)
	if err == nil {
		t.Errorf("Test fail, Removed module '%v' from user '%v' was successfully fetched", propertyName, name)
	}

	usersList.AddPropertyToEntity(name, propertyName, moduleData)
	_, err = usersList.GetPropertyAttachedToEntity(name, propertyName)
	if err != nil {
		t.Errorf("Test fail, Error while feteching module '%v' from user '%v', error: %v", propertyName, name, err)
	}

	usersList.RemoveResource(name)
	_, err = usersList.GetPropertyAttachedToEntity(name, propertyName)
	if err == nil {
		t.Errorf("Test fail, Module '%v' of removed user '%v' was successfully fetched", propertyName, name)
	}
	err = usersList.AddPropertyToEntity(name, propertyName, moduleData)
	if err == nil {
		t.Errorf("Test fail, Atteched module '%v' to removed user '%v'", propertyName, name)
	}
	usersList.AddResource(name)
	_, err = usersList.GetPropertyAttachedToEntity(name, propertyName)
	if err == nil {
		t.Errorf("Test fail, Module '%v' was fetched before atttached to the user '%v'", propertyName, name)
	}
}
Exemplo n.º 5
0
func initEntityManager() *en.EntityManager {
	entityManager := en.New()
	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 init() {
	logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard)

	ServicePath = cr.ServicePathPrefix + cr.Version + SsPrefix
	resourcePath = listener + ServicePath + StoragePath
	itemPath = listener + ServicePath + StorageItemPath

	baseHeaderInfo[secretIdParam] = secretCode

	usersList := en.New()
	stRestful = libsecurity_restful.NewLibsecurityRestful()
	secureStorage, _ := ss.NewStorage([]byte(secretCode))
	stRestful.SetData(usersList, nil, nil, nil, secureStorage)
	stRestful.SetToFilterFlag(false)

	go runServer()
	time.Sleep(100 * time.Millisecond)
}
Exemplo n.º 7
0
func init() {
	logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard)

	EnServicePath = cr.ServicePathPrefix + cr.Version + UmPrefix
	enResourcePath = listener + EnServicePath
	enUserResourcePath = listener + EnServicePath + UsersPath
	UsersServicePath = EnServicePath + UsersPath
	ResourceServicePath = EnServicePath + ResourcesPath
	enPath = listener + EnServicePath

	usersList := en.New()

	stRestful = libsecurity_restful.NewLibsecurityRestful()
	stRestful.SetData(usersList, nil, nil, nil, nil)
	stRestful.SetToFilterFlag(false)

	go runServer()
	time.Sleep(100 * time.Millisecond)
}
Exemplo n.º 8
0
func init() {
	logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard)

	ServicePath = cr.ServicePathPrefix + cr.Version + OcraPrefix
	resourcePath = listener + ServicePath + usersPath

	usersList := en.New()

	stRestful = libsecurity_restful.NewLibsecurityRestful()
	stRestful.SetData(usersList, nil, nil, nil, nil)
	stRestful.SetToFilterFlag(false)

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

	go runServer()
	time.Sleep(100 * time.Millisecond)
}
Exemplo n.º 9
0
	emptyRes = "{}"

	protectedEntityManagerLen = 2 // set it if the EntityManager.protectedEntityManager is chaned
)

var (
	enResourcePath     string //     = listener + EnServicePath
	enUserResourcePath string //= listener + EnServicePath + UsersPath
	enPath             string

	usersName     = []string{userName1, userName2}
	resourcesName = []string{resourceName1, resourceName2}

	stRestful  *libsecurity_restful.LibsecurityRestful
	BasicUsers = en.New()
)

func init() {
	logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard)

	EnServicePath = cr.ServicePathPrefix + cr.Version + UmPrefix
	enResourcePath = listener + EnServicePath
	enUserResourcePath = listener + EnServicePath + UsersPath
	UsersServicePath = EnServicePath + UsersPath
	ResourceServicePath = EnServicePath + ResourcesPath
	enPath = listener + EnServicePath

	usersList := en.New()

	stRestful = libsecurity_restful.NewLibsecurityRestful()
Exemplo n.º 10
0
func init() {
	entityManager = en.New()
}
Exemplo n.º 11
0
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.TokenSetUp(privateKeyFilePath)
	loginKey = ss.GetSecureKey(secureKeyFilePath)

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

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

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

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

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

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

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

	ss := storage_restful.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)
}