java decodetoken_Java DecodedJWT.getClaim方法代码示例

import com.auth0.jwt.interfaces.DecodedJWT; //导入方法依赖的package包/类

@Override

public Authentication authenticate(Authentication auth) throws AuthenticationException {

JWTAuthenticationToken authentication = (JWTAuthenticationToken) auth;

if(authentication.getCredentials() == null || !(authentication.getCredentials() instanceof String)) {

logger.error("Credentials not present");

return null;

}

String rawToken = (String) auth.getCredentials();

DecodedJWT token = JWTSecurityService.verify(jwtKey, rawToken);

Claim path = token.getClaim(JWTSecurityService.CLAIM_PATH);

authentication.setAuthenticated(true);

// TODO:AD This is super unfortunate, but not sure there is a better way when using JSP

if(StringUtils.contains(authentication.getRequestedPath(), "/WEB-INF/jsp/")) {

logger.warn("BYPASSING AUTH FOR WEB-INF page");

} else

if(!roughlyEqual(path.asString(), authentication.getRequestedPath())) {

throw new InsufficientAuthenticationException("Credentials not valid for path " + authentication

.getRequestedPath() + ". They are valid for " + path.asString());

}

List authorities = new ArrayList<>();

authorities.add(new SimpleGrantedAuthority("IS_AUTHENTICATED_FULLY"));

authorities.add(new SimpleGrantedAuthority("ROLE_TEMP"));

return new JWTAuthenticationToken(authorities, rawToken, authentication.getRequestedPath());

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值