X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=jaccmagic.txt;fp=jaccmagic.txt;h=decf99e0be5140b4b333210c55b6834dd0f0a8ef;hb=8845e7fe6141ccc98fd070ee4e653941f6e60508;hp=0000000000000000000000000000000000000000;hpb=b5dd7f771153492ebf5b70949dba8914af58a3cd;p=photos diff --git a/jaccmagic.txt b/jaccmagic.txt new file mode 100644 index 0000000..decf99e --- /dev/null +++ b/jaccmagic.txt @@ -0,0 +1,33 @@ + // https://blogs.oracle.com/monzillo/entry/using_jacc_to_determine_a + + Subject subject = (Subject) PolicyContext + .getContext("javax.security.auth.Subject.container"); + CodeSource cs = new CodeSource(null, + (java.security.cert.Certificate[]) null); + Principal principals[] = (subject == null ? new Principal[0] : subject + .getPrincipals().toArray(new Principal[0])); + for (Principal principal : principals) { + System.out + .println(principal + " " + principal.getClass().getName()); + } + + ProtectionDomain pd = new ProtectionDomain(cs, null, null, principals); + Policy policy = Policy.getPolicy(); + PermissionCollection pc = policy.getPermissions(pd); + pc.implies(new WebRoleRefPermission(null, null)); + Set roleSet = new HashSet(); + Enumeration e = pc.elements(); + while (e.hasMoreElements()) { + Permission p = e.nextElement(); + if (p instanceof WebRoleRefPermission) { + String roleRef = p.getActions(); + // confirm roleRef via isUserInRole to ensure proper scoping to + // Servlet Name + // if (request.isUserInRole(roleRef)) { + roleSet.add(p.getActions()); + System.out.println("Role actions: " + p.getActions()); + System.out.println("Role name: " + p.getName()); + // } + } + } + System.out.println("Roles in the context of this page: " + roleSet);