Find a {@link Principal} for the given credential

@param key
@param value
@return principal
168966
public static <T> Principal getPrincipalForCredential(final PropertyKey<T> key, final T value) {

		return getPrincipalForCredential(key, value, false);

	}
553907
public PrincipalUser getRemoteUser(HttpServletRequest req) {
        requireArgument(req != null, "Request cannot be null.");
        
        if(req.getHeader(HttpHeaders.AUTHORIZATION) != null) {	
	        PrincipalUser result = null;
	        Object username = req.getAttribute(AuthFilter.USER_ATTRIBUTE_NAME);
	        
	        if (username != null) {
	            result = userService.findUserByUsername(String.class.cast(username));
	        }
	        return result;
        }
        
        return null;
    }
1348984
public Object getValue(String key) {
        if (values == null) {
            return null;
        }
        return values.get(key);
    }
1269791
@Override
    public Set<Principal> getPrincipals(final HttpServletRequest request) {
        LOGGER.debug("Checking for principals using {}", HttpHeaderPrincipalProvider.class.getSimpleName());

        if (headerName == null || separator == null) {
            LOGGER.debug("headerName or separator not initialized");
            return emptySet();
        }

        LOGGER.debug("Trying to get principals from header: {}; separator: {}", headerName, separator);

        if (request == null) {
            LOGGER.debug("Servlet request from servletCredentials was null");
            return emptySet();
        }

        final String value = request.getHeader(headerName);

        if (value == null) {
            LOGGER.debug("Value for header {} is null", headerName);
            return emptySet();
        }

        final String[] names = value.split(separator);

        final Set<Principal> principals = new HashSet<>();

        for (final String name : names) {
            LOGGER.debug("Adding HTTP header-provided principal: {}", name.trim());
            principals.add(createPrincipal(name));
        }

        return principals;

    }
973319
@SneakyThrows
    protected boolean createUserResource(final Principal p, final Credential credential) {
        val user = new UserResource();
        this.mapper.map(user, p, credential);
        return scimService.create("Users", user) != null;
    }
1114779
protected Principal getPrincipal() {
        final Object principal = requestContext.getProperty("Principal");
        if (principal != null) {
            return (Principal) principal;
        } else {
            return null;
        }
    }
1091483
def _get_principal(self, principal_arn):
        
        if ':cert/' in principal_arn:
            certs = [_ for _ in self.certificates.values() if _.arn == principal_arn]
            if len(certs) == 0:
                ()
            principal = certs[0]
            return principal
        else:
            # TODO: search for cognito_ids
            pass
        ()
811293
@GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/username/{username}")
    @Description("Returns the user having the given username.")
    public PrincipalUserDto getUserByUsername(@Context HttpServletRequest req,
        @PathParam("username") final String userName) {

        Enumeration<String> headerNames = req.getHeaderNames();
        while(headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            String headerValue = req.getHeader(headerName);
            System.out.println(headerName + ": " + headerValue);
        }

        if (userName == null || userName.isEmpty()) {
            throw new WebApplicationException("Username cannot be null or empty.", Status.BAD_REQUEST);
        }

        PrincipalUser remoteUser = validateAndGetOwner(req, null);
        PrincipalUser user = _uService.findUserByUsername(userName);

        if (user != null) {
            super.validateResourceAuthorization(req, user, remoteUser);
            return PrincipalUserDto.transformToDto(user);
        } else if (!remoteUser.isPrivileged()) {
            throw new WebApplicationException(Response.Status.FORBIDDEN.getReasonPhrase(), Response.Status.FORBIDDEN);
        } else {
            throw new WebApplicationException(Response.Status.NOT_FOUND.getReasonPhrase(), Response.Status.NOT_FOUND);
        }
    }
336199
protected AuthenticationHandlerExecutionResult createAuthenticatedSubjectResult(final Credential credential, final Subject currentUser) {
        val username = currentUser.getPrincipal().toString();
        return createHandlerResult(credential, this.principalFactory.createPrincipal(username));
    }
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;
    }
99611
public static final String replaceValueIfKeyIsPassword(String key, String value)
  {
    return replacePossiblePassword(containsPassword(key),value);
  }
346238
public Principal getUserPrincipal()
    {
        LoginHandler lh = Handlers.get( getServletContext() ).getLoginHandler();
        return lh.getUserPrincipal(getHandlerContext());
    }
532561
@Override
    protected Principal getPrincipal(String username) {
        Principal principal;

        // force lookup of user info
        if (username.startsWith("*")) {
            principal = readPrincipal(username.substring(1));
            if (principal != null) {
                synchronized (principals) {
                    principals.put(username.substring(1), principal);
                }
            }
        }

        synchronized (principals) {
            principal = (Principal) principals.get(username);
        }
        if (principal == null) {
            principal = readPrincipal(username);
            if (principal != null) {
                synchronized (principals) {
                    principals.put(username, principal);
                }
            }
        }
        return principal;
    }
945184
protected String determinePrincipalIdFrom(final UserProfile profile, final BaseClient client) {
        var id = profile.getId();
        val properties = client != null ? client.getCustomProperties() : new HashMap<>();
        if (client != null && properties.containsKey(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_PRINCIPAL_ATTRIBUTE_ID)) {
            val attrObject = properties.get(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_PRINCIPAL_ATTRIBUTE_ID);
            if (attrObject != null) {
                val principalAttribute = attrObject.toString();
                if (profile.containsAttribute(principalAttribute)) {
                    val firstAttribute = CollectionUtils.firstElement(profile.getAttribute(principalAttribute));
                    if (firstAttribute.isPresent()) {
                        id = firstAttribute.get().toString();
                        id = typePrincipalId(id, profile);
                    }
                    LOGGER.debug("Delegated authentication indicates usage of client principal attribute [{}] for the identifier [{}]", principalAttribute, id);
                } else {
                    LOGGER.warn("Delegated authentication cannot find attribute [{}] to use as principal id", principalAttribute);
                }
            } else {
                LOGGER.warn("No custom principal attribute was provided by the client [{}]. Using the default id [{}]", client, id);
            }
        } else if (StringUtils.isNotBlank(principalAttributeId)) {
            if (profile.containsAttribute(principalAttributeId)) {
                val firstAttribute = CollectionUtils.firstElement(profile.getAttribute(principalAttributeId));
                if (firstAttribute.isPresent()) {
                    id = firstAttribute.get().toString();
                    id = typePrincipalId(id, profile);
                }
            } else {
                LOGGER.warn("CAS cannot use [{}] as the principal attribute id, since the profile attributes do not contain the attribute. "
                    + "Either adjust the CAS configuration to use a different attribute, or contact the delegated authentication provider noted by [{}] "
                    + "to release the expected attribute to CAS", principalAttributeId, profile.getAttributes());
            }
            LOGGER.debug("Delegated authentication indicates usage of attribute [{}] for the identifier [{}]", principalAttributeId, id);
        } else if (isTypedIdUsed) {
            id = profile.getTypedId();
            LOGGER.debug("Delegated authentication indicates usage of typed profile id [{}]", id);
        }
        LOGGER.debug("Final principal id determined based on client [{}] and user profile [{}] is [{}]", profile, client, id);
        return id;
    }
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);
    }
561671
private Map<String, List<String>> groupPrincipalByScheme(
            List<Principal> principals) {
        Map<String, List<String>> principalsByScheme = new LinkedHashMap<String, List<String>>();

        String provider;
        List<String> principalValues;
        for (Principal principal : principals) {
            provider = principal.getProvider();
            if (!principalsByScheme.containsKey(provider)) {
                principalsByScheme.put(provider, new ArrayList<String>());
            }
            principalValues = principalsByScheme.get(provider);
            principalValues.add(principal.getId());
        }

        return principalsByScheme;
    }
5178
def get_principal(name):
    '''
    
    '''
    ret = {}

    cmd = __execute_kadmin('get_principal {0}'.format(name))

    if cmd['retcode'] != 0 or cmd['stderr']:
        ret['comment'] = cmd['stderr'].splitlines()[-1]
        ret['result'] = False

        return ret

    for i in cmd['stdout'].splitlines()[1:]:
        (prop, val) = i.split(':', 1)

        ret[prop] = val

    return ret