File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\security\WhoAmI.java.html

1 package hudson.security;
2
3 import hudson.Extension;
4 import hudson.Functions;
5 import hudson.model.Api;
6 import hudson.model.UnprotectedRootAction;
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import jenkins.model.Jenkins;
12
13 import org.acegisecurity.Authentication;
14 import org.acegisecurity.GrantedAuthority;
15 import org.kohsuke.stapler.export.Exported;
16 import org.kohsuke.stapler.export.ExportedBean;
17
18 /**
19 * Expose the data needed for /whoAmI, so it can be exposed by Api.
20 *
21 * @author Ryan Campbell
22 *
23 */
24 @Extension
25 @ExportedBean
26 public class WhoAmI implements UnprotectedRootAction {
27
28 public Api getApi() {
29 return new Api(this);
30 }
31
32 @Exported
33 public String getName() {
34 return auth().getName();
35 }
36
37 @Exported
38 public boolean isAuthenticated() {
39 return auth().isAuthenticated();
40 }
41
42 @Exported
43 public boolean isAnonymous() {
44 return Functions.isAnonymous();
45 }
46
47 @Exported
48 public String getDetails() {
49 return auth().getDetails() != null ? auth().getDetails().toString() : null;
50 }
51
52 @Exported
53 public String getToString() {
54 return auth().toString();
55 }
56
57 private Authentication auth() {
58 return Jenkins.getAuthentication();
59 }
60
61 @Exported
62 public String[] getAuthorities() {
63 if (auth().getAuthorities() == null) {
64 return new String[0];
65 }
66 List <String> authorities = new ArrayList<String>();
67 for (GrantedAuthority a : auth().getAuthorities()) {
68 authorities.add(a.getAuthority());
69 }
70 return (String[]) authorities.toArray(new String[authorities.size()]);
71 }
72
73 @Override
74 public String getIconFileName() {
75 return null;
76 }
77
78 @Override
79 public String getDisplayName() {
80 return "Who Am I";
81 }
82
83 @Override
84 public String getUrlName() {
85 return "whoAmI";
86 }
87 }
88