use of org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService in project spring-authorization-server by spring-projects.
the class OAuth2ConfigurerUtils method getAuthorizationConsentService.
static <B extends HttpSecurityBuilder<B>> OAuth2AuthorizationConsentService getAuthorizationConsentService(B builder) {
OAuth2AuthorizationConsentService authorizationConsentService = builder.getSharedObject(OAuth2AuthorizationConsentService.class);
if (authorizationConsentService == null) {
authorizationConsentService = getOptionalBean(builder, OAuth2AuthorizationConsentService.class);
if (authorizationConsentService == null) {
authorizationConsentService = new InMemoryOAuth2AuthorizationConsentService();
}
builder.setSharedObject(OAuth2AuthorizationConsentService.class, authorizationConsentService);
}
return authorizationConsentService;
}
use of org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService in project oauth2-server by gw2auth.
the class ClientConsentServiceImpl method save.
// region OAuth2AuthorizationConsentService
@Override
@Transactional
public void save(OAuth2AuthorizationConsent authorizationConsent) {
if (!authorizationConsent.getScopes().containsAll(this.authorizationCodeParamAccessor.getRequestedScopes())) {
throw this.authorizationCodeParamAccessor.error(new OAuth2Error(OAuth2ErrorCodes.ACCESS_DENIED));
}
final long accountId = Long.parseLong(authorizationConsent.getPrincipalName());
final long clientRegistrationId = Long.parseLong(authorizationConsent.getRegisteredClientId());
try (LoggingContext log = log(accountId, clientRegistrationId, LogType.CONSENT)) {
ClientConsentEntity clientConsentEntity = this.clientConsentRepository.findByAccountIdAndClientRegistrationId(accountId, clientRegistrationId).orElseGet(() -> createAuthorizedClientEntity(accountId, clientRegistrationId)).withAdditionalScopes(authorizationConsent.getScopes());
clientConsentEntity = this.clientConsentRepository.save(clientConsentEntity);
log.log("Updated consented oauth2-scopes to [%s]", String.join(", ", clientConsentEntity.authorizedScopes()));
}
}
Aggregations