Question

In FUSE (or Karaf), how does one get the caller user id? I'm actually using FUSE with blueprint services.

For example, in a J2EE session bean, you can do:

sessionCtx.getCallerPrincipal()

Is there an equivalent in the OSGI service space?

Was it helpful?

Solution

In Karaf we use plain jaas to do service authentication. So you can use the following code to access the subject and principals.

AccessControlContext acc = AccessController.getContext();
Subject subject = Subject.getSubject(acc);
Set<Principal> principals = subject.getPrincipals();

In karaf 3 there is also built in role based access control for OSGi services. So you can define which roles may access which services.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top