Пример #1
0
func (ah *CbAuthHandler) GetSaslCredentials() (string, string, error) {
	u, p, err := cbauth.GetMemcachedServiceAuth(ah.Hostport)
	if err != nil {
		return "", "", err
	}
	return u, p, nil
}
Пример #2
0
func (ah *CbAuthHandler) AuthenticateMemcachedConn(host string, conn *memcached.Client) error {
	u, p, err := cbauth.GetMemcachedServiceAuth(host)
	if err != nil {
		panic(err)
	}
	_, err = conn.Auth(u, p)
	_, err = conn.SelectBucket(ah.Bucket)
	return err
}
Пример #3
0
func GetNewConnection(kvAddr string) (*mcc.Client, error) {
	c, err := mcc.Connect("tcp", kvAddr)
	if err != nil {
		return nil, fmt.Errorf("audit: Error in connection to"+
			" memcached %v", err)
	}
	u, p, err := cbauth.GetMemcachedServiceAuth(kvAddr)
	if err != nil {
		return nil, fmt.Errorf("audit: Error in getting auth for"+
			" memcached %v", err)
	}
	_, err = c.Auth(u, p)
	if err != nil {
		return nil, fmt.Errorf("audit: Error in auth %v", err)
	}
	return c, nil
}
Пример #4
0
func main() {

	flag.Parse()
	/*
	   NOTE. This example requires the following environment variables to be set.

	   CBAUTH_REVRPC_URL

	   e.g

	   CBAUTH_REVRPC_URL="http://*****:*****@127.0.0.1:9000/_cbauth"

	*/

	url, err := url.Parse(*serverURL)
	if err != nil {
		log.Printf("Failed to parse url %v", err)
		return
	}

	hostPort := url.Host

	user, bucket_password, err := cbauth.GetHTTPServiceAuth(hostPort)
	if err != nil {
		log.Printf("Failed %v", err)
		return
	}

	log.Printf(" HTTP Servce username %s password %s", user, bucket_password)

	client, err := couchbase.ConnectWithAuthCreds(*serverURL, user, bucket_password)
	if err != nil {
		log.Printf("Connect failed %v", err)
		return
	}

	cbpool, err := client.GetPool("default")
	if err != nil {
		log.Printf("Failed to connect to default pool %v", err)
		return
	}

	mUser, mPassword, err := cbauth.GetMemcachedServiceAuth(hostPort)
	if err != nil {
		log.Printf(" failed %v", err)
		return
	}

	var cbbucket *couchbase.Bucket
	cbbucket, err = cbpool.GetBucketWithAuth(*bucketName, mUser, mPassword)

	if err != nil {
		log.Printf("Failed to connect to bucket %v", err)
		return
	}

	log.Printf(" Bucket name %s Bucket %v", *bucketName, cbbucket)

	err = cbbucket.Set("k1", 5, "value")
	if err != nil {
		log.Printf("set failed error %v", err)
		return
	}

	if *authUser != "" {
		creds, err := cbauth.Auth(*authUser, *authPswd)
		if err != nil {
			log.Printf(" failed %v", err)
			return
		}

		permission := fmt.Sprintf("cluster.bucket[%s].data!read", *bucketName)
		canAccess, err := creds.IsAllowed(permission)
		if err != nil {
			log.Printf(" error %v checking permission %v", err, permission)
		} else {
			log.Printf(" result of checking permission %v : %v", permission, canAccess)
		}
	}

}
Пример #5
0
func main() {

	flag.Parse()
	/*
	   NOTE. This example requires the following environment variables to be set.

	   NS_SERVER_CBAUTH_URL
	   NS_SERVER_CBAUTH_USER
	   NS_SERVER_CBAUTH_PWD

	   e.g

	   NS_SERVER_CBAUTH_URL="http://localhost:9000/_cbauth"
	   NS_SERVER_CBAUTH_USER="******"
	   NS_SERVER_CBAUTH_PWD="asdasd"

	*/

	url, err := url.Parse(*serverURL)
	if err != nil {
		log.Printf("Failed to parse url %v", err)
		return
	}

	hostPort := url.Host

	user, bucket_password, err := cbauth.GetHTTPServiceAuth(hostPort)
	if err != nil {
		log.Printf("Failed %v", err)
		return
	}

	log.Printf(" HTTP Servce username %s password %s", user, bucket_password)

	client, err := couchbase.ConnectWithAuthCreds(*serverURL, user, bucket_password)
	if err != nil {
		log.Printf("Connect failed %v", err)
		return
	}

	cbpool, err := client.GetPool("default")
	if err != nil {
		log.Printf("Failed to connect to default pool %v", err)
		return
	}

	mUser, mPassword, err := cbauth.GetMemcachedServiceAuth(hostPort)
	if err != nil {
		log.Printf(" failed %v", err)
		return
	}

	var cbbucket *couchbase.Bucket
	cbbucket, err = cbpool.GetBucketWithAuth(*bucketName, mUser, mPassword)

	if err != nil {
		log.Printf("Failed to connect to bucket %v", err)
		return
	}

	log.Printf(" Bucket name %s Bucket %v", *bucketName, cbbucket)

	err = cbbucket.Set("k1", 5, "value")
	if err != nil {
		log.Printf("set failed error %v", err)
		return
	}

	if *authUser != "" {
		creds, err := cbauth.Auth(*authUser, *authPswd)
		if err != nil {
			log.Printf(" failed %v", err)
			return
		}

		canAccess, err := creds.CanAccessBucket(*bucketName)
		if err != nil {
			log.Printf(" can't access bucket %v", err)
		}

		log.Printf(" results canaccess %v bucket %v", canAccess, *bucketName)

		canRead, err := creds.CanReadBucket(*bucketName)
		if err != nil {
			log.Printf(" can't read bucket %v", err)
		}

		log.Printf(" results canread %v bucket %v", canRead, *bucketName)

		canDDL, err := creds.CanDDLBucket(*bucketName)
		if err != nil {
			log.Printf(" can't DDL bucket %v", err)
		}

		log.Printf(" results canDDL %v bucket %v", canDDL, *bucketName)
	}

}