Esempio n. 1
0
// GoCall creates instance of security.Call that uses the provided Java
// Call as its underlying implementation.
func GoCall(env jutil.Env, jCall jutil.Object) (security.Call, error) {
	if jCall.IsNull() {
		return nil, nil
	}
	if jutil.IsInstanceOf(env, jCall, jCallImplClass) {
		// Called with our implementation of Call, which maintains a Go reference - use it.
		ref, err := jutil.CallLongMethod(env, jCall, "nativeRef", nil)
		if err != nil {
			return nil, err
		}
		return (*(*security.Call)(jutil.GoRefValue(jutil.Ref(ref)))), nil
	}
	// Reference Java call; it will be de-referenced when the go call
	// created below is garbage-collected (through the finalizer callback we
	// setup just below).
	jCall = jutil.NewGlobalRef(env, jCall)
	call := &callImpl{
		jCall: jCall,
	}
	runtime.SetFinalizer(call, func(c *callImpl) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		jutil.DeleteGlobalRef(env, c.jCall)
	})
	return call, nil
}
Esempio n. 2
0
// GoBlessingStore creates an instance of security.BlessingStore that uses the
// provided Java BlessingStore as its underlying implementation.
func GoBlessingStore(env jutil.Env, jBlessingStore jutil.Object) (security.BlessingStore, error) {
	if jBlessingStore.IsNull() {
		return nil, nil
	}
	if jutil.IsInstanceOf(env, jBlessingStore, jBlessingStoreImplClass) {
		// Called with our implementation of BlessingStore, which maintains a Go reference - use it.
		ref, err := jutil.JLongField(env, jBlessingStore, "nativeRef")
		if err != nil {
			return nil, err
		}
		return (*(*security.BlessingStore)(jutil.GoRefValue(jutil.Ref(ref)))), nil
	}
	// Reference Java BlessingStore; it will be de-referenced when the Go
	// BlessingStore created below is garbage-collected (through the finalizer
	// callback we setup just below).
	jBlessingStore = jutil.NewGlobalRef(env, jBlessingStore)
	s := &blessingStore{
		jBlessingStore: jBlessingStore,
	}
	runtime.SetFinalizer(s, func(s *blessingStore) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		jutil.DeleteGlobalRef(env, s.jBlessingStore)
	})
	return s, nil
}
Esempio n. 3
0
// GoPrincipal converts the provided Java VPrincipal object into a Go Principal.
func GoPrincipal(env jutil.Env, jPrincipal jutil.Object) (security.Principal, error) {
	if jPrincipal.IsNull() {
		return nil, nil
	}
	if jutil.IsInstanceOf(env, jPrincipal, jVPrincipalImplClass) {
		// Called with our implementation of VPrincipal, which maintains a Go reference - use it.
		ref, err := jutil.CallLongMethod(env, jPrincipal, "nativeRef", nil)
		if err != nil {
			return nil, err
		}
		return (*(*security.Principal)(jutil.GoRefValue(jutil.Ref(ref)))), nil
	}

	// Reference Java VPrincipal; it will be de-referenced when the Go Principal
	// created below is garbage-collected (through the finalizer callback we
	// setup just below).
	jPrincipal = jutil.NewGlobalRef(env, jPrincipal)
	// Create Go Principal.
	p := &principal{
		jPrincipal: jPrincipal,
	}
	runtime.SetFinalizer(p, func(p *principal) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		jutil.DeleteGlobalRef(env, p.jPrincipal)
	})
	return p, nil
}
Esempio n. 4
0
// GoAuthorizer converts the given Java authorizer into a Go authorizer.
func GoAuthorizer(env jutil.Env, jAuth jutil.Object) (security.Authorizer, error) {
	if jAuth.IsNull() {
		return nil, nil
	}
	if jutil.IsInstanceOf(env, jAuth, jPermissionsAuthorizerClass) {
		// Called with our implementation of Authorizer, which maintains a Go reference - use it.
		ref, err := jutil.JLongField(env, jAuth, "nativeRef")
		if err != nil {
			return nil, err
		}
		return *(*security.Authorizer)(jutil.GoRefValue(jutil.Ref(ref))), nil
	}
	// Reference Java dispatcher; it will be de-referenced when the go
	// dispatcher created below is garbage-collected (through the finalizer
	// callback we setup below).
	jAuth = jutil.NewGlobalRef(env, jAuth)
	a := &authorizer{
		jAuth: jAuth,
	}
	runtime.SetFinalizer(a, func(a *authorizer) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		jutil.DeleteGlobalRef(env, a.jAuth)
	})
	return a, nil
}
Esempio n. 5
0
// GoBlessingRoots creates an instance of security.BlessingRoots that uses the
// provided Java BlessingRoots as its underlying implementation.
func GoBlessingRoots(env jutil.Env, jBlessingRoots jutil.Object) (security.BlessingRoots, error) {
	if jBlessingRoots.IsNull() {
		return nil, nil
	}
	if jutil.IsInstanceOf(env, jBlessingRoots, jBlessingRootsImplClass) {
		// Called with our implementation of BlessingRoots, which maintains a Go reference - use it.
		ref, err := jutil.CallLongMethod(env, jBlessingRoots, "nativeRef", nil)
		if err != nil {
			return nil, err
		}
		return (*(*security.BlessingRoots)(jutil.GoRefValue(jutil.Ref(ref)))), nil
	}
	// Reference Java BlessingRoots; it will be de-referenced when the Go
	// BlessingRoots created below is garbage-collected (through the finalizer
	// callback we setup just below).
	jBlessingRoots = jutil.NewGlobalRef(env, jBlessingRoots)
	r := &blessingRoots{
		jBlessingRoots: jBlessingRoots,
	}
	runtime.SetFinalizer(r, func(r *blessingRoots) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		jutil.DeleteGlobalRef(env, r.jBlessingRoots)
	})
	return r, nil
}