Gets the realm from the subjects' WSCredential.

@param subject {@code null} is not supported.
@return
196143
public String getRealm(Subject subject) throws Exception {
        String realm = null;
        WSCredential credential = getWSCredential(subject);
        if (credential != null) {
            realm = credential.getRealmName();
        }
        return realm;
    }
296318
@Nonnull
  public static ICommonsList <IAuthToken> getAllTokensOfSubject (@Nonnull final IAuthSubject aSubject)
  {
    ValueEnforcer.notNull (aSubject, "Subject");

    return s_aRWLock.readLocked ( () -> CommonsArrayList.createFiltered (s_aMap.values (),
                                                                         aToken -> aToken.getIdentification ()
                                                                                         .hasAuthSubject (aSubject)));
  }
657549
@Override
    public Principal getCallerPrincipal() {

        String securityName = null;
        Principal principal = null;
        Subject callerSubject = getCallerSubject();

        if (callerSubject == null) {
            return null;
        }

        SubjectHelper subjectHelper = new SubjectHelper();
        if (subjectHelper.isUnauthenticated(callerSubject)) {
            return null;
        }

        // Here is the order to get the callerPrincipal
        // 1) jsonWebToken in subject
        // 2) From JASPIC property
        // 3) From WSCredential.getSecurityName
        // 4) From WSPrincipal
        // 5) First Principal in Subject

        // 1) From jsonWebToken in subject
        Principal jsonWebToken = MpJwtHelper.getJsonWebTokenPricipal(callerSubject);
        if (jsonWebToken != null) {
            return jsonWebToken;
        }

        WSCredential wscredential = getWSCredential(callerSubject);

        // 2) From JASPIC property
        if (wscredential != null) {
            try {
                principal = (Principal) wscredential.get("com.ibm.wsspi.security.cred.jaspi.principal");
                if (principal != null)
                    return principal;
            } catch (Exception e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Internal error getting JASPIC Principal from credential", e);
                }
            }

            // 3) From WSCredential.getSecurityName
            try {
                securityName = wscredential.getSecurityName();
            } catch (Exception e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Error getting securityName from WSCredential", e);
                }
            }

            WSPrincipal wsPrincipal = null;
            if (securityName != null) {
                Set<WSPrincipal> principals = callerSubject.getPrincipals(WSPrincipal.class);
                if (!principals.isEmpty()) {
                    wsPrincipal = principals.iterator().next();
                    wsPrincipal = new WSPrincipal(securityName, wsPrincipal.getAccessId(), wsPrincipal.getAuthenticationMethod());
                }

                if (wsPrincipal != null) {
                    return wsPrincipal;
                }
            }

            // 4) From WSPrincipal
            Set<Principal> principals = callerSubject.getPrincipals();
            if (principals.size() > 0) {
                for (Iterator<Principal> iterator = principals.iterator(); iterator.hasNext();) {
                    principal = iterator.next();
                    if (principal instanceof WSPrincipal)
                        return principal;
                }
            }

            // There is no WSPrincipal so just return first one
            // 5) First Principal in Subject
            return principals.iterator().next();
        }

        return null;
    }
520701
public Message message(String subject, String messageBody) {
        Collection<Member> recipients = new ArrayList<Member>();
        return message(subject, messageBody, recipients);
    }
1187929
private Set<String> getUserRoles(Subject subject) {
        Set<String> userRoles = null;

        // get roles from specified classes
        Set<Principal> principals = subject.getPrincipals();
        if (roleClassNames != null && roleClassNames.size() > 0) {
            for (Principal p : principals) {
                if (roleClassNames.contains(p.getClass().getName())) {
                    if (userRoles == null) userRoles = new HashSet<String>();
                    userRoles.add(p.getName());
                }
            }
        }

        // get roles from specified attributes
        Map<String, Set<String>> attributes =
                SubjectUtils.getAttributes(subject);
        for (String key : attributes.keySet()) {
            if (roleAttributeNames.contains(key)) {
                if (userRoles == null) userRoles = new HashSet<String>();
                userRoles.addAll(attributes.get(key));
            }
        }

        if (userRoles == null) userRoles = Collections.emptySet();
        if (logger.isDebugEnabled()) {
            for (String r : userRoles) {
                logger.debug("found role: {}", r);
            }
        }

        return userRoles;
    }
1212074
public boolean isUnauthenticated(Subject subject) {
        if (subject == null) {
            return true;
        }

        WSCredential wsCred = getWSCredential(subject);
        if (wsCred == null) {
            return true;
        } else {
            return wsCred.isUnauthenticated();
        }
    }
948157
public String getRealm() {
        if (UNDEFINED.equals(realm)) {
            Principal principal = securityIdentity.getPrincipal();
            String realm = null;
            if (principal instanceof RealmPrincipal) {
                realm = ((RealmPrincipal)principal).getRealm();
            }
            this.realm = realm;

        }

        return this.realm;
    }
