title: Jenkins- groovy, read folder permisisons
body: <p>Does anybody have an idea, if its possible, then how to read the permissions for given Jenkins folder?</p>
  
  <ul>
  <li>using CloudBees Folder plugin</li>
  <li>(<a href="https://wiki.jenkins.io/display/JENKINS/CloudBees+Folders+Plugin" rel="nofollow noreferrer">https://wiki.jenkins.io/display/JENKINS/CloudBees+Folders+Plugin</a>)</li>
  <li>using Matrix Authorization Strategy</li>
  <li>(<a href="https://plugins.jenkins.io/matrix-auth" rel="nofollow noreferrer">https://plugins.jenkins.io/matrix-auth</a>)</li>
  </ul>
  
  <p>I found the way how to iterate over jobs and get <code>Folder</code> "jobs" 
  But have no idea how to access the folder permisisons/read it</p>
  
  <p>Access to folder is pretty simple </p>
  
  <pre><code>import com.cloudbees.hudson.plugins.folder.*
  import groovyjarjarasm.asm.Item
  
    def items=Jenkins.instance.getAllItems();
  
    items.each{
      if(it instanceof Folder){
        println it.fullName
      } 
    }  
  </code></pre>
  
  <p>I noticed, when eg. on folder 'A' will grant to user Aread (ldapid) read permissions, then in config file is following </p>
  
  <pre><code>&lt;com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty&gt;
        &lt;inheritanceStrategy class="org.jenkinsci.plugins.matrixauth.inheritance.InheritParentStrategy"/&gt;
        &lt;permission&gt;com.cloudbees.plugins.credentials.CredentialsProvider.View:Aread&lt;/permission&gt;
  </code></pre>
  
  <p>I found also javadoc for cloudbee's folder class, but there is nothing about permision :/ </p>
  
  <p><a href="https://javadoc.jenkins.io/plugin/cloudbees-folder/com/cloudbees/hudson/plugins/folder/package-summary.html" rel="nofollow noreferrer">https://javadoc.jenkins.io/plugin/cloudbees-folder/com/cloudbees/hudson/plugins/folder/package-summary.html</a> </p>
  
  <p>Thanks for your tips 
  (I am using inbuilt script editor for running groovy script)</p>
  
  <p>After some findings I found some clues in 
  <a href="https://stackoverflow.com/questions/26449432/jenkins-add-permissions-to-jobs-using-groovy">Jenkins Add permissions to jobs using groovy</a></p>
  
  <p>But, when implemented</p>
  
  <pre><code>import com.cloudbees.hudson.plugins.folder.*
  import groovyjarjarasm.asm.Item
  import jenkins.model.Jenkins
  import hudson.security.*
  import hudson.model.*
  
  //AbstractProject proj = Hudson.instance.getItem("YourJob")
  //AuthorizationMatrixProperty authProperty = proj.getProperty(AuthorizationMatrixProperty.class)
  
    def items=Jenkins.instance.getAllItems();
  
    items.each{
      if(it instanceof Folder){
        println it.fullName
        AbstractProject proj = Hudson.instance.getItem(it.fullName)
        AuthorizationMatrixProperty authProperty = proj.getProperty(AuthorizationMatrixProperty.class)
      } 
    } 
  </code></pre>
  
  <p>got an error</p>
  
  <pre><code>org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.cloudbees.hudson.plugins.folder.Folder@a35435b[fooFolderName]' with class 'com.cloudbees.hudson.plugins.folder.Folder' to class 'hudson.model.AbstractProject'
  </code></pre>
  
  <p>(already tried <em>it.name</em>, / <em>it</em> as well :/
  - code snippet will do not fail if there is not a folder, but classic job</p>