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

Java InvalidSignatureException类代码示例

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

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



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

示例1: authenticate

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication t)
        throws AuthenticationException {
    JWTToken jwtToken = (JWTToken) t;
    try {
    	String username = jwtToken.getClaims().getUsername();
    	String secret = usernameAuthBean.getUserSecret().get(username);
    	if (secret != null) {
    		MacSigner signer = new MacSigner(secret);
    		JwtHelper.decodeAndVerify(jwtToken.getToken(), signer);
    		jwtToken.setAuthenticated(Boolean.TRUE);
    		String role = usernameAuthBean.getUserRoles().get(username);
    		jwtToken.addRole(role);
    		
    	}
        
    } catch (InvalidSignatureException e) {
        return null;
    }
    return jwtToken;
}
 
开发者ID:fergarrui,项目名称:jwt-example,代码行数:22,代码来源:JwtAuthenticationProvider.java


示例2: verifyToken

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
/**
 * Verifies the specified token, refreshing the cached token verification key if needed.
 * 
 * @param tokenString
 */
protected void verifyToken(String tokenString) {
    try {
        verify(tokenString);
    } catch (InvalidSignatureException e) {
        refreshTokenKey();
        verify(tokenString);
    }
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:14,代码来源:CustomTokenServices.java


示例3: testLoadAuthenticationForInvalidPublicKey

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
@Test
public void testLoadAuthenticationForInvalidPublicKey() throws IOException {
    String publicKey = FileReaderUtils.readFileFromClasspath("invalid_token_key.pub");
    CachedRemoteTokenService tokenService = new CachedRemoteTokenService("clientId", "clientSecret", "http://localhost:8089", publicKey, identityClient);
    try {
        tokenService.loadAuthentication(token);
    } catch (InvalidSignatureException e) {
        Assert.assertEquals("RSA Signature did not match content", e.getMessage());
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:11,代码来源:CachedRemoteTokenServiceTest.java


示例4: testLoadAuthenticationForInvalidMacKeyUsed

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
@Test
public void testLoadAuthenticationForInvalidMacKeyUsed() throws IOException {
    CachedRemoteTokenService tokenService = new CachedRemoteTokenService("clientId", "clientSecret", "http://localhost:8089", "alma", identityClient);
    try {
        tokenService.loadAuthentication(token);
    } catch (InvalidSignatureException e) {
        Assert.assertEquals("Calculated signature did not match actual value", e.getMessage());
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:10,代码来源:CachedRemoteTokenServiceTest.java


示例5: testLoadAuthenticationForInvalidMacKey

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
@Test
public void testLoadAuthenticationForInvalidMacKey() throws IOException {
    String ssoToken = FileReaderUtils.readFileFromClasspath("sso_token_mac_signed.txt");
    CachedRemoteTokenService tokenService = new CachedRemoteTokenService("clientId", "clientSecret", "http://localhost:8089", "korte", identityClient);
    try {
        tokenService.loadAuthentication(ssoToken);
    } catch (InvalidSignatureException e) {
        Assert.assertEquals("Calculated signature did not match actual value", e.getMessage());
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:11,代码来源:CachedRemoteTokenServiceTest.java


示例6: decodeAndVerify

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
@Nullable
@Override
public BlueWebToken decodeAndVerify(@Nonnull final String idToken){

    final long now = System.currentTimeMillis();
    if(log.isTraceEnabled()){
        log.trace("Decoding token [" + idToken + "]");
    }
    try{

        Jwt jwt = JwtHelper.decode(idToken);
        // Get the key ID we need to use to verify the token
        String keyId = getKeyId(idToken);
        if("".equals(keyId.trim())){
            log.warn("Failed to retrieve key ID for token");
            return null;
        }
        BlueWebToken token = typeSecuredObjectMapper().readValue(
          jwt.getClaims(),
          BlueWebToken.class);
        // Get the key and verify the JWT signature
        RSAPublicKey key = rsaPublicKey(keyId, token.getAuthContextReference());
        jwt.verifySignature(new RsaVerifier(key));

        // Validate the nonce

        if(!nonceService.isValid(token.getNonce())){
            log.warn("Failed to validate nonce in token. This could be a replay attack.");
            return null;
        }
        if(!claimValidationService.validateAudience(token)){
            log.warn("Failed to validate audience in token. This could be a replay attack.");
            return null;
        }
        if(!claimValidationService.validateIssuer(token)){
            log.warn("Failed to validate issuer of token. This could be a replay attack.");
            return null;
        }
        if(!claimValidationService.validateNotBefore(token, now)){
            log.warn("Failed to validate notBefore time in token. This could be a replay attack. 'Now' milliseconds: " + now + "; 'NotBefore' milliseconds: " + token
              .getNotBefore()
              .toInstant()
              .toEpochMilli());
            return null;
        }
        if(!claimValidationService.validateExpiration(token, now)){
            log.warn("Failed to validate expiration time in token. This could be a replay attack. 'Now' milliseconds: " + now + "; 'Expiration' milliseconds: " + token
              .getExpiration()
              .toInstant()
              .toEpochMilli());
            return null;
        }

        return token;

    }catch(IOException | IllegalArgumentException | InvalidSignatureException x){
        log.warn("Failed to extract data from JWT token: " + x.getMessage(), x);
    }
    return null;
}
 
开发者ID:Xitikit,项目名称:xitikit-blue,代码行数:61,代码来源:SimpleB2CAuthenticationService.java


示例7: invalidHmacSignatureRaisesException

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
@Test(expected=InvalidSignatureException.class)
public void invalidHmacSignatureRaisesException() {
	JwtHelper.decode(JOE_HMAC_TOKEN).verifySignature(new MacSigner("differentkey".getBytes()));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:5,代码来源:JwtTests.java


示例8: invalidRsaSignatureRaisesException

import org.springframework.security.jwt.crypto.sign.InvalidSignatureException; //导入依赖的package包/类
@Test(expected = InvalidSignatureException.class)
public void invalidRsaSignatureRaisesException() {
	JwtHelper.decodeAndVerify(JOE_RSA_TOKEN, new RsaVerifier(N, D));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:5,代码来源:JwtTests.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java MediaWikiParserFactory类代码示例发布时间:2022-05-22
下一篇:
Java FMLLoadEvent类代码示例发布时间: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