Ok, I found this 
(https://wiki.jenkins-ci.org/display/JENKINS/Making+your+plugin+behave+in+secured+Jenkins)
 
right after I posted here (naturally). So I changed my check to look like 
this:

private boolean userHasPermission(Permission permission) {
ACL acl = Jenkins.getInstance().getACL();
return acl.hasPermission(Jenkins.getAuthentication(), permission);
}

Now I have the opposite problem: When logged in as the Readonly user, and I 
pass Permission.READ into that method, it returns "false". However, the 
Admin user has access as expected.

Any ideas?

On Saturday, February 23, 2013 2:29:04 PM UTC-7, JoelJ wrote:
>
> After searching around on Google and asking in IRC (it's saturday, I 
> wasn't really expecting much activity ;) ), I've decided I should ask here.
>
> What's the proper way to check if a user has permissions to do something? 
> Here's what I have:
>
> if(currentUser.hasPermission(Permission.DELETE)) {
>
> //procede with delete
>
> } 
>
>
> So on my test Jenkins instance I set up Matrix security and a readonly 
> user. Here's what it looks like:
>
>
> <https://lh3.googleusercontent.com/-yap_H49l5ko/USkzxcn4CSI/AAAAAAAACUM/zHJJvjz9kGE/s1600/Screen+Shot+2013-02-23+at+2.24.36+PM.png>
>  
> However, the above check always returns true. In fact, with a debugger I 
> tried every different Permission and it always returns true.
>
> I'm writing a plugin that allows users to upload files to Jenkins and if 
> you have access to delete, you see a little "Delete" button, but I 
> obviously don't want just anyone to do that.
>
> It seems like I'm completely missing something here. Any ideas?
>
> Thanks,
>
> -Joel
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to