@Override public Subject run() { return Subject.getSubject(AccessController.getContext()); } });
@VisibleForTesting public ReqContext(AccessControlContext acl_ctxt) { _subject = Subject.getSubject(acl_ctxt); _reqID = uniqueId.incrementAndGet(); }
@VisibleForTesting public ReqContext(AccessControlContext acl_ctxt) { subject = Subject.getSubject(acl_ctxt); reqID = uniqueId.incrementAndGet(); }
private void handleCallback(OAuthBearerTokenCallback callback) throws IOException { if (callback.token() != null) throw new IllegalArgumentException("Callback had a token already"); Subject subject = Subject.getSubject(AccessController.getContext()); Set<OAuthBearerToken> privateCredentials = subject != null ? subject.getPrivateCredentials(OAuthBearerToken.class) : Collections.emptySet(); if (privateCredentials.size() != 1) throw new IOException( String.format("Unable to find OAuth Bearer token in Subject's private credentials (size=%d)", privateCredentials.size())); callback.token(privateCredentials.iterator().next()); }
@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 public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { if (!configured()) throw new IllegalStateException("Callback handler not configured"); for (Callback callback : callbacks) { if (callback instanceof OAuthBearerTokenCallback) handleCallback((OAuthBearerTokenCallback) callback); else if (callback instanceof SaslExtensionsCallback) handleCallback((SaslExtensionsCallback) callback, Subject.getSubject(AccessController.getContext())); else throw new UnsupportedCallbackException(callback); } }
@Override public void open() throws TTransportException { try { AccessControlContext context = AccessController.getContext(); Subject subject = Subject.getSubject(context); Subject.doAs(subject, new PrivilegedExceptionAction<Void>() { public Void run() { try { wrapped.open(); } catch (TTransportException tte) { // Wrap the transport exception in an RTE, since Subject.doAs() then goes // and unwraps this for us out of the doAs block. We then unwrap one // more time in our catch clause to get back the TTE. (ugh) throw new RuntimeException(tte); } return null; } }); } catch (PrivilegedActionException ioe) { throw new RuntimeException("Received an ioe we never threw!", ioe); } catch (RuntimeException rte) { if (rte.getCause() instanceof TTransportException) { throw (TTransportException) rte.getCause(); } else { throw rte; } } }
public void init() { AccessControlContext acc = AccessController.getContext(); Subject subject = Subject.getSubject(acc); if (subject == null) { return; } setNameFromPrincipal(subject.getPrincipals()); }
/** * Look in the current subject for a WorkerToken. This should really only happen when we are in a worker, because the tokens will not * be placed in anything else. * * @param type the type of connection we need a token for. * @return the found token or null. */ public static WorkerToken findWorkerTokenInSubject(ThriftConnectionType type) { WorkerTokenServiceType serviceType = type.getWtType(); WorkerToken ret = null; if (serviceType != null) { Subject subject = Subject.getSubject(AccessController.getContext()); if (subject != null) { ret = ClientAuthUtils.findWorkerToken(subject, serviceType); } } return ret; } }
@GetMapping("/username") public String username() { Subject subject = Subject.getSubject(AccessController.getContext()); return subject.getPrincipals().iterator().next().getName(); } }
/** * Return the current user, including any doAs in the current stack. * @return the current user * @throws IOException if login fails */ @InterfaceAudience.Public @InterfaceStability.Evolving public static UserGroupInformation getCurrentUser() throws IOException { AccessControlContext context = AccessController.getContext(); Subject subject = Subject.getSubject(context); if (subject == null || subject.getPrincipals(User.class).isEmpty()) { return getLoginUser(); } else { return new UserGroupInformation(subject); } }
@Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException { Subject subject = Subject.getSubject(AccessController.getContext()); for (Callback callback : callbacks) { if (callback instanceof NameCallback) {
/** * It first looks the shiro subject in AccessControlContext since JMX will use multiple threads to * process operations from the same client, then it looks into Shiro's thead context. * * @return the shiro subject, null if security is not enabled */ @Override public Subject getSubject() { Subject currentUser; // First try get the principal out of AccessControlContext instead of Shiro's Thread context // since threads can be shared between JMX clients. javax.security.auth.Subject jmxSubject = javax.security.auth.Subject.getSubject(AccessController.getContext()); if (jmxSubject != null) { Set<ShiroPrincipal> principals = jmxSubject.getPrincipals(ShiroPrincipal.class); if (!principals.isEmpty()) { ShiroPrincipal principal = principals.iterator().next(); currentUser = principal.getSubject(); ThreadContext.bind(currentUser); return currentUser; } } // in other cases like rest call, client operations, we get it from the current thread currentUser = SecurityUtils.getSubject(); if (currentUser == null || currentUser.getPrincipal() == null) { throw new AuthenticationRequiredException("Failed to find the authenticated user."); } return currentUser; }
boolean performAuthentication = jaasLogin; GSSCredential gssCredential = null; Subject sub = Subject.getSubject(AccessController.getContext()); if (sub != null) { Set<GSSCredential> gssCreds = sub.getPrivateCredentials(GSSCredential.class);
loggedInSubject = Subject.getSubject(context); if (loggedInSubject == null) { throw new SQLException("The Subject is not set");
JMXAuditLogEntry entry = null; if (audit != OFF) { Subject subject = Subject.getSubject(AccessController.getContext()); String caller = "anonymous"; if (subject != null) {
try { Subject current = Subject.getSubject(AccessController.getContext()); System.out.println("----------------------------------------"); Set<Principal> principals = current.getPrincipals();
private Iterator<? extends Object> getJAASPrincipals() { Subject subject = Subject.getSubject(AccessController.getContext()); return subject != null && subject.getPrincipals() != null ? subject.getPrincipals().iterator() : Collections.emptyIterator(); }
public static String getCurrentUserName() { AccessControlContext acc = AccessController.getContext(); final Subject subject = Subject.getSubject(acc); if (subject != null && subject.getPrincipals(UserPrincipal.class).iterator().hasNext()) { return subject.getPrincipals(UserPrincipal.class).iterator().next().getName(); } else { return null; } }
public static String getCurrentUserName() { AccessControlContext acc = AccessController.getContext(); final Subject subject = Subject.getSubject(acc); if (subject != null && subject.getPrincipals(UserPrincipal.class).iterator().hasNext()) { return subject.getPrincipals(UserPrincipal.class).iterator().next().getName(); } else { return null; } }