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


Java Algorithm类代码示例

本文整理汇总了Java中com.auth0.jwt.algorithms.Algorithm的典型用法代码示例。如果您正苦于以下问题:Java Algorithm类的具体用法?Java Algorithm怎么用?Java Algorithm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Algorithm类属于com.auth0.jwt.algorithms包,在下文中一共展示了Algorithm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verify

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
public void verify() throws IOException, CertificateException {

        PublicKey publicKey = loadPublicKey();
        
//        Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
//        cipher.init(Cipher.DECRYPT_MODE, publicKey);
//        byte[] encryptedbytes = cipher.doFinal(Base64.getUrlDecoder().decode(signatureStr.getBytes()));
//        String result = Base64.getUrlEncoder().encodeToString(encryptedbytes);
//        System.out.println("---------------------------------");
//        System.out.println(result);
//        System.out.println(parts[0] + parts[1]);
//        
//        System.out.println("---------------------------------");
        
        //TODO: possible decode without 3rd party library...
        JWTVerifier verifier = JWT.require(Algorithm.RSA256((RSAKey) publicKey)).withIssuer(issuer).build();
        DecodedJWT jwt = verifier.verify(token);
//        System.out.println("DecodedJWT");
//        System.out.println(jwt);
//        System.out.println("---------------------------------");
    }
 
开发者ID:yuhuachang,项目名称:spring-boot-oauth2-azuread,代码行数:22,代码来源:AzureAdJwtToken.java

