Code example for Subject

Methods: doAsgetPrincipals

0
 
public class PreserveCombiner { 
 
    public static void main(String[] args) throws Exception {
 
        Subject s = new Subject();
        s.getPrincipals().add(new X500Principal("cn=duke"));
 
        String result = (String)Subject.doAs(s, new PrivilegedAction() {
            public Object run() {
 
                // get subject from current ACC - this always worked 
                Subject doAsSubject =
                        Subject.getSubject(AccessController.getContext());
                if (doAsSubject == null) {
                    return "test 1 failed"; 
                } else { 
                    System.out.println(doAsSubject);
                    System.out.println("test 1 passed");
                }