本文整理汇总了Java中org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails类的典型用法代码示例。如果您正苦于以下问题:Java OAuth2AuthenticationDetails类的具体用法?Java OAuth2AuthenticationDetails怎么用?Java OAuth2AuthenticationDetails使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuth2AuthenticationDetails类属于org.springframework.security.oauth2.provider.authentication包,在下文中一共展示了OAuth2AuthenticationDetails类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: oauth2ClientContext
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
new DefaultAccessTokenRequest());
Authentication principal = SecurityContextHolder.getContext()
.getAuthentication();
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
String token = oauthsDetails.getTokenValue();
context.setAccessToken(new DefaultOAuth2AccessToken(token));
}
}
return context;
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:19,代码来源:OAuth2RestOperationsConfiguration.java
示例2: extractCurrentToken
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
public static String extractCurrentToken() {
final OAuth2Authentication auth = getAuthentication();
if (auth == null) {
throw new IllegalStateException("Cannot get current authentication object");
}
if (auth.getDetails() == null) {
return null;
}
if (auth.getDetails() instanceof OAuth2AuthenticationDetails) {
return (OAuth2AuthenticationDetails.class.cast(auth.getDetails())).getTokenValue();
}
if (auth.getDetails() instanceof String) {
return String.valueOf(auth.getDetails());
}
return null;
}
示例3: getRemoteAddress
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Optional<String> getRemoteAddress() {
return getDetails().flatMap(details -> {
String address;
if (details instanceof OAuth2AuthenticationDetails) {
address = OAuth2AuthenticationDetails.class.cast(details).getRemoteAddress();
} else if (details instanceof WebAuthenticationDetails) {
address = WebAuthenticationDetails.class.cast(details).getRemoteAddress();
} else {
throw new IllegalStateException("Unsupported auth details type " + details.getClass());
}
return Optional.ofNullable(address);
});
}
示例4: getSessionId
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Optional<String> getSessionId() {
return getDetails().flatMap(details -> {
String sessionId;
if (details instanceof OAuth2AuthenticationDetails) {
sessionId = OAuth2AuthenticationDetails.class.cast(details).getSessionId();
} else if (details instanceof WebAuthenticationDetails) {
sessionId = WebAuthenticationDetails.class.cast(details).getSessionId();
} else {
throw new IllegalStateException("Unsupported auth details type " + details.getClass());
}
return Optional.ofNullable(sessionId);
});
}
示例5: getDetailsMap
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Optional<Map<String, Object>> getDetailsMap() {
return getDetails().flatMap(
details -> {
if (details instanceof OAuth2AuthenticationDetails) {
Object decodedDetails = OAuth2AuthenticationDetails.class.cast(
details).getDecodedDetails();
return Optional.ofNullable(Map.class.cast(decodedDetails));
} else if (details instanceof WebAuthenticationDetails) {
return Optional.empty();
} else {
throw new IllegalStateException("Unsupported auth details type "
+ details.getClass());
}
});
}
示例6: setUserTenantContext
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
private String setUserTenantContext(HttpServletRequest request) {
String tenant;
final OAuth2Authentication auth = getAuthentication();
if (auth == null) {
tenant = request.getHeader(HEADER_TENANT);
TenantContext.setCurrent(tenant);
} else {
Map<String, String> details = null;
if (auth.getDetails() != null) {
details = Map.class.cast(OAuth2AuthenticationDetails.class.cast(auth.getDetails())
.getDecodedDetails());
}
details = firstNonNull(details, new HashMap<>());
tenant = details.getOrDefault(AUTH_TENANT_KEY, "");
String xmUserKey = details.getOrDefault(AUTH_USER_KEY, "");
String userLogin = (String) auth.getPrincipal();
TenantContext.setCurrent(new TenantInfo(tenant, userLogin, xmUserKey));
}
return tenant;
}
示例7: fetch
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
public static EAccessToken fetch(OAuth2Authentication oAuth2Authentication, OAuth2AccessToken accessToken){
EAccessToken eAccessToken = new EAccessToken();
eAccessToken.setOpenUser(fetch(oAuth2Authentication));
Object details = oAuth2Authentication.getDetails();
if(details instanceof OAuth2AuthenticationDetails){
OAuth2AuthenticationDetails details1 = (OAuth2AuthenticationDetails) details;
eAccessToken.setRemoteAddress(details1.getRemoteAddress());
eAccessToken.setSessionId(details1.getSessionId());
}
eAccessToken.setTokenType(accessToken.getTokenType());
eAccessToken.setTokenValue(accessToken.getValue());
eAccessToken.setExpiresIn(accessToken.getExpiresIn());
if (accessToken.getRefreshToken() != null) {
eAccessToken.setRefreshToken(accessToken.getRefreshToken().getValue());
}
if (accessToken.getScope() != null) {
String scopes = Strings.join2("|", accessToken.getScope().toArray(new String[]{}));
eAccessToken.setScopes(scopes);
}
return eAccessToken;
}
示例8: getWebSocketHttpHeaders
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
@Override
public WebSocketHttpHeaders getWebSocketHttpHeaders(final WebSocketSession userAgentSession) {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
Principal principal = userAgentSession.getPrincipal();
if (principal != null && OAuth2Authentication.class.isAssignableFrom(principal.getClass())) {
OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) principal;
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails();
String accessToken = details.getTokenValue();
headers.put(HttpHeaders.AUTHORIZATION, Collections.singletonList("Bearer " + accessToken));
if(logger.isDebugEnabled()) {
logger.debug("Added Oauth2 bearer token authentication header for user " +
principal.getName() + " to web sockets http headers");
}
}
else {
if(logger.isDebugEnabled()) {
logger.debug("Skipped adding basic authentication header since user session principal is null");
}
}
return headers;
}
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:22,代码来源:OAuth2BearerPrincipalHeadersCallback.java
示例9: apply
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
@Override
public void apply(RequestTemplate template) {
if (!template.headers().containsKey(AUTH_HEADER)) {
AitLogger.debug(logger, "Trying to assign the authorization token to the request header");
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null && auth.getDetails() instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) auth.getDetails();
if (StringUtils.isEmpty(details.getTokenValue())) {
AitLogger.warn(logger, "Empty token value.");
} else {
template.header(AUTH_HEADER, String.format("%s %s", BEARER, details.getTokenValue()));
}
} else {
AitLogger.warn(logger, "Null or unknown authentication type object: {}", auth);
}
}
}
示例10: apply
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
@Override
public void apply(RequestTemplate template) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (template.headers().containsKey(AUTHORIZATION_HEADER)) {
log.warn("The Authorization token has been already set");
} else if (auth == null || !(auth instanceof OAuth2Authentication)) {
log.warn("Can not obtain existing token for request, if it is a non secured request, ignore.");
} else {
OAuth2Authentication auth2Authentication = (OAuth2Authentication) auth;
OAuth2AuthenticationDetails oAuth2AuthenticationDetails = (OAuth2AuthenticationDetails) auth2Authentication.getDetails();
log.debug("Constructing Header {} for Token {}", AUTHORIZATION_HEADER, oAuth2AuthenticationDetails.getTokenType());
template.header(AUTHORIZATION_HEADER, String.format("%s %s", oAuth2AuthenticationDetails.getTokenType(),
oAuth2AuthenticationDetails.getTokenValue()));
}
}
开发者ID:nextgearcapital,项目名称:feign-hystrix-oauth2-spring-boot-starter,代码行数:17,代码来源:OAuth2FeignRequestInterceptor.java
示例11: getUserInfo
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
@Override
public OpenIDConnectUserInfoDto getUserInfo(Principal principal) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
Optional<OAuth2AuthenticationDetails> oAuth2AuthenticationDetails = Optional.of(principal)
.filter(OAuth2Authentication.class::isInstance)
.map(OAuth2Authentication.class::cast)
.map(OAuth2Authentication::getDetails)
.filter(OAuth2AuthenticationDetails.class::isInstance)
.map(OAuth2AuthenticationDetails.class::cast);
final String tokenValue = oAuth2AuthenticationDetails.map(OAuth2AuthenticationDetails::getTokenValue).get();
final String tokenType = oAuth2AuthenticationDetails.map(OAuth2AuthenticationDetails::getTokenType).get();
final String userInfoUri = resourceServerProperties.getUserInfoUri();
headers.add("Authorization", tokenType + " " + tokenValue);
HttpEntity<?> httpEntity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
OpenIDConnectUserInfoDto userInfo = restTemplate
.exchange(userInfoUri, HttpMethod.GET, httpEntity, OpenIDConnectUserInfoDto.class).getBody();
return userInfo;
}
示例12: getUserDetailModelFromOAuth2Authentication
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
/**
* Map manually for prototype.
* <p>
* todo: add map configuration to dozer
*
* @param auth {@link Authentication}
* @param emailList {@link List} of {@link GitHubEmailDto}
* @return {@link UserDetailModel}
*/
public UserDetailModel getUserDetailModelFromOAuth2Authentication(final Authentication auth, final List<GitHubEmailDto> emailList) {
final UserDetailModel model = new UserDetailModel();
model.setUserName(auth.getName());
model.setAvatarUrl(this.getValueFromDetailsByString(auth, "avatar_url"));
model.setUserCompany(this.getValueFromDetailsByString(auth, "company"));
model.setUserLocation(this.getValueFromDetailsByString(auth, "location"));
// populate email
final String userEmail = Optional
.ofNullable(this.getValueFromDetailsByString(auth, "email"))
.orElse(emailList.stream().filter(GitHubEmailDto::isPrimary).findFirst().get().getEmail());
model.setUserEmail(userEmail);
// set ip from {@link OAuth2AuthenticationDetails}
model.setIp(((OAuth2AuthenticationDetails) auth.getDetails()).getRemoteAddress());
// default role: user
// todo: check against user of organisation "inspectit" and if organisation has user; set role to "admin" or "mod"
model.setRole("user");
return model;
}
示例13: logRequest
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
/**
* Method logs REST API method invocation
*/
protected void logRequest(ServletRequest request) {
if (log.isDebugEnabled()) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
String tokenValue = "";
if (authentication instanceof CubaAnonymousAuthenticationToken) {
tokenValue = "anonymous";
}
if (authentication.getDetails() instanceof OAuth2AuthenticationDetails){
tokenValue = ((OAuth2AuthenticationDetails) authentication.getDetails()).getTokenValue();
}
log.debug("REST API request [{}] {} {} {}",
tokenValue,
((HttpServletRequest) request).getMethod(),
getRequestURL((HttpServletRequest) request),
request.getRemoteAddr());
}
}
}
示例14: pingIdpSession
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
protected IdpSessionStatus pingIdpSession(Authentication authentication) {
if (authentication instanceof OAuth2Authentication) {
Object details = authentication.getDetails();
String accessTokenId = ((OAuth2AuthenticationDetails) details).getTokenValue();
OAuth2AccessToken accessToken = tokenStore.readAccessToken(accessTokenId);
if (accessToken == null) {
return IdpSessionStatus.UNSUPPORTED;
}
String idpSessionId = getIdpSessionId(accessToken);
if (idpSessionId == null) {
return IdpSessionStatus.UNSUPPORTED;
}
return pingIdpSessionServer(idpSessionId);
}
return IdpSessionStatus.UNSUPPORTED;
}
示例15: apply
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入依赖的package包/类
@Override
public void apply(HttpClientRequest<ByteBuf> request, Authentication auth) {
logger.info("OAuth2TokenStrategy called for auth: " + auth + " and request: " + request);
if (auth != null) {
if (auth instanceof OAuth2Authentication) {
Object details = auth.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
logger.info("OAuth2 authentication details found");
OAuth2AuthenticationDetails oauth = (OAuth2AuthenticationDetails) details;
String accessToken = oauth.getTokenValue();
String tokenType = oauth.getTokenType() == null ? "Bearer" : oauth.getTokenType();
request.withHeader("Authorization", tokenType + " " + accessToken);
} else {
logger.info("No OAuth2 authentication details found");
}
}
} else {
logger.warn("OAuth2TokenStrategy enabled, but inbound request does not contain a Spring Security Authentication context");
}
}