Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Verifying if user is in group (outside of master node)? #4016

JShelton ·

Hello!

I'm trying to verify that a user is in a particular group via a config that is not running on the master node. Specifically, a remote Windows node. Is this possible? How am I able to accomplish this?

Code I am currently using is this:

groovy:
import com.pmease.quickbuild.persistence.*

SessionManager.openSession();
try {
    def user = system.userManager.load(request.requesterId)
    if (user.groupNames.contains("SpecialUsers"))
      logger.info('user is in this group')
    else
      logger.info('user is not in this group')
 
} finally {
  SessionManager.closeSession();
}

Error (only on remote node):

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pmease.quickbuild.model.User.memberships, could not initialize proxy - no Session
    at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:576)
    at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:215)
    at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:555)
    at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:143)
    at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:294)
    at java_util_List$iterator.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java...
  • solved #2
  • replies 1
  • views 23
  • stars 0
robinshen ADMIN ·

Unfortunately this only works on server node. You may run the logic on server and store the result into a variable, and access that variable from agent if necessary.