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


Java JwtHelper.decodeAndVerify方法代码示例

本文整理汇总了Java中org.springframework.security.jwt.JwtHelper.decodeAndVerify方法的典型用法代码示例。如果您正苦于以下问题:Java JwtHelper.decodeAndVerify方法的具体用法?Java JwtHelper.decodeAndVerify怎么用?Java JwtHelper.decodeAndVerify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.jwt.JwtHelper的用法示例。


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

示例1: authenticate

import org.springframework.security.jwt.JwtHelper; //导入方法依赖的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: decode

import org.springframework.security.jwt.JwtHelper; //导入方法依赖的package包/类
protected Map<String, Object> decode(String token) {
	Jwt jwt = JwtHelper.decodeAndVerify(token, verifier);
	String content = jwt.getClaims();
	try {
		@SuppressWarnings("unchecked")
		Map<String, Object> map = objectMapper.readValue(content, Map.class);
		return map;
	}
	catch (Exception e) {
		throw new InvalidTokenException("Cannot convert access token to JSON", e);
	}
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:13,代码来源:JwtTokenEnhancer.java

示例3: rsaKeyCreatesValidRsaSignedTokens

import org.springframework.security.jwt.JwtHelper; //导入方法依赖的package包/类
@Test
public void rsaKeyCreatesValidRsaSignedTokens() throws Exception {
	String rsaKey = "-----BEGIN RSA PRIVATE KEY-----  \n"
			+ "MIIBywIBAAJhAOTeb4AZ+NwOtPh+ynIgGqa6UWNVe6JyJi+loPmPZdpHtzoqubnC \n"
			+ "wEs6JSiSZ3rButEAw8ymgLV6iBY02hdjsl3h5Z0NWaxx8dzMZfXe4EpfB04ISoqq\n"
			+ "hZCxchvuSDP4eQIDAQABAmEAqUuYsuuDWFRQrZgsbGsvC7G6zn3HLIy/jnM4NiJK\n"
			+ "t0JhWNeN9skGsR7bqb1Sak2uWqW8ZqnqgAC32gxFRYHTavJEk6LTaHWovwDEhPqc\n"
			+ "Zs+vXd6tZojJQ35chR/slUEBAjEA/sAd1oFLWb6PHkaz7r2NllwUBTvXL4VcMWTS\n"
			+ "pN+5cU41i9fsZcHw6yZEl+ZCicDxAjEA5f3R+Bj42htNI7eylebew1+sUnFv1xT8\n"
			+ "jlzxSzwVkoZo+vef7OD6OcFLeInAHzAJAjEAs6izolK+3ETa1CRSwz0lPHQlnmdM\n"
			+ "Y/QuR5tuPt6U/saEVuJpkn4LNRtg5qt6I4JRAjAgFRYTG7irBB/wmZFp47izXEc3\n"
			+ "gOdvA1hvq3tlWU5REDrYt24xpviA0fvrJpwMPbECMAKDKdiDi6Q4/iBkkzNMefA8\n"
			+ "7HX27b9LR33don/1u/yvzMUo+lrRdKAFJ+9GPE9XFA== \n" + "-----END RSA PRIVATE KEY----- ";
	tokenEnhancer.setSigningKey(rsaKey);
	OAuth2Authentication authentication = new OAuth2Authentication(createOAuth2Request("foo", null),
			userAuthentication);
	OAuth2AccessToken token = tokenEnhancer.enhance(new DefaultOAuth2AccessToken("FOO"), authentication);
	JwtHelper.decodeAndVerify(token.getValue(), new RsaVerifier(rsaKey));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:20,代码来源:JwtTokenEnhancerTests.java

示例4: decode

import org.springframework.security.jwt.JwtHelper; //导入方法依赖的package包/类
public UserJwtToken decode(String token) {
    try {
        Jwt jwt = JwtHelper.decodeAndVerify(token, verifier);
        String content = jwt.getClaims();
        return objectMapper.readValue(content, UserJwtToken.class);
    }
    catch (Exception e) {
        throw new IllegalArgumentException("Cannot decode access token from JSON", e);
    }
}
 
开发者ID:leon,项目名称:spring-oauth-social-microservice-starter,代码行数:11,代码来源:JwtService.java

示例5: getSSOAuthentication

import org.springframework.security.jwt.JwtHelper; //导入方法依赖的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

示例6: verify

import org.springframework.security.jwt.JwtHelper; //导入方法依赖的package包/类
private void verify(String tokenString) {
    if (configuration.areDummyTokensEnabled() && tokenString.equals(TokenUtil.DUMMY_TOKEN)) {
        return;
    }
    JwtHelper.decodeAndVerify(tokenString, getSignatureVerifier(getCachedTokenKey()));
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:7,代码来源:CustomTokenServices.java


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