use of org.springframework.security.oauth2.provider.ClientDetails in project fw-cloud-framework by liuweijw.
the class AjaxLoginSuccessHandler method onAuthenticationSuccess.
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
String header = request.getHeader(SecurityConstant.AUTHORIZATION);
if (StringHelper.isBlank(header) || !header.startsWith(SecurityConstant.BASIC)) {
throw new UnapprovedClientAuthenticationException("请求头中client信息为空");
}
try {
String[] tokens = extractAndDecodeHeader(header);
assert tokens.length == 2;
String clientId = tokens[0];
String clientSecret = tokens[1];
JSONObject params = new JSONObject();
params.put("clientId", clientId);
params.put("clientSecret", clientSecret);
params.put("authentication", authentication);
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);
TokenRequest tokenRequest = new TokenRequest(MapUtil.newHashMap(), clientId, clientDetails.getScope(), "mobile");
OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails);
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication);
OAuth2AccessToken oAuth2AccessToken = authorizationServerTokenServices.createAccessToken(oAuth2Authentication);
response.setCharacterEncoding(CommonConstant.UTF8);
response.setContentType(CommonConstant.CONTENT_TYPE);
PrintWriter printWriter = response.getWriter();
printWriter.append(objectMapper.writeValueAsString(oAuth2AccessToken));
} catch (IOException e) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
}
use of org.springframework.security.oauth2.provider.ClientDetails in project irida by phac-nml.
the class IridaWebSecurityConfig method tokenServices.
@Bean
@Primary
public ResourceServerTokenServices tokenServices(@Qualifier("clientDetails") ClientDetailsService clientDetails, @Qualifier("iridaTokenStore") TokenStore tokenStore) {
DefaultTokenServices services = new DefaultTokenServices();
services.setTokenStore(tokenStore);
services.setSupportRefreshToken(true);
services.setClientDetailsService(clientDetails);
return services;
}
use of org.springframework.security.oauth2.provider.ClientDetails in project irida by phac-nml.
the class UserRevListener method setClientId.
/**
* Add the OAuth2 client ID to the revision listener if the user is
* connecting via OAuth2
*
* @param entity
* The revision entity to modify if necessary
*/
private void setClientId(UserRevEntity entity) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
// OAuth2Authentication
if (auth instanceof OAuth2Authentication) {
try {
logger.trace("Found OAuth2Authentication in session. Storing clientId in revision.");
OAuth2Authentication oAuth = (OAuth2Authentication) auth;
String clientId = oAuth.getOAuth2Request().getClientId();
IridaClientDetails clientDetails = clientRepo.loadClientDetailsByClientId(clientId);
entity.setClientId(clientDetails.getId());
} catch (NullPointerException ex) {
throw new IllegalStateException("The OAuth2 client details are not in the session so it cannot be added to the revision.");
}
}
}
use of org.springframework.security.oauth2.provider.ClientDetails in project seldon-core by SeldonIO.
the class ClientBuilder method build.
public ClientDetails build() {
BaseClientDetails result = new BaseClientDetails();
result.setClientId(clientId);
result.setAuthorizedGrantTypes(authorizedGrantTypes);
result.setAccessTokenValiditySeconds(accessTokenValiditySeconds);
result.setRefreshTokenValiditySeconds(refreshTokenValiditySeconds);
result.setRegisteredRedirectUri(registeredRedirectUris);
result.setClientSecret(secret);
result.setScope(scopes);
result.setAuthorities(AuthorityUtils.createAuthorityList(authorities.toArray(new String[authorities.size()])));
result.setResourceIds(resourceIds);
result.setAdditionalInformation(additionalInformation);
if (autoApprove) {
result.setAutoApproveScopes(scopes);
} else {
result.setAutoApproveScopes(autoApproveScopes);
}
return result;
}
use of org.springframework.security.oauth2.provider.ClientDetails in project dhis2-core by dhis2.
the class DefaultClientDetailsUserDetailsService method loadUserByUsername.
public UserDetails loadUserByUsername(String username) {
ClientDetails clientDetails;
try {
clientDetails = clientDetailsService.loadClientByClientId(username);
} catch (NoSuchClientException e) {
throw new UsernameNotFoundException(e.getMessage(), e);
}
String clientSecret = clientDetails.getClientSecret();
if (clientSecret == null || clientSecret.trim().length() == 0) {
clientSecret = emptyPassword;
}
return new User(username, clientSecret, clientDetails.getAuthorities());
}
Aggregations