Search in sources :

Example 1 with OAuth2AuthorizationConsentService

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;
}
Also used : InMemoryOAuth2AuthorizationConsentService(org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationConsentService) OAuth2AuthorizationConsentService(org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService) InMemoryOAuth2AuthorizationConsentService(org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationConsentService)

Example 2 with OAuth2AuthorizationConsentService

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()));
    }
}
Also used : OAuth2Error(org.springframework.security.oauth2.core.OAuth2Error) ClientConsentEntity(com.gw2auth.oauth2.server.repository.client.consent.ClientConsentEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ClientConsentEntity (com.gw2auth.oauth2.server.repository.client.consent.ClientConsentEntity)1 OAuth2Error (org.springframework.security.oauth2.core.OAuth2Error)1 InMemoryOAuth2AuthorizationConsentService (org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationConsentService)1 OAuth2AuthorizationConsentService (org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService)1 Transactional (org.springframework.transaction.annotation.Transactional)1