Java Code Examples for io.jsonwebtoken.lang.Strings#hasText()
The following examples show how to use
io.jsonwebtoken.lang.Strings#hasText() .
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 |
@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: EllipticCurveProvider.java From jjwt with Apache License 2.0 | 6 votes |
/** * Generates a new secure-random key pair of sufficient strength for the specified Elliptic Curve {@link * SignatureAlgorithm} (must be one of {@code ES256}, {@code ES384} or {@code ES512}) using the specified {@link * SecureRandom} random number generator via the specified JCA provider and algorithm name. * * @param jcaAlgorithmName the JCA name of the algorithm to use for key pair generation, for example, {@code * ECDSA}. * @param jcaProviderName the JCA provider name of the algorithm implementation (for example {@code "BC"} for * BouncyCastle) or {@code null} if the default provider should be used. * @param alg alg the algorithm indicating strength, must be one of {@code ES256}, {@code ES384} or * {@code ES512} * @param random the SecureRandom generator to use during key generation. * @return a new secure-randomly generated key pair of sufficient strength for the specified Elliptic Curve {@link * SignatureAlgorithm} (must be one of {@code ES256}, {@code ES384} or {@code ES512}) using the specified {@link * SecureRandom} random number generator via the specified JCA provider and algorithm name. * @see #generateKeyPair() * @see #generateKeyPair(SignatureAlgorithm) * @see #generateKeyPair(SignatureAlgorithm, SecureRandom) */ public static KeyPair generateKeyPair(String jcaAlgorithmName, String jcaProviderName, SignatureAlgorithm alg, SecureRandom random) { Assert.notNull(alg, "SignatureAlgorithm argument cannot be null."); Assert.isTrue(alg.isEllipticCurve(), "SignatureAlgorithm argument must represent an Elliptic Curve algorithm."); try { KeyPairGenerator g; if (Strings.hasText(jcaProviderName)) { g = KeyPairGenerator.getInstance(jcaAlgorithmName, jcaProviderName); } else { g = KeyPairGenerator.getInstance(jcaAlgorithmName); } String paramSpecCurveName = EC_CURVE_NAMES.get(alg); ECGenParameterSpec spec = new ECGenParameterSpec(paramSpecCurveName); g.initialize(spec, random); return g.generateKeyPair(); } catch (Exception e) { throw new IllegalStateException("Unable to generate Elliptic Curve KeyPair: " + e.getMessage(), e); } }
Example 3
Source File: DefaultJwtBuilder.java From jjwt with Apache License 2.0 | 5 votes |
@Override public JwtBuilder setId(String jti) { if (Strings.hasText(jti)) { ensureClaims().setId(jti); } else { if (this.claims != null) { claims.setId(jti); } } return this; }
Example 4
Source File: DefaultHeader.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public String getCompressionAlgorithm() { String alg = getString(COMPRESSION_ALGORITHM); if (!Strings.hasText(alg)) { alg = getString(DEPRECATED_COMPRESSION_ALGORITHM); } return alg; }
Example 5
Source File: DefaultJwtBuilder.java From jjwt with Apache License 2.0 | 5 votes |
@Override public JwtBuilder setAudience(String aud) { if (Strings.hasText(aud)) { ensureClaims().setAudience(aud); } else { if (this.claims != null) { claims.setAudience(aud); } } return this; }
Example 6
Source File: DefaultJwtBuilder.java From jjwt with Apache License 2.0 | 5 votes |
@Override public JwtBuilder setSubject(String sub) { if (Strings.hasText(sub)) { ensureClaims().setSubject(sub); } else { if (this.claims != null) { claims.setSubject(sub); } } return this; }
Example 7
Source File: DefaultJwtBuilder.java From jjwt with Apache License 2.0 | 5 votes |
@Override public JwtBuilder setIssuer(String iss) { if (Strings.hasText(iss)) { ensureClaims().setIssuer(iss); } else { if (this.claims != null) { claims.setIssuer(iss); } } return this; }
Example 8
Source File: DefaultCompressionCodecResolver.java From jjwt with Apache License 2.0 | 5 votes |
@Override public CompressionCodec resolveCompressionCodec(Header header) { String cmpAlg = getAlgorithmFromHeader(header); final boolean hasCompressionAlgorithm = Strings.hasText(cmpAlg); if (!hasCompressionAlgorithm) { return null; } return byName(cmpAlg); }
Example 9
Source File: DefaultHeader.java From jjwt with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public String getCompressionAlgorithm() { String alg = getString(COMPRESSION_ALGORITHM); if (!Strings.hasText(alg)) { alg = getString(DEPRECATED_COMPRESSION_ALGORITHM); } return alg; }
Example 10
Source File: ShiroJwtVerifyingFilter.java From cassandra-reaper with Apache License 2.0 | 5 votes |
private static Optional<String> getJwtUser(ServletRequest req) { String jwt = WebUtils.toHttp(req).getHeader("Authorization"); if (null != jwt && jwt.startsWith("Bearer ")) { try { jwt = jwt.substring(jwt.indexOf(' ') + 1); Jws<Claims> claims = Jwts.parser().setSigningKey(ShiroJwtProvider.SIGNING_KEY).parseClaimsJws(jwt); String user = claims.getBody().getSubject(); return Strings.hasText(user) ? Optional.of(user) : Optional.empty(); } catch (JwtException | IllegalArgumentException e) { LOG.error("Failed validating JWT {} from {}", jwt, WebUtils.toHttp(req).getRemoteAddr()); LOG.debug("exception", e); } } return Optional.empty(); }
Example 11
Source File: ConfigJwkResolver.java From juiser with Apache License 2.0 | 5 votes |
private Resource getResource(JwkConfig jwk) { if (jwk.isEnabled()) { final String value = jwk.getResource(); if (Strings.hasText(value)) { try { return this.resourceLoader.getResource(value); } catch (Exception e) { String msg = "Unable to load juiser.header.jwt.key.resource [" + value + "]."; throw new IllegalArgumentException(msg, e); } } } return null; }
Example 12
Source File: StringClaimResolver.java From juiser with Apache License 2.0 | 5 votes |
@Override protected String toTypedValue(Object v, Claims claims) { String value = String.valueOf(v); if (!Strings.hasText(value) || "null".equalsIgnoreCase(value)) { illegal(claims); } return value; }
Example 13
Source File: JuiserSecurityAutoConfiguration.java From juiser with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(name = "juiserJwtDataExtractor") public Function<Claims, Collection<String>> juiserGrantedAuthoritiesClaimResolver() { final SpringSecurityJwtConfig jwt = forwardedHeaderConfig().getJwt(); String expression = jwt.getGrantedAuthoritiesExpression(); if (!Strings.hasText(expression)) { expression = "['user']['groups']['items'].![get('name')]"; } return new StringCollectionClaimResolver(new ClaimsExpressionEvaluator(expression), false); }
Example 14
Source File: DefaultJwtBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public JwtBuilder setId(String jti) { if (Strings.hasText(jti)) { ensureClaims().setId(jti); } else { if (this.claims != null) { claims.setId(jti); } } return this; }
Example 15
Source File: DefaultJwtBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public JwtBuilder setAudience(String aud) { if (Strings.hasText(aud)) { ensureClaims().setAudience(aud); } else { if (this.claims != null) { claims.setAudience(aud); } } return this; }
Example 16
Source File: DefaultJwtBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public JwtBuilder setSubject(String sub) { if (Strings.hasText(sub)) { ensureClaims().setSubject(sub); } else { if (this.claims != null) { claims.setSubject(sub); } } return this; }
Example 17
Source File: DefaultJwtBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public JwtBuilder setIssuer(String iss) { if (Strings.hasText(iss)) { ensureClaims().setIssuer(iss); } else { if (this.claims != null) { claims.setIssuer(iss); } } return this; }
Example 18
Source File: ForwardedUserFilter.java From juiser with Apache License 2.0 | 4 votes |
public boolean isEnabled(HttpServletRequest request) throws ServletException { String headerValue = request.getHeader(headerName); return Strings.hasText(headerValue); }