• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SignatureVerifier类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getSignatureVerifier

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
@Override
public SignatureVerifier getSignatureVerifier() throws Exception {
    String publicKeyEndpointUri = getTokenEndpoint().replace("/token", "/certs");
    HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
    LinkedHashMap<String, List<Map<String, Object>>> result =
        restTemplate.getForObject(publicKeyEndpointUri, LinkedHashMap.class);
    Map<String, Object> properties = result.get("keys").get(0);
    BigInteger modulus = new BigInteger(1, Base64Utils.decodeFromUrlSafeString((String) properties.get("n")));
    BigInteger publicExponent = new BigInteger(1, Base64Utils.decodeFromString((String) properties.get("e")));
    try {
        PublicKey publicKey =
            KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
        RSAPublicKey rsaKey = (RSAPublicKey) RSAKeyFactory.toRSAKey(publicKey);
        return new RsaVerifier(rsaKey);
    } catch (GeneralSecurityException ex) {
        log.error("could not create key verifier", ex);
        throw ex;
    }
}
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:20,代码来源:_KeycloakSignatureVerifierClient.java


示例2: tryCreateSignatureVerifier

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
/**
 * Fetch a new public key from the AuthorizationServer.
 *
 * @return true, if we could fetch it; false, if we could not.
 */
private boolean tryCreateSignatureVerifier() {
    long t = System.currentTimeMillis();
    if (t - lastKeyFetchTimestamp < oAuth2Properties.getSignatureVerification().getPublicKeyRefreshRateLimit()) {
        return false;
    }
    try {
        SignatureVerifier verifier = signatureVerifierClient.getSignatureVerifier();
        if(verifier!=null) {
            setVerifier(verifier);
            lastKeyFetchTimestamp = t;
            log.debug("Public key retrieved from OAuth2 server to create SignatureVerifier");
            return true;
        }
    } catch (Throwable ex) {
        log.error("could not get public key from OAuth2 server to create SignatureVerifier", ex);
    }
    return false;
}
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:24,代码来源:_OAuth2JwtAccessTokenConverter.java


