本文整理汇总了Java中io.jsonwebtoken.Claims.getSubject方法的典型用法代码示例。如果您正苦于以下问题:Java Claims.getSubject方法的具体用法?Java Claims.getSubject怎么用?Java Claims.getSubject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.jsonwebtoken.Claims
的用法示例。
在下文中一共展示了Claims.getSubject方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthentication
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public Authentication getAuthentication(String token) {
Claims claims = Jwts.parser()
.setSigningKey(secretKey)
.parseClaimsJws(token)
.getBody();
Collection<? extends GrantedAuthority> authorities = Arrays.stream(claims.get(AUTHORITIES_KEY)
.toString()
.split(","))
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
User principal = new User(claims.getSubject(), "", authorities);
return new UsernamePasswordAuthenticationToken(principal, token, authorities);
}
示例2: parseRefreshToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public SecurityUser parseRefreshToken(RawAccessJwtToken rawAccessToken) {
Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
Claims claims = jwsClaims.getBody();
String subject = claims.getSubject();
List<String> scopes = claims.get(SCOPES, List.class);
if (scopes == null || scopes.isEmpty()) {
throw new IllegalArgumentException("Refresh Token doesn't have any scopes");
}
if (!scopes.get(0).equals(Authority.REFRESH_TOKEN.name())) {
throw new IllegalArgumentException("Invalid Refresh Token scope");
}
boolean isPublic = claims.get(IS_PUBLIC, Boolean.class);
UserPrincipal principal = new UserPrincipal(isPublic ? UserPrincipal.Type.PUBLIC_ID : UserPrincipal.Type.USER_NAME,
subject);
SecurityUser securityUser = new SecurityUser(new UserId(UUID.fromString(claims.get(USER_ID, String.class))));
securityUser.setUserPrincipal(principal);
return securityUser;
}
示例3: getAuthentication
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public Authentication getAuthentication(String token) {
Claims claims = Jwts.parser()
.setSigningKey(secretKey)
.parseClaimsJws(token)
.getBody();
Collection<? extends GrantedAuthority> authorities =
Arrays.asList(claims.get(AUTHORITIES_KEY).toString().split(",")).stream()
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
User principal = new User(claims.getSubject(), "",
authorities);
return new UsernamePasswordAuthenticationToken(principal, "", authorities);
}
示例4: getUserFromToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public JWTUserDetails getUserFromToken(String token){
JWTUserDetails user;
try {
final Claims claims=getClaimsFromToken(token);
String userId = getUserIdFromToken(token);
String username=claims.getSubject();
List<GrantedAuthority> authorities =AuthorityUtils.commaSeparatedStringToAuthorityList((String) claims.get(CLAIM_KEY_AUTHORITIES));
/* boolean account_enabled = (Boolean) claims.get(CLAIM_KEY_ACCOUNT_ENABLED);
boolean account_non_locked = (Boolean) claims.get(CLAIM_KEY_ACCOUNT_NON_LOCKED);
boolean account_non_expired = (Boolean) claims.get(CLAIM_KEY_ACCOUNT_NON_EXPIRED);*/
user = new JWTUserDetails(userId, username, "password", authorities);
}catch (Exception e){
logger.error("getUserFromToken error");
user=null;
}
return user;
}
示例5: parseAccessJwtToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public SecurityUser parseAccessJwtToken(RawAccessJwtToken rawAccessToken) {
Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey());
Claims claims = jwsClaims.getBody();
String subject = claims.getSubject();
List<String> scopes = claims.get(SCOPES, List.class);
if (scopes == null || scopes.isEmpty()) {
throw new IllegalArgumentException("JWT Token doesn't have any scopes");
}
SecurityUser securityUser = new SecurityUser(new UserId(UUID.fromString(claims.get(USER_ID, String.class))));
securityUser.setEmail(subject);
securityUser.setAuthority(Authority.parse(scopes.get(0)));
securityUser.setFirstName(claims.get(FIRST_NAME, String.class));
securityUser.setLastName(claims.get(LAST_NAME, String.class));
securityUser.setEnabled(claims.get(ENABLED, Boolean.class));
boolean isPublic = claims.get(IS_PUBLIC, Boolean.class);
UserPrincipal principal = new UserPrincipal(isPublic ? UserPrincipal.Type.PUBLIC_ID : UserPrincipal.Type.USER_NAME,
subject);
securityUser.setUserPrincipal(principal);
String tenantId = claims.get(TENANT_ID, String.class);
if (tenantId != null) {
securityUser.setTenantId(new TenantId(UUID.fromString(tenantId)));
}
String customerId = claims.get(CUSTOMER_ID, String.class);
if (customerId != null) {
securityUser.setCustomerId(new CustomerId(UUID.fromString(customerId)));
}
return securityUser;
}
示例6: getUsernameFromToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
* Obtém o username (email) contido no token JWT.
*
* @param token
* @return String
*/
public String getUsernameFromToken(String token) {
String username;
try {
Claims claims = getClaimsFromToken(token);
username = claims.getSubject();
} catch (Exception e) {
username = null;
}
return username;
}
示例7: getUsernameFromToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public String getUsernameFromToken(String token) {
String username;
try {
final Claims claims = getClaimsFromToken(token);
username = claims.getSubject();
} catch (Exception e) {
username = null;
}
return username;
}
示例8: getUsernameFromToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
* 根据token得到用户名
*
* @param token
* @return
*/
public String getUsernameFromToken ( String token ) {
String username;
try {
final Claims claims = getClaimsFromToken( token );
username = claims.getSubject();
} catch ( Exception e ) {
username = null;
}
return username;
}
示例9: getAuthentication
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
static Authentication getAuthentication(HttpServletRequest request) {
// 从Header中拿到token
String token = request.getHeader(HEADER_STRING);
if (token != null) {
try {
// 解析 Token
Claims claims = Jwts.parser()
// 验签
.setSigningKey(SECRET)
// 去掉 Bearer
.parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
.getBody();
// 拿用户名
String user = claims.getSubject();
// 得到 权限(角色)
List<GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList((String) claims.get("authorities"));
// 返回验证令牌
return user != null ?
new UsernamePasswordAuthenticationToken(user, null, authorities) :
null;
} catch (Exception e) {
return null;
}
}
return null;
}
示例10: getUsernameFromToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public String getUsernameFromToken(String token) {
String username;
try {
final Claims clamis=getClaimsFromToken(token);
username=clamis.getSubject();
}catch (Exception e){
username=null;
}
return username;
}
示例11: isAdmin
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
* Checks if use is an admin
*
* @param token the JWT given
* @return true if admin exists, false otherwise
*/
public static boolean isAdmin(String token) {
Claims claims = null;
UserDaoImpl ud = new UserDaoImpl();
User user = null;
String cUsername = null;
boolean verified = false;
if(token == null) {
return false;
}
try {
claims = Jwts.parser()
.setSigningKey(getSecret())
.parseClaimsJws(token).getBody();
cUsername = claims.getSubject();
user = ud.getUserByUsername(cUsername);
if(cUsername == null || user == null || user.getRoleFlag() != 2) {
return false;
}
verified = true;
}catch(SignatureException se) {
se.printStackTrace();
}
return verified;
}
示例12: getAuthentication
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public Authentication getAuthentication(String token) {
Claims claims = Jwts.parser()
.setSigningKey(secretKey)
.parseClaimsJws(token)
.getBody();
Collection<? extends GrantedAuthority> authorities =
Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(","))
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
User principal = new User(claims.getSubject(), "", authorities);
return new UsernamePasswordAuthenticationToken(principal, "", authorities);
// Claims claims = Jwts.parser()
// .setSigningKey(secretKey)
// .parseClaimsJws(token)
// .getBody();
//
// String principal = claims.getSubject();
//
// // CHANGES START HERE
// String roles = claims.get(AUTHORITIES_KEY, Map.class).get("roles").toString();
// if(roles != null && roles.length() > 0) {
// roles = roles.substring(1, roles.length() - 1);
// }
//
// Collection<? extends GrantedAuthority> authorities =
// Arrays.asList(roles.split(",")).stream()
// .map(authority -> new SimpleGrantedAuthority("ROLE_" + authority.toUpperCase()))
// .collect(Collectors.toList());
//
// return new UsernamePasswordAuthenticationToken(principal, token, authorities);
}
示例13: getUsernameFromToken
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
* 从token中获取username信息
* @param token token
* @return
*/
public String getUsernameFromToken(String token) {
String username;
try {
final Claims claims = this.getClaimsFromToken(token);
username = claims.getSubject();
} catch (Exception e) {
username = null;
}
return username;
}
示例14: decodeCookie
import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
@Override
protected String[] decodeCookie(String cookieValue) throws InvalidCookieException {
try {
Claims claims = Jwts.parser()
.setSigningKey(getKey())
.parseClaimsJws(cookieValue)
.getBody();
return new String[] { claims.getId(), claims.getSubject() };
} catch (JwtException e) {
LOGGER.warn(e.getMessage());
throw new InvalidCookieException(e.getMessage());
}
}
开发者ID:springuni,项目名称:springuni-particles,代码行数:15,代码来源:PersistentJwtTokenBasedRememberMeServices.java