示例2: testRiscJwtCreatorJtiNotProvidedButRequired

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testRiscJwtCreatorJtiNotProvidedButRequired() throws Exception {
    thrown.expect(Exception.class);
    thrown.expectMessage("Jti has not been set");

    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = RiscJwtCreator.build()
            .withNbf(nbf)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = RiscJWT.require(algorithm);
    JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:21,代码来源:RiscJwtCreatorTest.java

示例3: testExtendedJwtCreatorNonStandardClaimDateValue

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorNonStandardClaimDateValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ExtendedJwtCreator.build()
            .withNbf(nbf)
            .withPicture(PICTURE)
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .withNonStandardClaim("nonStandardClaim", new Date())
            .sign(algorithm);

    GoogleVerification verification = ExtendedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:22,代码来源:ExtendedJwtCreatorTest.java

示例4: testExtendedJwtCreatorNonStandardClaimStringValue

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorNonStandardClaimStringValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ExtendedJwtCreator.build()
            .withNbf(nbf)
            .withPicture(PICTURE)
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .withNonStandardClaim("nonStandardClaim", "nonStandardClaimValue")
            .sign(algorithm);

    GoogleVerification verification = ExtendedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:22,代码来源:ExtendedJwtCreatorTest.java

示例5: shouldFailTokenMissingUid

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void shouldFailTokenMissingUid() throws Exception {
    final String host = "http://test.com";
    final String token = JWT
            .create()
            .withClaim("name", "adminuser")
            .withClaim("url", host)
            .withArrayClaim("roles", new String[] {"role1", "role2", "role3"})
            .withIssuedAt(Date.from(LocalDateTime.now().toInstant(offset)))
            .withExpiresAt(Date.from(LocalDateTime.now().plusHours(2).toInstant(offset)))
            .sign(Algorithm.HMAC256("secret"));

    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
            .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getHeader("Authorization"))
            .thenReturn("Bearer " + token);

    synValve.start();
    synValve.invoke(request, response);

    verify(request).getHeader("Authorization");
    verify(response).sendError(401, "Token authentication failed.");
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:26,代码来源:SynValveTest.java

示例6: testScopedJwtCreatorInvalidIssuer

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testScopedJwtCreatorInvalidIssuer() throws Exception {
    thrown.expect(InvalidClaimException.class);
    thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ScopedJwtCreator.build()
            .withScope("scope")
            .withIssuer("invalid")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = ScopedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForScoped("scope", asList("issuer"), asList("audience"), 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:18,代码来源:ScopedJwtCreatorTest.java

示例7: testFbJwtCreatorNonStandardClaimDateValue

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testFbJwtCreatorNonStandardClaimDateValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = FbJwtCreator.build()
            .withExp(exp)
            .withIat(iat)
            .withUserId(USER_ID)
            .withAppId(APP_ID)
            .setIsNoneAlgorithmAllowed(true)
            .withNonStandardClaim("nonStandardClaim", new Date())
            .sign(algorithm);
    Verification verification = FbJWT.require(algorithm);
    JWT verifier = verification.createVerifierForFb(USER_ID, APP_ID).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:18,代码来源:FbJwtCreatorTest.java

示例8: testClaimsWithoutVerify

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testClaimsWithoutVerify() {
    token = JWT.create()
            .withArrayClaim("roles", new String[]{"Role1", "Role2"})
            .withClaim("uid", 1)
            .withClaim("name", "admin")
            .withClaim("url", "http://test.com")
            .withIssuedAt(Date.from(LocalDateTime.now().toInstant(offset)))
            .withExpiresAt(Date.from(LocalDateTime.now().plusHours(2).toInstant(offset)))
            .sign(Algorithm.none());
    final Verifier verifier = Verifier.create(token);
    assertEquals(1, verifier.getUid());
    assertEquals("admin", verifier.getName());
    assertEquals("http://test.com", verifier.getUrl());
    final List<String> roles = verifier.getRoles();
    assertEquals(2, roles.size());
    assertEquals("Role1", roles.get(0));
    assertEquals("Role2", roles.get(1));
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:20,代码来源:VerifierTest.java

示例9: testFbJwtCreatorNoneAlgorithmNotSpecifiedButStillNotAllowed

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testFbJwtCreatorNoneAlgorithmNotSpecifiedButStillNotAllowed() throws Exception {
    thrown.expect(IllegalAccessException.class);
    thrown.expectMessage("None algorithm isn't allowed");

    Algorithm algorithm = Algorithm.none();
    String token = FbJwtCreator.build()
            .withExp(exp)
            .withIat(iat)
            .withUserId(USER_ID)
            .withAppId(APP_ID)
            .sign(algorithm);
    Verification verification = FbJWT.require(algorithm);
    JWT verifier = verification.createVerifierForFb(USER_ID, APP_ID).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:17,代码来源:FbJwtCreatorTest.java

示例10: testGoogleJwtCreatorNonStandardClaimDate

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorNonStandardClaimDate() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = GoogleJwtCreator.build()
            .withPicture(PICTURE)
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .withNonStandardClaim("nonStandardClaim", new Date())
            .sign(algorithm);
    GoogleVerification verification = GoogleJWT.require(algorithm);
    JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:22,代码来源:GoogleJwtCreatorTest.java

示例11: testGoogleJwtCreatorInvalidPicture

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorInvalidPicture() throws Exception {
    thrown.expect(InvalidClaimException.class);
    thrown.expectMessage("The Claim 'picture' value doesn't match the required one.");

    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = GoogleJwtCreator.build()
            .withPicture("invalid")
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .sign(algorithm);

    GoogleVerification verification = GoogleJWT.require(algorithm);
    JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:23,代码来源:GoogleJwtCreatorTest.java

示例12: testExtendedJwtCreatorAllStandardClaimsMustBeRequired

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorAllStandardClaimsMustBeRequired() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ExtendedJwtCreator.build()
            .withNbf(nbf)  //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
            .withPicture(PICTURE)
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .sign(algorithm);
    GoogleVerification verification = ExtendedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:22,代码来源:ExtendedJwtCreatorTest.java

示例13: testExtendedJwtCreatorNoneAlgorithmNotAllowed

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorNoneAlgorithmNotAllowed() throws Exception {
    thrown.expect(IllegalAccessException.class);
    thrown.expectMessage("None algorithm isn't allowed");

    Algorithm algorithm = Algorithm.none();
    String token = ExtendedJwtCreator.build()
            .withNbf(nbf)
            .withPicture(PICTURE)
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .setIsNoneAlgorithmAllowed(false)
            .sign(algorithm);

    GoogleVerification verification = ExtendedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:25,代码来源:ExtendedJwtCreatorTest.java

示例14: testScopedJwtCreatorAllStandardClaimsMustBeRequired

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testScopedJwtCreatorAllStandardClaimsMustBeRequired() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ScopedJwtCreator.build()
            .withScope("scope")
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = ScopedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForScoped("scope", asList("issuer"), asList("audience"), 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:18,代码来源:ScopedJwtCreatorTest.java

示例15: testRiscJwtCreatorBase32Encoding

import com.auth0.jwt.algorithms.Algorithm; //导入依赖的package包/类
@Test
public void testRiscJwtCreatorBase32Encoding() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = RiscJwtCreator.build()
            .withJWTId(jti)
            .withNbf(nbf)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .signBase32Encoding(algorithm);
    Verification verification = RiscJWT.require(algorithm);
    JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode32Bytes(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:19,代码来源:RiscJwtCreatorTest.java


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