当前位置: 首页>>代码示例>>Java>>正文


Java JoseException类代码示例

本文整理汇总了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;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:20,代码来源:AuthenticationServiceImpl.java

示例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;
  }
}
 
开发者ID:MetaMind,项目名称:quickstart,代码行数:24,代码来源:AssertionGenerator.java

示例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();
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:26,代码来源:SSOFacadeTest.java

示例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();
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:26,代码来源:SSOFacadeTest.java

示例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);
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:20,代码来源:SSOFacadeTest.java

示例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);
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:23,代码来源:SSOFacadeTest.java

示例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);
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:20,代码来源:SSOFacadeTest.java

示例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);
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:20,代码来源:SSOFacadeTest.java

示例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);
 }
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:23,代码来源:SSOFacadeTest.java

示例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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:32,代码来源:OidcIdTokenSigningAndEncryptionService.java

示例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);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:20,代码来源:JcaCryptoOps.java

示例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);
    }
}
 
开发者ID:jtanza,项目名称:rufus,代码行数:18,代码来源:TokenGenerator.java

示例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;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:AuthenticationServiceImpl.java

示例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());
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:21,代码来源:DefaultJwksSupplier.java

示例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);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:19,代码来源:DeflateRFC1951CompressionAlgorithmTest.java


注:本文中的org.jose4j.lang.JoseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。