org.springframework.security.jwt.Jwt.getEncoded()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(291)

本文整理了Java中org.springframework.security.jwt.Jwt.getEncoded()方法的一些代码示例,展示了Jwt.getEncoded()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jwt.getEncoded()方法的具体详情如下:
包路径:org.springframework.security.jwt.Jwt
类名称:Jwt
方法名:getEncoded

Jwt.getEncoded介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-security-oauth

protected String encode(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
  String content;
  try {
    content = objectMapper.formatMap(tokenConverter.convertAccessToken(accessToken, authentication));
  }
  catch (Exception e) {
    throw new IllegalStateException("Cannot convert access token to JSON", e);
  }
  String token = JwtHelper.encode(content, signer).getEncoded();
  return token;
}

代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2

protected String encode(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
  String content;
  try {
    content = objectMapper.formatMap(tokenConverter.convertAccessToken(accessToken, authentication));
  }
  catch (Exception e) {
    throw new IllegalStateException("Cannot convert access token to JSON", e);
  }
  String token = JwtHelper.encode(content, signer).getEncoded();
  return token;
}

代码示例来源:origin: io.choerodon/choerodon-starter-feign-replay

@Override
public void apply(RequestTemplate template) {
  try {
    String token = null;
    if (SecurityContextHolder.getContext() != null
        && SecurityContextHolder.getContext().getAuthentication() != null
        && SecurityContextHolder.getContext().getAuthentication().getDetails() instanceof OAuth2AuthenticationDetails) {
      OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) SecurityContextHolder
          .getContext().getAuthentication().getDetails();
      if (details.getTokenType() != null && details.getTokenValue() != null) {
        token = details.getTokenType() + " " + details.getTokenValue();
      } else if (details.getDecodedDetails() instanceof CustomUserDetails) {
        token = OAUTH_TOKEN_PREFIX
            + JwtHelper.encode(OBJECT_MAPPER.writeValueAsString(details.getDecodedDetails()), signer).getEncoded();
      }
    }
    if (token == null) {
      token = OAUTH_TOKEN_PREFIX + JwtHelper.encode(OBJECT_MAPPER.writeValueAsString(defaultUserDetails), signer).getEncoded();
    }
    template.header(RequestVariableHolder.HEADER_JWT, token);
    setLabel(template);
  } catch (Exception e) {
    LOGGER.error("generate jwt token failed {}", e);
  }
}

代码示例来源:origin: com.hand.hap.cloud/hap-feign-replay-starter

@Override
public void apply(RequestTemplate template) {
  if (HystrixRequestContext.isCurrentThreadInitialized()) {
    String token = HystrixHeaderInterceptor.token.get();
    String label = HystrixHeaderInterceptor.label.get();
    if (token != null) {
      template.header(HystrixHeaderInterceptor.HEADER_TOKEN, token);
    }else {
      try {
        String jwtToken = "Bearer " + JwtHelper.encode(OBJECT_MAPPER.writeValueAsString(DEFAULT_USER), SIGNER).getEncoded();
        LOGGER.info("token {}",jwtToken);
        template.header(HystrixHeaderInterceptor.HEADER_TOKEN, jwtToken);
      } catch (IOException e) {
        LOGGER.info("error {}",e);
      }
    }
    if (label != null) {
      template.header(HystrixHeaderInterceptor.HEADER_LABEL, label);
    }
  }else {
    try {
      String jwtToken = "Bearer " + JwtHelper.encode(OBJECT_MAPPER.writeValueAsString(DEFAULT_USER), SIGNER).getEncoded();
      LOGGER.info("token {}",jwtToken);
      template.header(HystrixHeaderInterceptor.HEADER_TOKEN, jwtToken);
    } catch (IOException e) {
      LOGGER.info("error {}",e);
    }
  }
}

代码示例来源:origin: otto-de/edison-microservice

public String getBearerToken(final String scope) {
    final ZonedDateTime soon = ZonedDateTime.now().plusDays(365);
    final String jwtToken = "{\n" +
        "  \"aud\": [\n" +
        "    \"" + aud + "\"\n" +
        "  ],\n" +
        "  \"exp\": " + soon.toEpochSecond() + ",\n" +
        "  \"user_name\": \"3d44bbc24614e28edd094bc54ef0497809717af5\",\n" +
        "  \"jti\": \"3cee521d-96a7-4d82-b726-7e02355f3a55\",\n" +
        "  \"client_id\": \"fe0661e5a99e4d43bd3496cc6c58025f\",\n" +
        "  \"scope\": [\n" +
        "    \"" + scope + "\"\n" +
        "  ]\n" +
        "}";
    final RsaSigner rsaSigner = new RsaSigner((RSAPrivateKey) keyPair.getPrivate());
    final Jwt encode = JwtHelper.encode(jwtToken, rsaSigner);

    return "Bearer " + encode.getEncoded();
  }
}

相关文章