1357023
public Collection<WsGetGroupsResult> getGroupsForSubjectId(final String subjectId) {
        try {
            val groupsClient = new GcGetGroups().addSubjectId(subjectId);
            val results = groupsClient.execute().getResults();
            if (results == null || results.length == 0) {
                LOGGER.warn("Subject id [{}] could not be located.", subjectId);
                return new ArrayList<>(0);
            }
            LOGGER.debug("Found [{}] groups for [{}]", results.length, subjectId);
            return CollectionUtils.wrapList(results);
        } catch (final Exception e) {
            LOGGER.warn("Grouper WS did not respond successfully. Ensure your credentials are correct "
                + ", the url endpoint for Grouper WS is correctly configured and the subject [{}] exists in Grouper.", subjectId, e);
        }
        return new ArrayList<>(0);
    }
121141
@Override
    public void setCredential(Subject subject) throws CredentialException {
        Set<WSPrincipal> principals = subject.getPrincipals(WSPrincipal.class);
        if (principals.isEmpty()) {
            return;
        }
        if (principals.size() != 1) {
            throw new CredentialException("Too many WSPrincipals in the subject");
        }
        WSPrincipal principal = principals.iterator().next();
        setCredential(subject, principal);
    }
784000
public Principal getSubjectDN() {
        if (info == null)
            return null;
        try {
            Principal subject = (Principal)info.get(X509CertInfo.SUBJECT + DOT +
                                                    X509CertInfo.DN_NAME);
            return subject;
        } catch (Exception e) {
            return null;
        }
    }
545255
private String resolveSubjectToDatastream(String subject) throws ServerException{
        String pidURI = PID.toURI(m_obj.getPid());
        if (subject.startsWith(pidURI)) {
            if (subject.length() == pidURI.length()) {
                return "RELS-EXT";
            }
            if (subject.charAt(pidURI.length()) == '/') {
                return "RELS-INT";
            }
        }
        throw new GeneralException("Cannot determine which relationship datastream to update for subject " + subject + ".  Relationship subjects must be the URI of the object or the URI of a datastream within the object.");
    }
903468
private String getCerticateSubject(AtomicServiceReference<Object> serviceRef, Properties sslProperties) {
        String certificateDN = null;
        try {
            certificateDN = sslHelper.getClientKeyCertSubject(serviceRef, sslProperties);
        } catch (KeyStoreException ke) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.error(tc, "CWKKD0020.ssl.get.certificate.user", MONGO, id, ke);
            }
            throw new RuntimeException(Tr.formatMessage(tc, "CWKKD0020.ssl.get.certificate.user", MONGO, id, ke));
        } catch (CertificateException ce) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.error(tc, "CWKKD0020.ssl.get.certificate.user", MONGO, id, ce);
            }
            throw new RuntimeException(Tr.formatMessage(tc, "CWKKD0020.ssl.get.certificate.user", MONGO, id, ce));
        }

        // handle null .... cannot find the client key
        if (certificateDN == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.error(tc, "CWKKD0026.ssl.certificate.exception", MONGO, id);
            }
            throw new RuntimeException(Tr.formatMessage(tc, "CWKKD0026.ssl.certificate.exception", MONGO, id));
        }

        return certificateDN;
    }
908950
def _get_subject(self):
        
        subject_context = SubjectContext(yosai=self, security_manager=self.security_manager)
        subject = self.security_manager.create_subject(subject_context=subject_context)
        global_subject_context.stack.append(subject)
        return subject
584544
def get_root_subject(self):
        ''

        manifest = URIRef(self.manifest)

        if list(self.rdf.triples((manifest, None, None))):
            return manifest
        else:
            return self.rdf.subjects(None, self.manifest).next()
781943
@GET
    public Iterator<EmoRole> getAllRoles(final @Authenticated Subject subject) {
        return _uac.getAllRoles(subject);
    }
766126
public static SipPrincipal impersonatePrincipal(String username, Realm realm) {
		Method getPrincipalMethod = null;
		Class clazz = realm.getClass();
		try {
			if(!(realm instanceof RealmBase)) {
				throw new RuntimeException("Only Realms extending RealmBase are supported. Report this error. Current realm class is " +
						realm.getClass().getCanonicalName());
			}
			while(getPrincipalMethod == null) {
				try {
					getPrincipalMethod = clazz.getDeclaredMethod("getPrincipal", String.class);
				} catch (NoSuchMethodException e) {
					log.warn("unexpected exception while impersonatePrincipal", e);
				}
				clazz = clazz.getSuperclass();
				if(clazz == null) break;
			}
			getPrincipalMethod.setAccessible(true);
			Principal principal =  (Principal) getPrincipalMethod.invoke(realm, username);
			return new CatalinaSipPrincipal(principal);
		} catch (Throwable t) {
			log.error("Could not impersonate user " + username, t);
		} finally {
			if(getPrincipalMethod != null) {
				getPrincipalMethod.setAccessible(false);
			}
		}
		return null;
		
	}
98104
public Observable<ServiceResponse<UserInner>> getPublishingUserWithServiceResponseAsync() {
        if (this.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
        }
        return service.getPublishingUser(this.apiVersion(), this.acceptLanguage(), this.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<UserInner>>>() {
                @Override
                public Observable<ServiceResponse<UserInner>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<UserInner> clientResponse = getPublishingUserDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }