Finds the user name associated with a given token (e.g. for audit).
@param token a token
@return a user name, or null if the otken did not match anything
354540
public String findUsername( String token ) {
		return token == null ? null : this.tokenToUsername.get( token );
	}
229906
function findUserFromAccessToken(accessToken, UserModel) {

    if (!accessToken) return null;

    return UserModel.findById(accessToken.userId).then((user) => {
        if (!user) return Promise.reject('No user with this access token was found.');
        return Promise.resolve(user);
    });
}
231056
public static String getUsername(String token) {
		String accessTokenPayload = token.substring(token.indexOf(".") + 1, token.lastIndexOf(".") );
		byte[] decoded = Base64.getMimeDecoder().decode(accessTokenPayload);
		String output = new String(decoded);
		Map<String,Object> myMap = new HashMap<String, Object>();
		String result = "unknown";

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			myMap = objectMapper.readValue(output, HashMap.class);
			if(myMap.get("sub") instanceof String) {
				result = (String) myMap.get("sub");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
1035322
public static String cleanseToken(String token) {
    if (token == null || token.length() == 0) { return token; };

    String cleansed = token.replaceAll(SPACE, UNDERSCORE);
    cleansed = cleansed.replaceAll(Constants.SEP, UNDERSCORE);

    return cleansed;
  }
230448
public Map<String, Object> validateTokenAndGetClaims(final String token) {
        final CommonProfile profile = validateToken(token);

        final Map<String, Object> claims = new HashMap<>(profile.getAttributes());
        claims.put(JwtClaims.SUBJECT, profile.getId());

        return claims;
    }
266723
@Restricted(NoExternalUse.class)
    public @Nullable ApiTokenStore.HashedToken getLegacyTokenOf(@Nonnull User user) {
        ApiTokenProperty apiTokenProperty = user.getProperty(ApiTokenProperty.class);
        return apiTokenProperty.getTokenStore().getLegacyToken();
    }
553012
@SuppressWarnings("unchecked")
    @Override
	public <T extends ApiUser> T getUserByName(String username) {
	    User sfsUser = getZone().getUserByName(username);
        if(sfsUser != null && sfsUser.containsProperty(APIKey.USER))
            return (T) sfsUser.getProperty(APIKey.USER);
        return null;
	}
189701
public boolean validateToken(final String token) {
        try {
            final JwtParser jwtParser = Jwts.parser().setSigningKey(key);
            jwtParser.parse(token);
            this.subject = jwtParser.parseClaimsJws(token).getBody().getSubject();
            this.expiration = jwtParser.parseClaimsJws(token).getBody().getExpiration();
            return true;
        } catch (SignatureException e) {
            LOGGER.info(SecurityMarkers.SECURITY_FAILURE, "Received token that did not pass signature verification");
        } catch (ExpiredJwtException e) {
            LOGGER.debug(SecurityMarkers.SECURITY_FAILURE, "Received expired token");
        } catch (MalformedJwtException e) {
            LOGGER.debug(SecurityMarkers.SECURITY_FAILURE, "Received malformed token");
            LOGGER.debug(SecurityMarkers.SECURITY_FAILURE, e.getMessage());
        } catch (UnsupportedJwtException | IllegalArgumentException e) {
            LOGGER.error(SecurityMarkers.SECURITY_FAILURE, e.getMessage());
        }
        return false;
    }
196943
protected function findUserByToken(Token $token)
    {
        // retrieves the user ID from the token.
        $id = $token->getClaim('sub');

        // use the users provider to find the token subject (user)
        // but it's id (subject)
        return $this->provider->retrieveById($id);
    }
1057876
public UserRecoverRequest retrieveRecoverRequest(String token) {
		UserRecoverRequest req = this.dao.exists(token, UserRecoverRequest.class);
		if (req == null)
			return null;
		if (req.getExpiration().getTime() < System.currentTimeMillis())
			return null;
		if (req.isUsed())
			return null;
		return req;
	}
38572
public static final void signAuthToken(AuthToken token) {
        String signature = generateSignature(token);
        token.setSignature(signature);
    }
977161
public Instant getCreatedTimeFromToken(String token) {
        try {
            final Claims claims = getClaimsFromToken(token);
            return Instant.ofEpochMilli((Long) claims.get(CLAIM_KEY_CREATED));
        } catch (Exception e) {
            log.error("get created Time from jwt token error : {}", e.getMessage());
            return null;
        }
    }
428673
protected User getUser(String username) {
    Integer id = userIds().get(username.toLowerCase());
    if (id == null) {
      throw new IllegalStateException(format("Could not find ID corresponding to username [%s]", username));
    }

    return getUser(id);
  }
233288
@Override
    public String extractSignedToken(String token) {
        String[] chunks = token.split("-", 3);
        if (chunks.length != 3) {
            // Invalid format
            return null;
        }
        String signature = chunks[0];
        String nonce = chunks[1];
        String raw = chunks[2];
        if (constantTimeEquals(signature, sign(nonce + "-" + raw))) {
            return raw;
        } else {
            return null;
        }
    }
519749
public String getToken(){
		if(this.tokenPosition>0){
			String[] ar = StringUtils.split(this.line, null, this.tokenPosition+1);
			if(ar!=null && ar.length>(this.tokenPosition-1)){
				return StringUtils.trim(ar[this.tokenPosition-1]);
			}
		}
		return null;
	}
441374
@Nullable
	static String extractName(@Nullable Object authentication) {

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

		Expression expression = PARSER.parseExpression(NAME_EXPRESSION);

		return expression.getValue(authentication, String.class);
	}
1315485
public Parser<Token> token(String tokenName) {
    return Parsers.token(InternalFunctors.tokenWithSameValue(word(tokenName)));
  }