本文整理汇总了Java中org.jose4j.lang.JoseException类的典型用法代码示例。如果您正苦于以下问题:Java JoseException类的具体用法?Java JoseException怎么用?Java JoseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JoseException类属于org.jose4j.lang包,在下文中一共展示了JoseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJWT
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Encrypt the otp to be send via mail
*/
@Override
public String createJWT(String userid, long ttlMillis) {
Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setKey(key);
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
jwe.setEncryptionMethodHeaderParameter(
ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
jwe.setPayload(userid + "&&" + ttlMillis);
try {
return jwe.getCompactSerialization();
} catch (JoseException e) {
xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
}
return null;
}
示例2: generateJWTAssertion
import org.jose4j.lang.JoseException; //导入依赖的package包/类
public static String generateJWTAssertion(String email, String privateKeyBase64,
float expiryInSeconds) {
PrivateKey privateKey = getPrivateKey(privateKeyBase64);
final JwtClaims claims = new JwtClaims();
claims.setSubject(email);
claims.setAudience("https://api.metamind.io/v1/oauth2/token");
claims.setExpirationTimeMinutesInTheFuture(expiryInSeconds / 60);
claims.setIssuedAtToNow();
// Generate the payload
final JsonWebSignature jws = new JsonWebSignature();
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
jws.setPayload(claims.toJson());
jws.setKeyIdHeaderValue(UUID.randomUUID().toString());
// Sign using the private key
jws.setKey(privateKey);
try {
return jws.getCompactSerialization();
} catch (JoseException e) {
return null;
}
}
示例3: createSignedTokenFromClaims
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Create a RSA256 signed token from given claims and RSA jwk.
*
* @param JwtClaims claims
* @param RsaJsonWebKey rsaJsonWebKey
* @return String
* @throws JoseException
*/
private String createSignedTokenFromClaims(JwtClaims claims, RsaJsonWebKey rsaJsonWebKey) throws JoseException {
// A JWT is a JWS and/or a JWE with JSON claims as the payload.
// In this example it is a JWS so we create a JsonWebSignature object.
JsonWebSignature jws = new JsonWebSignature();
// The payload of the JWS is JSON content of the JWT Claims
jws.setPayload(claims.toJson());
// The JWT is signed using the private key
jws.setKey(rsaJsonWebKey.getPrivateKey());
// Set the signature algorithm on the JWT/JWS that will integrity protect the claims
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
return jws.getCompactSerialization();
}
示例4: createUnsupportedSignedTokenFromClaims
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Create a RSA384 signed token from given claims and RSA jwk.
*
* @param JwtClaims claims
* @param RsaJsonWebKey rsaJsonWebKey
* @return String
* @throws JoseException
*/
private String createUnsupportedSignedTokenFromClaims(JwtClaims claims, RsaJsonWebKey rsaJsonWebKey) throws JoseException {
// A JWT is a JWS and/or a JWE with JSON claims as the payload.
// In this example it is a JWS so we create a JsonWebSignature object.
JsonWebSignature jws = new JsonWebSignature();
// The payload of the JWS is JSON content of the JWT Claims
jws.setPayload(claims.toJson());
// The JWT is signed using the private key
jws.setKey(rsaJsonWebKey.getPrivateKey());
// Set the signature algorithm on the JWT/JWS that will integrity protect the claims
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA384);
return jws.getCompactSerialization();
}
示例5: testMissingNBFCLaim
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Test proper signed token missing mandatory nbf claim.
* @throws JoseException
*/
@Test(expected=SSOException.class)
public void testMissingNBFCLaim() throws JoseException, SSOException {
RsaJsonWebKey jwk = this.generateRsaJwk();
JwtClaims claims = this.createMalformedClaims();
claims.setExpirationTimeMinutesInTheFuture(10);
claims.setIssuedAtToNow();
//claims.setNotBeforeMinutesInThePast(2);
String jwt = this.createSignedTokenFromClaims(claims, jwk);
final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
ssoFac.verify(jwt);
}
示例6: testFutureNBFCLaim
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Test proper signed token valid in an hour.
* @throws JoseException
*/
@Test(expected=SSOException.class)
public void testFutureNBFCLaim() throws JoseException, SSOException {
RsaJsonWebKey jwk = this.generateRsaJwk();
JwtClaims claims = this.createMalformedClaims();
NumericDate nbf = NumericDate.now();
nbf.addSeconds(3600);
claims.setExpirationTimeMinutesInTheFuture(10);
claims.setIssuedAtToNow();
claims.setNotBefore(nbf);
String jwt = this.createSignedTokenFromClaims(claims, jwk);
final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
ssoFac.verify(jwt);
}
示例7: testMissingIATCLaim
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Test proper signed token missing mandatory iat claim.
* @throws JoseException
*/
@Test(expected=SSOException.class)
public void testMissingIATCLaim() throws JoseException, SSOException {
RsaJsonWebKey jwk = this.generateRsaJwk();
JwtClaims claims = this.createMalformedClaims();
claims.setExpirationTimeMinutesInTheFuture(10);
//claims.setIssuedAtToNow();
claims.setNotBeforeMinutesInThePast(2);
String jwt = this.createSignedTokenFromClaims(claims, jwk);
final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
ssoFac.verify(jwt);
}
示例8: testMissingEXPCLaim
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Test proper signed token missing mandatory exp claim.
* @throws JoseException
*/
@Test(expected=SSOException.class)
public void testMissingEXPCLaim() throws JoseException, SSOException {
RsaJsonWebKey jwk = this.generateRsaJwk();
JwtClaims claims = this.createMalformedClaims();
//claims.setExpirationTimeMinutesInTheFuture(10);
claims.setIssuedAtToNow();
claims.setNotBeforeMinutesInThePast(2);
String jwt = this.createSignedTokenFromClaims(claims, jwk);
final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
ssoFac.verify(jwt);
}
示例9: testPastEXPCLaim
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Test proper signed token already expired.
* @throws JoseException
*/
@Test(expected=SSOException.class)
public void testPastEXPCLaim() throws JoseException, SSOException {
RsaJsonWebKey jwk = this.generateRsaJwk();
JwtClaims claims = this.createMalformedClaims();
NumericDate exp = NumericDate.now();
exp.addSeconds(-3600);
claims.setExpirationTime(exp);
claims.setIssuedAtToNow();
claims.setNotBeforeMinutesInThePast(2);
String jwt = this.createSignedTokenFromClaims(claims, jwk);
final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
ssoFac.verify(jwt);
}
示例10: encode
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Sign id token claim string.
*
* @param svc the service
* @param claims the claims
* @return the string
* @throws JoseException the jose exception
*/
public String encode(final OidcRegisteredService svc, final JwtClaims claims) throws JoseException {
try {
LOGGER.debug("Attempting to produce id token generated for service [{}]", svc);
final JsonWebSignature jws = new JsonWebSignature();
final String jsonClaims = claims.toJson();
jws.setPayload(jsonClaims);
LOGGER.debug("Generated claims to put into id token are [{}]", jsonClaims);
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.NONE);
jws.setAlgorithmConstraints(AlgorithmConstraints.NO_CONSTRAINTS);
String innerJwt = svc.isSignIdToken() ? signIdToken(svc, jws) : jws.getCompactSerialization();
if (svc.isEncryptIdToken() && StringUtils.isNotBlank(svc.getIdTokenEncryptionAlg())
&& StringUtils.isNotBlank(svc.getIdTokenEncryptionEncoding())) {
innerJwt = encryptIdToken(svc, jws, innerJwt);
}
return innerJwt;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
throw Throwables.propagate(e);
}
}
示例11: sign
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public String sign(final JwtClaims claims) {
try {
final RsaJsonWebKey aSigningKey = cachedDataProvider.getASigningKey();
final JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setKeyIdHeaderValue(aSigningKey.getKeyId());
jws.setKey(aSigningKey.getPrivateKey());
jws.setAlgorithmHeaderValue(aSigningKey.getAlgorithm());
jws.sign();
return jws.getCompactSerialization();
} catch (final JoseException e) {
throw new InternalServerErrorException(e);
}
}
示例12: generateToken
import org.jose4j.lang.JoseException; //导入依赖的package包/类
public String generateToken(String subject) {
final JwtClaims claims = new JwtClaims();
claims.setSubject(subject);
claims.setExpirationTimeMinutesInTheFuture(TOKEN_EXPIRATION_IN_MINUTES);
final JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setAlgorithmHeaderValue(HMAC_SHA256);
jws.setKey(new HmacKey(tokenSecret));
jws.setDoKeyValidation(false); //relaxes hmac key length restrictions
try {
return jws.getCompactSerialization();
} catch (JoseException e) {
throw new RuntimeException(e);
}
}
示例13: decryptJWT
import org.jose4j.lang.JoseException; //导入依赖的package包/类
/**
* Decrypt the otp received via mail
*/
@Override
public String decryptJWT(String token) {
JsonWebEncryption jwe = new JsonWebEncryption();
Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
jwe.setKey(key);
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
jwe.setEncryptionMethodHeaderParameter(
ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
try {
jwe.setCompactSerialization(token);
return jwe.getPayload();
} catch (JoseException e) {
xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
}
jwe.setKey(key);
return null;
}
示例14: extractX509Certificate
import org.jose4j.lang.JoseException; //导入依赖的package包/类
private JsonWebKeySet extractX509Certificate(String json) {
Map<String, String> certificates = parse(json, new TypeReference<Map<String, String>>() {});
ImmutableList.Builder<JsonWebKey> jwkBuilder = ImmutableList.builder();
X509Util x509Util = new X509Util();
for (Entry<String, String> entry : certificates.entrySet()) {
try {
String cert = entry.getValue().trim()
.replace(X509_CERT_PREFIX, "")
.replace(X509_CERT_SUFFIX, "");
X509Certificate x509Certificate = x509Util.fromBase64Der(cert);
PublicKey publicKey = x509Certificate.getPublicKey();
JsonWebKey jwk = toJsonWebKey(publicKey);
jwk.setKeyId(entry.getKey());
jwkBuilder.add(jwk);
} catch (JoseException exception) {
throw new UnauthenticatedException("Failed to parse public key", exception);
}
}
return new JsonWebKeySet(jwkBuilder.build());
}
示例15: testSomeDataCompressedElsewhere
import org.jose4j.lang.JoseException; //导入依赖的package包/类
public void testSomeDataCompressedElsewhere() throws JoseException
{
String s ="q1bKLC5WslLKKCkpKLaK0Y/Rz0wp0EutSMwtyEnVS87PVdLhUkqtKFCyMjQ2NTcyNTW3sACKJJamoGgqRujJL0o" +
"H6ckqyQSqKMmNLIsMCzWqsPAp8zM3cjINjHdNTPbQizd1BClKTC4CKjICMYtLk4BMp6LMxDylWi4A";
byte[] decoded = Base64Url.decode(s);
CompressionAlgorithm ca = new DeflateRFC1951CompressionAlgorithm();
byte[] decompress = ca.decompress(decoded);
String decompedString = StringUtil.newStringUtf8(decompress);
String expected = "{\"iss\":\"https:\\/\\/idp.example.com\",\n" +
"\"exp\":1357255788,\n" +
"\"aud\":\"https:\\/\\/sp.example.org\",\n" +
"\"jti\":\"tmYvYVU2x8LvN72B5Q_EacH._5A\",\n" +
"\"acr\":\"2\",\n" +
"\"sub\":\"Brian\"}\n";
assertEquals(expected, decompedString);
}