本文整理了Java中org.springframework.security.jwt.Jwt.getEncoded()
方法的一些代码示例,展示了Jwt.getEncoded()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jwt.getEncoded()
方法的具体详情如下:
包路径:org.springframework.security.jwt.Jwt
类名称: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();
}
}
内容来源于网络,如有侵权,请联系作者删除!