private boolean isNimbus(Subject who) { Set<Principal> principals; boolean isNimbusInstance = false; if (who != null) { principals = who.getPrincipals(); for (Principal principal : principals) { if (principal instanceof NimbusPrincipal) { isNimbusInstance = true; } } } return isNimbusInstance; }
/** * The default constructor initializing the sets of public and private * credentials and principals with the empty set. */ public Subject() { principals = new SecureSet<Principal>(_PRINCIPALS); publicCredentials = new SecureSet<Object>(_PUBLIC_CREDENTIALS); privateCredentials = new SecureSet<Object>(_PRIVATE_CREDENTIALS); readOnly = false; }
/** * Get the set of TokenIdentifiers belonging to this UGI * * @return the set of TokenIdentifiers belonging to this UGI */ public synchronized Set<TokenIdentifier> getTokenIdentifiers() { return subject.getPublicCredentials(TokenIdentifier.class); }
@Override public String run() { Subject subject = Subject.getSubject(acc); if (subject == null) { return null; } Set<Principal> principals = subject.getPrincipals(); if (principals == null) { return null; } for (Principal p : principals) { return p.getName(); } return null; } });
@Override protected Subject getDefaultSubject() { HashSet<Principal> principals = new HashSet<Principal>(); principals.add(new Principal() { public String getName() { return "user"; } public String toString() { return "user"; } }); return new Subject(true, principals, new HashSet<Object>(), new HashSet<Object>()); } }
@Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { String username = (String) options.get(USERNAME_CONFIG); if (username != null) subject.getPublicCredentials().add(username); String password = (String) options.get(PASSWORD_CONFIG); if (password != null) subject.getPrivateCredentials().add(password); }
private static <T> T doAs(Subject subject, GssSupplier<T> action) { return Subject.doAs(subject, (PrivilegedAction<T>) () -> { try { return action.get(); } catch (GSSException e) { throw new RuntimeException(e); } }); } }
private int committedTokenCount() { return subject.getPrivateCredentials(OAuthBearerToken.class).size(); } }
@Override public Subject run() { return Subject.getSubject(AccessController.getContext()); } });
/** * Returns this {@code Subject}'s public credentials which are a subclass of * the {@code Class} provided. * * @param c * the {@code Class} as a criteria which the public credentials * returned must satisfy. * @return this {@code Subject}'s public credentials. Modifications to the * returned set of credentials do not affect this {@code Subject}'s * credentials. */ public <T> Set<T> getPublicCredentials(Class<T> c) { return publicCredentials.get(c); }
private <T extends Principal> T getCanonicalUser(Class<T> cls) { for(T user: subject.getPrincipals(cls)) { return user; } return null; }
public void init() { AccessControlContext acc = AccessController.getContext(); Subject subject = Subject.getSubject(acc); if (subject == null) { return; } setNameFromPrincipal(subject.getPrincipals()); }
static KerberosTicket getTicketGrantingTicket(Subject subject) { Set<KerberosTicket> tickets = subject.getPrivateCredentials(KerberosTicket.class); for (KerberosTicket ticket : tickets) { if (isOriginalTicketGrantingTicket(ticket)) { return ticket; } } throw new IllegalArgumentException("kerberos ticket not found in " + subject); }
@Override public String toString() { return "LoginManager(serviceName=" + serviceName() + // subject.toString() exposes private credentials, so we can't use it ", publicCredentials=" + subject().getPublicCredentials() + ", refCount=" + refCount + ')'; }
/** * Returns this {@code Subject}'s private credentials which are a subclass * of the {@code Class} provided. * * @param c * the {@code Class} as a criteria which the private credentials * returned must satisfy. * @return this {@code Subject}'s private credentials. Modifications to the * returned set of credentials do not affect this {@code Subject}'s * credentials. */ public <T> Set<T> getPrivateCredentials(Class<T> c) { return privateCredentials.get(c); }
@Override public Set<Principal> getPrincipals() { return subject.getPrincipals(); } }
/** * Returns this {@code Subject}'s {@link Principal} which is a subclass of * the {@code Class} provided. * * @param c * the {@code Class} as a criteria which the {@code Principal} * returned must satisfy. * @return this {@code Subject}'s {@link Principal}. Modifications to the * returned set of {@code Principal}s do not affect this {@code * Subject}'s set. */ public <T extends Principal> Set<T> getPrincipals(Class<T> c) { return ((SecureSet<Principal>) principals).get(c); }
public Set<Principal> getPrincipals() { return subject.getPrincipals(); }
/** * The primary principal associated current subject */ public Principal principal() { if (subject == null) { return null; } Set<Principal> princs = subject.getPrincipals(); if (princs.size() == 0) { return null; } return (Principal) (princs.toArray()[0]); }
/** * The primary principal associated current subject */ public Principal principal() { if (_subject == null) return null; Set<Principal> princs = _subject.getPrincipals(); if (princs.size() == 0) return null; return (Principal) (princs.toArray()[0]); }