Java 类io.jsonwebtoken.Header 实例源码

项目:USM    文件:DefaultJwtTokenHandler.java   
static private String signClaims(Claims claims) 
{
  // Header
  Map<String, Object> header = new HashMap<>();
  header.put(Header.TYPE, Header.JWT_TYPE);
  header.put(JwsHeader.ALGORITHM, signatureAlgorithm);

  // Signature key
  Key key = new SecretKeySpec(getSecretKey(), 
                              signatureAlgorithm.getJcaName());

  String ret = Jwts.builder().
          setHeader(header).
          setClaims(claims).
          signWith(signatureAlgorithm, key).
          compact();

  return ret;
}
项目:jjwt    文件:DefaultCompressionCodecResolver.java   
@Override
public CompressionCodec resolveCompressionCodec(Header header) {
    String cmpAlg = getAlgorithmFromHeader(header);

    final boolean hasCompressionAlgorithm = Strings.hasText(cmpAlg);

    if (!hasCompressionAlgorithm) {
        return null;
    }
    if (CompressionCodecs.DEFLATE.getAlgorithmName().equalsIgnoreCase(cmpAlg)) {
        return CompressionCodecs.DEFLATE;
    }
    if (CompressionCodecs.GZIP.getAlgorithmName().equalsIgnoreCase(cmpAlg)) {
        return CompressionCodecs.GZIP;
    }

    throw new CompressionException("Unsupported compression algorithm '" + cmpAlg + "'");
}
项目:thingsboard    文件:AbstractControllerTest.java   
protected void validateJwtToken(String token, String username) {
    Assert.assertNotNull(token);
    Assert.assertFalse(token.isEmpty());
    int i = token.lastIndexOf('.');
    Assert.assertTrue(i > 0);
    String withoutSignature = token.substring(0, i + 1);
    Jwt<Header, Claims> jwsClaims = Jwts.parser().parseClaimsJwt(withoutSignature);
    Claims claims = jwsClaims.getBody();
    String subject = claims.getSubject();
    Assert.assertEquals(username, subject);
}
项目:apiman-plugins    文件:ConfigCheckingJwtHandler.java   
@Override
public Map<String, Object> onPlaintextJwt(@SuppressWarnings("rawtypes") Jwt<Header, String> jwt) {
    if (config.getRequireSigned()) {
        super.onPlaintextJwt(jwt);
    }
    return Collections.emptyMap();
}
项目:come2help    文件:JwtTokenHandler.java   
public String createTokenForUser(UserAuthentication user) {
    return Jwts.builder()
            .setSubject(user.getInternalId() != null ? user.getInternalId() + "" : null)
            .setHeaderParam(Header.TYPE, Header.JWT_TYPE)
            .claim(CLAIM_AUTH_PROVIDER, user.getAuthProvider())
            .claim(CLAIM_EXTERNAL_ID, user.getExternalId())
            .claim(CLAIM_GIVEN_NAME, user.getGivenName())
            .claim(CLAIM_SURNAME, user.getSurname())
            .claim(CLAIM_EMAIL, user.getEmail())
            .claim(CLAIM_AUTHORITIES, user.getAuthorities().stream().map(a -> a.getAuthority()).collect(Collectors.toList()))
            .setIssuedAt(new Date())
            .setExpiration(new Date(new Date().getTime() + DAY_DURATION))
            .signWith(SignatureAlgorithm.HS256, secretKey)
            .compact();
}
项目:spring-oauth2-jwt-minimal    文件:JwtTokenHandler.java   
public String createTokenForUser(UserAuthentication user) {
    return Jwts.builder()
            .setSubject(user.getName())
            .setHeaderParam(Header.TYPE, Header.JWT_TYPE)
            .claim(CLAIM_AUTH_PROVIDER, user.getAuthProvider())
            .claim(CLAIM_EXTERNAL_ID, user.getExternalId())
            .claim(CLAIM_GIVEN_NAME, user.getGivenName())
            .claim(CLAIM_SURNAME, user.getSurname())
            .claim(CLAIM_EMAIL, user.getEmail())
            .setIssuedAt(new Date())
            .setExpiration(new Date(new Date().getTime() + DAY_DURATION))
            .signWith(SignatureAlgorithm.HS256, secretKey)
            .compact();
}
项目:jjwt    文件:DefaultJwtParser.java   
@Override
public Jwt<Header, String> parsePlaintextJwt(String plaintextJwt) {
    return parse(plaintextJwt, new JwtHandlerAdapter<Jwt<Header, String>>() {
        @Override
        public Jwt<Header, String> onPlaintextJwt(Jwt<Header, String> jwt) {
            return jwt;
        }
    });
}
项目:jjwt    文件:DefaultJwtParser.java   
@Override
public Jwt<Header, Claims> parseClaimsJwt(String claimsJwt) {
    try {
        return parse(claimsJwt, new JwtHandlerAdapter<Jwt<Header, Claims>>() {
            @Override
            public Jwt<Header, Claims> onClaimsJwt(Jwt<Header, Claims> jwt) {
                return jwt;
            }
        });
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedJwtException("Signed JWSs are not supported.", iae);
    }
}
项目:che-starter    文件:KeycloakTokenParser.java   
@SuppressWarnings("rawtypes")
public String getIdentityId(final String keycloakToken) throws JsonProcessingException, IOException {
    Jwt<Header, Claims> jwt = getJwt(keycloakToken);
    return jwt.getBody().getSubject();
}
项目:che-starter    文件:KeycloakTokenParser.java   
@SuppressWarnings("rawtypes")
public String getSessionState(final String keycloakToken) throws JsonProcessingException, IOException {
   Jwt<Header, Claims> jwt = getJwt(keycloakToken);
   return jwt.getBody().get(SESSION_STATE).toString();
}
项目:che-starter    文件:KeycloakTokenParser.java   
@SuppressWarnings("rawtypes")
private Jwt<Header, Claims> getJwt(final String keycloakToken) {
    String jwt = keycloakToken.replaceFirst(TOKEN_PREFIX, "");
    String tokenWithoutSignature = getJWSWithoutSignature(jwt);
    return Jwts.parser().parseClaimsJwt(tokenWithoutSignature);
}
项目:RepositoryPattern    文件:JwtTokenHelper.java   
public static Map<String, Object> getTokenBody(String jwsToken) {
    String jwtToken = jwsToken.substring(0, jwsToken.lastIndexOf(".") + 1);
    Jwt<Header, Claims> untrusted = Jwts.parser().parseClaimsJwt(jwtToken);
    return untrusted.getBody();
}
项目:apiman-plugins    文件:ConfigCheckingJwtHandler.java   
@Override
public Map<String, Object> onClaimsJwt(@SuppressWarnings("rawtypes") Jwt<Header, Claims> jwt) {
    return config.getRequireSigned() ? super.onClaimsJwt(jwt) : jwt.getBody();
}
项目:jjwt    文件:DefaultJwt.java   
public DefaultJwt(Header header, B body) {
    this.header = header;
    this.body = body;
}
项目:jjwt    文件:DefaultJwt.java   
@Override
public Header getHeader() {
    return header;
}
项目:jjwt    文件:DefaultCompressionCodecResolver.java   
private String getAlgorithmFromHeader(Header header) {
    Assert.notNull(header, "header cannot be null.");

    return header.getCompressionAlgorithm();
}