io.jsonwebtoken.Header Java Examples

The following examples show how to use io.jsonwebtoken.Header. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultCompressionCodecResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 + "'");
}
 
Example #2
Source File: DefaultJwtParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
        }
    });
}
 
Example #3
Source File: DefaultJwtParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: DefaultJwtBuilder.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@Override
public JwtBuilder setHeaderParams(Map<String, Object> params) {
    if (!Collections.isEmpty(params)) {

        Header header = ensureHeader();

        for (Map.Entry<String, Object> entry : params.entrySet()) {
            header.put(entry.getKey(), entry.getValue());
        }
    }
    return this;
}
 
Example #5
Source File: ConfigCheckingJwtHandler.java    From apiman-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> onPlaintextJwt(@SuppressWarnings("rawtypes") Jwt<Header, String> jwt) {
    if (config.getRequireSigned()) {
        super.onPlaintextJwt(jwt);
    }
    return Collections.emptyMap();
}
 
Example #6
Source File: DefaultCompressionCodecResolver.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@Override
public CompressionCodec resolveCompressionCodec(Header header) {
    String cmpAlg = getAlgorithmFromHeader(header);

    final boolean hasCompressionAlgorithm = Strings.hasText(cmpAlg);

    if (!hasCompressionAlgorithm) {
        return null;
    }
    return byName(cmpAlg);
}
 
Example #7
Source File: DefaultJwtParser.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #8
Source File: DefaultJwtParser.java    From jjwt with Apache License 2.0 5 votes vote down vote up
@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;
        }
    });
}
 
Example #9
Source File: ImmutableJwtParser.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public Jwt<Header, Claims> parseClaimsJwt(String claimsJwt) throws ExpiredJwtException, UnsupportedJwtException, MalformedJwtException, SignatureException, IllegalArgumentException {
    return this.jwtParser.parseClaimsJwt(claimsJwt);
}
 
Example #10
Source File: DefaultJwtBuilder.java    From jjwt with Apache License 2.0 4 votes vote down vote up
protected Header ensureHeader() {
    if (this.header == null) {
        this.header = new DefaultHeader();
    }
    return this.header;
}
 
Example #11
Source File: DefaultJwtBuilder.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public JwtBuilder setHeader(Header header) {
    this.header = header;
    return this;
}
 
Example #12
Source File: DefaultCompressionCodecResolver.java    From jjwt with Apache License 2.0 4 votes vote down vote up
private String getAlgorithmFromHeader(Header header) {
    Assert.notNull(header, "header cannot be null.");

    return header.getCompressionAlgorithm();
}
 
Example #13
Source File: DefaultJwt.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public Header getHeader() {
    return header;
}
 
Example #14
Source File: DefaultJwt.java    From jjwt with Apache License 2.0 4 votes vote down vote up
public DefaultJwt(Header header, B body) {
    this.header = header;
    this.body = body;
}
 
Example #15
Source File: DefaultJwt.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public DefaultJwt(Header header, B body) {
    this.header = header;
    this.body = body;
}
 
Example #16
Source File: ImmutableJwtParser.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public Jwt<Header, String> parsePlaintextJwt(String plaintextJwt) throws UnsupportedJwtException, MalformedJwtException, SignatureException, IllegalArgumentException {
    return this.jwtParser.parsePlaintextJwt(plaintextJwt);
}
 
Example #17
Source File: ConfigCheckingJwtHandler.java    From apiman-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> onClaimsJwt(@SuppressWarnings("rawtypes") Jwt<Header, Claims> jwt) {
    return config.getRequireSigned() ? super.onClaimsJwt(jwt) : jwt.getBody();
}
 
Example #18
Source File: DefaultCompressionCodecResolver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String getAlgorithmFromHeader(Header header) {
    Assert.notNull(header, "header cannot be null.");

    return header.getCompressionAlgorithm();
}
 
Example #19
Source File: DefaultJwt.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Header getHeader() {
    return header;
}