示例3: getSSOAuthentication

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
private OAuth2Authentication getSSOAuthentication(String accessToken) {
    try {
        SignatureVerifier verifier = isAssymetricKey(jwtSignKey) ? new RsaVerifier(jwtSignKey) : new MacSigner(jwtSignKey);
        Jwt jwt = JwtHelper.decodeAndVerify(accessToken, verifier);
        Map<String, Object> claims = objectMapper.readValue(jwt.getClaims(), new MapTypeReference());
        Object userClaim = claims.get("user");
        Map<String, Object> tokenMap = new HashMap<>();
        Map<String, Object> userMap = objectMapper.readValue(userClaim.toString(), new MapTypeReference());
        String exp = claims.get("exp").toString();
        tokenMap.put("exp", Long.valueOf(exp));
        Object email = userMap.get("email");
        tokenMap.put("user_id", email);
        tokenMap.put("user_name", email);
        tokenMap.put("scope", Arrays.asList("cloudbreak.networks.read", "periscope.cluster", "cloudbreak.usages.user", "cloudbreak.recipes", "openid",
            "cloudbreak.templates.read", "cloudbreak.usages.account", "cloudbreak.events", "cloudbreak.stacks.read",
            "cloudbreak.blueprints", "cloudbreak.networks", "cloudbreak.templates", "cloudbreak.credentials.read",
            "cloudbreak.securitygroups.read", "cloudbreak.securitygroups", "cloudbreak.stacks", "cloudbreak.credentials",
            "cloudbreak.recipes.read", "cloudbreak.blueprints.read"));

        OAuth2AccessToken oAuth2AccessToken = jwtAccessTokenConverter.extractAccessToken(accessToken, tokenMap);
        if (oAuth2AccessToken.isExpired()) {
            throw new InvalidTokenException("The token has expired");
        }
        OAuth2Authentication oAuth2Authentication = jwtAccessTokenConverter.extractAuthentication(tokenMap);
        if (oAuth2Authentication != null) {
            LOGGER.info("JWT token verified for: {}", oAuth2Authentication.getPrincipal());
        }
        return oAuth2Authentication;
    } catch (IOException e) {
        LOGGER.error("Failed to parse the JWT token", e);
        throw new InvalidTokenException("The specified JWT token is invalid", e);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:34,代码来源:CachedRemoteTokenService.java


示例4: getSignatureVerifier

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
/**
 * Fetches the public key from the UAA.
 *
 * @return the public key used to verify JWT tokens; or null.
 */
@Override
public SignatureVerifier getSignatureVerifier() throws Exception {
    try {
        HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
        String key = (String) restTemplate
            .exchange(getPublicKeyEndpoint(), HttpMethod.GET, request, Map.class).getBody()
            .get("value");
        return new RsaVerifier(key);
    } catch (IllegalStateException ex) {
        log.warn("could not contact UAA to get public key");
        return null;
    }
}
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:19,代码来源:_UaaSignatureVerifierClient.java


示例5: verifier

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
@Bean
public SignatureVerifier verifier() {
    return new MacSigner("non-prod");
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:5,代码来源:OAuth2ResourceServer.java


示例6: downloadKeys

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
private void downloadKeys(final String url) {
    Map<String, SignatureVerifier> tempVerifiers = new HashMap<>();
    ResponseEntity<Map> responseEntity = restTemplate.getForEntity(url, Map.class);
    Map response = responseEntity.getBody();

    for (Object key : response.keySet()) {
        String certificateString = (String)response.get(key);
        InputStream is = new ByteArrayInputStream(certificateString.getBytes(StandardCharsets.UTF_8));
        try {
            CertificateFactory f = CertificateFactory.getInstance("X.509");
            X509Certificate certificate = (X509Certificate)f.generateCertificate(is);
            PublicKey pk = certificate.getPublicKey();
            RsaVerifier verifier = new RsaVerifier((RSAPublicKey)pk);
            tempVerifiers.put((String)key, verifier);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (tempVerifiers.size() > 0) {
        // do we need to synchronize here?
        verifiers = tempVerifiers;
    }

    String cacheControlValue = responseEntity.getHeaders().getCacheControl();
    int maxAge = DEFAULT_MAX_AGE;
    if (cacheControlValue != null) {
        Matcher matcher = MAX_AGE_PATTERN.matcher(cacheControlValue);
        if (matcher.matches()) {
            maxAge = Integer.parseInt(matcher.group(1));
        }
    }

    // start timer to update keys
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            downloadKeys(url);
        }
    }, maxAge * 1000); // max-age is in seconds unit
}
 
开发者ID:AgeOfMobile,项目名称:spring-firebase-auth,代码行数:42,代码来源:FirebaseTokenConverter.java


示例7: decodeAndVerify

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
public static Jwt decodeAndVerify(String token, SignatureVerifier verifier) {
	Jwt jwt = decode(token);
	jwt.verifySignature(verifier);

	return jwt;
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:7,代码来源:JwtHelper.java


示例8: verifySignature

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
/**
 * Validates a signature contained in the 'crypto' segment.
 *
 * @param verifier the signature verifier
 */
public void verifySignature(SignatureVerifier verifier) {
	verifier.verify(signingInput(), crypto);
	}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:9,代码来源:JwtHelper.java


示例9: getSignatureVerifier

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
/**
 * Returns the SignatureVerifier used to verify JWT tokens.
 * Fetches the public key from the Authorization server to create
 * this verifier.
 *
 * @return the new verifier used to verify JWT signatures.
 * Will be null if we cannot contact the token endpoint.
 * @throws Exception if we could not create a SignatureVerifier or contact the token endpoint.
 */
SignatureVerifier getSignatureVerifier() throws Exception;
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:11,代码来源:_OAuth2SignatureVerifierClient.java


示例10: verifySignature

import org.springframework.security.jwt.crypto.sign.SignatureVerifier; //导入依赖的package包/类
void verifySignature(SignatureVerifier verifier); 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:2,代码来源:Jwt.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ElementKind类代码示例发布时间:2022-05-22
下一篇:
Java JoinPredecessor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap