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


Java Claims.get方法代码示例

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


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

示例1: getConnUser

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public static RequestUserDTO getConnUser(HttpServletRequest request) {
    String token = request.getHeader(HEADER_STRING);
    if (token == null) {
        token = getTokenFromCookis(request);
    }
    if (token != null) {
        // 解析 Token
        Claims claims = Jwts.parser().setSigningKey(SECRET)
                .parseClaimsJws(token).getBody();

        return new RequestUserDTO(
                claims.get("DomainId", String.class),
                claims.get("UserId", String.class),
                claims.get("OrgUnitId", String.class));
    }
    return new RequestUserDTO();
}
 
开发者ID:hzwy23,项目名称:hauth-java,代码行数:18,代码来源:JwtService.java

示例2: authenticate

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
    final JwtToken token = (JwtToken) authentication.getCredentials();
    final Claims claims = jwt.validate(token);

    final String userId = claims.getSubject();
    final String email  = claims.get("mail", String.class);

    @SuppressWarnings("unchecked")
    final List<String> scopes = (List<String>) claims.get("scopes", List.class);
    final List<GrantedAuthority> auths = scopes.stream()
        .map(SimpleGrantedAuthority::new)
        .collect(Collectors.toList());

    final JwtUserDetails user = new JwtUserDetails(userId, email, auths);
    return new JwtAuthentication(token, user);
}
 
开发者ID:membaza,项目名称:users-service,代码行数:19,代码来源:JwtAuthenticationProvider.java

示例3: parseAndValidate

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public AuthTokenDetails parseAndValidate(String token) {
    AuthTokenDetails authTokenDetails = null;
    try {
        Claims claims = Jwts.parser().setSigningKey(getSecretKey())
                .parseClaimsJws(token)
                .getBody();
        String userId = claims.getSubject();
        String username = (String) claims.get("username");
        List<String> roleNames = (List) claims.get("roleNames");
        Date expirationDate = claims.getExpiration();

        authTokenDetails = new AuthTokenDetails();
        authTokenDetails.setId(Long.valueOf(userId));
        authTokenDetails.setUsername(username);
        authTokenDetails.setRoleNames(roleNames);
        authTokenDetails.setExpirationDate(expirationDate);
    } catch (JwtException ex) {
        logger.error(ex.getMessage(), ex);
    }
    return authTokenDetails;
}
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:22,代码来源:JsonWebTokenUtility.java

示例4: getPayload

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
 * Parses the token header into a payload data map
 *
 * @param tokenHeader Object holding the token
 * @return data map of the token parsed
 */
private Map<String, String> getPayload(String tokenHeader) {
	String tokenWithoutBearer = tokenHeader.replace(TOKEN_PREFIX, "");
	String tokenWithoutSignatureAndBearer = removeSignature(tokenWithoutBearer);
	Claims body = Jwts.parser()
			.parseClaimsJwt(tokenWithoutSignatureAndBearer)
			.getBody();
	return body.get("data", Map.class);
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:15,代码来源:JwtAuthorizationFilter.java

示例5: getAudienceFromToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public String getAudienceFromToken(String token) {
    String audience;
    try {
        final Claims claims = getClaimsFromToken(token);
        audience = (String) claims.get(CLAIM_KEY_AUDIENCE);
    } catch (Exception e) {
        audience = null;
    }
    return audience;
}
 
开发者ID:rodrigues882013,项目名称:springboot-rest-api-skeleton,代码行数:11,代码来源:JwtTokenUtil.java

示例6: login

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
@RequestMapping(value = "api/me", method = {RequestMethod.GET})
public User login(final HttpServletRequest request) throws ServletException {
  final Claims claims = (Claims) request.getAttribute("claims");
  final Integer userId = (Integer) claims.get("userId");

  return rbacService.getUserByUserId(userId.longValue());
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:8,代码来源:UserController.java

示例7: 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;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:31,代码来源:JwtTokenFactory.java

示例8: getLastPasswordResetDateFromTokenClaims

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
Date getLastPasswordResetDateFromTokenClaims(Claims claims) {
    Date lastPasswordResetDate;
    try {
        lastPasswordResetDate = new Date((Long) claims.get(CLAIM_KEY_LAST_PASSWORD_CHANGE_DATE));
    } catch (Exception e) {
        LOG.error("Failed to extract lastPasswordResetDate claim from token!", e);
        lastPasswordResetDate = null;
    }
    return lastPasswordResetDate;
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:11,代码来源:JwtUtils.java

示例9: getAudienceFromToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
 * @param token
 * @return
 */
public String getAudienceFromToken ( String token ) {
	String audience;
	try {
		final Claims claims = getClaimsFromToken( token );
		audience = ( String ) claims.get( CLAIM_KEY_AUDIENCE );
	} catch ( Exception e ) {
		audience = null;
	}
	return audience;
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:15,代码来源:JwtTokenUtil.java

示例10: getClaims

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
@Override
public Claims getClaims(String requestedPrincipal, String authToken) throws AuthenticationException, AuthorizationException {
    Claims claims;
    try {
        claims = jwtDecoder.decodeAndVerify(authToken);
        String principalIdFromToken = claims.get("usr", String.class);
        if (!Objects.equals(requestedPrincipal, principalIdFromToken)) {
            throw new AuthorizationException("User not authorized to perform action");
        }

        return claims;
    } catch (JWTVerificationException e) {
        throw new AuthenticationException("JWT Token not valid");
    }
}
 
开发者ID:julianghionoiu,项目名称:tdl-auth,代码行数:16,代码来源:JWTKMSAuthorizer.java

示例11: getUserIdFromToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
private String getUserIdFromToken(String token) {
    String userId;
    try {
        final Claims clamis=getClaimsFromToken(token);
        userId= (String) clamis.get(CLAIM_KEY_USER_ID);
    }catch (Exception e){
        userId=null;
    }
    return userId;
}
 
开发者ID:BENULL,项目名称:LushX,代码行数:11,代码来源:JWTUtils.java

示例12: doFilterInternal

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
	
	//CORS
	response.addHeader("Access-Control-Allow-Origin", "*");
	if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equalsIgnoreCase(request.getMethod())) {
		response.addHeader("Access-Control-Allow-Headers", "Authorization");
		response.addHeader("Access-Control-Allow-Headers", "Content-Type");
		response.addHeader("Access-Control-Max-Age", "1");
		response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
	}
	
	final String authHeader = request.getHeader(this.authHeader);
	
	String username;
	String authToken;
	
	if (authHeader != null && authHeader.startsWith("Bearer ")) {
		authToken = authHeader.substring(7);
		try {
			username = jwtTokenUtil.getUsernameFromToken(authToken);
		} catch (Exception e) {
			username = null;
			authToken = null;
		}
	} else {
		username = null;
		authToken = null;
	}
	
	if (username != null && authToken != null && SecurityContextHolder.getContext().getAuthentication() == null) {
		Claims claims = jwtTokenUtil.getAllClaimsFromToken(authToken);
		if (jwtTokenUtil.validateToken(authToken)) {
			List<String> rolesMap = claims.get("role", List.class);
			List<Role> roles = new ArrayList<>();
			for (String rolemap : rolesMap) {
				roles.add(Role.valueOf(rolemap));
			}
			UserDetails userDetails = new JWTUser(
				username, null, JWTUserFactory.mapToGrantedAuthorities(roles), claims.get("enable", Boolean.class)
			);
			UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
			authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
			SecurityContextHolder.getContext().setAuthentication(authentication);
		}
	}
	
	if (!request.getMethod().equalsIgnoreCase("OPTIONS")) {
		chain.doFilter(request, response);
	}
}
 
开发者ID:ard333,项目名称:spring-boot-jjwt,代码行数:52,代码来源:AuthenticationFilter.java


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