spring-authorization-server OAuth2AuthorizationConsentAuthenticationContext 源码

  • 2022-08-16
  • 浏览 (513)

spring-authorization-server OAuth2AuthorizationConsentAuthenticationContext 代码

文件路径:/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2AuthorizationConsentAuthenticationContext.java

/*
 * Copyright 2020-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.security.oauth2.server.authorization.authentication;

import java.util.Map;

import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsent;
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
import org.springframework.util.Assert;

/**
 * An {@link OAuth2AuthenticationContext} that holds an {@link OAuth2AuthorizationConsent.Builder} and additional information
 * and is used when customizing the building of the {@link OAuth2AuthorizationConsent}.
 *
 * @author Steve Riesenberg
 * @author Joe Grandja
 * @since 0.2.1
 * @see OAuth2AuthenticationContext
 * @see OAuth2AuthorizationConsent
 */
public final class OAuth2AuthorizationConsentAuthenticationContext extends OAuth2AuthenticationContext {

	private OAuth2AuthorizationConsentAuthenticationContext(Map<Object, Object> context) {
		super(context);
	}

	/**
	 * Returns the {@link OAuth2AuthorizationConsent.Builder authorization consent builder}.
	 *
	 * @return the {@link OAuth2AuthorizationConsent.Builder}
	 */
	public OAuth2AuthorizationConsent.Builder getAuthorizationConsent() {
		return get(OAuth2AuthorizationConsent.Builder.class);
	}

	/**
	 * Returns the {@link RegisteredClient registered client}.
	 *
	 * @return the {@link RegisteredClient}
	 */
	public RegisteredClient getRegisteredClient() {
		return get(RegisteredClient.class);
	}

	/**
	 * Returns the {@link OAuth2Authorization authorization}.
	 *
	 * @return the {@link OAuth2Authorization}
	 */
	public OAuth2Authorization getAuthorization() {
		return get(OAuth2Authorization.class);
	}

	/**
	 * Returns the {@link OAuth2AuthorizationRequest authorization request}.
	 *
	 * @return the {@link OAuth2AuthorizationRequest}
	 */
	public OAuth2AuthorizationRequest getAuthorizationRequest() {
		return get(OAuth2AuthorizationRequest.class);
	}

	/**
	 * Constructs a new {@link Builder} with the provided {@link OAuth2AuthorizationCodeRequestAuthenticationToken}.
	 *
	 * @param authentication the {@link OAuth2AuthorizationCodeRequestAuthenticationToken}
	 * @return the {@link Builder}
	 */
	public static Builder with(OAuth2AuthorizationCodeRequestAuthenticationToken authentication) {
		return new Builder(authentication);
	}

	/**
	 * A builder for {@link OAuth2AuthorizationConsentAuthenticationContext}.
	 */
	public static final class Builder extends AbstractBuilder<OAuth2AuthorizationConsentAuthenticationContext, Builder> {

		private Builder(OAuth2AuthorizationCodeRequestAuthenticationToken authentication) {
			super(authentication);
		}

		/**
		 * Sets the {@link OAuth2AuthorizationConsent.Builder authorization consent builder}.
		 *
		 * @param authorizationConsent the {@link OAuth2AuthorizationConsent.Builder}
		 * @return the {@link Builder} for further configuration
		 */
		public Builder authorizationConsent(OAuth2AuthorizationConsent.Builder authorizationConsent) {
			return put(OAuth2AuthorizationConsent.Builder.class, authorizationConsent);
		}

		/**
		 * Sets the {@link RegisteredClient registered client}.
		 *
		 * @param registeredClient the {@link RegisteredClient}
		 * @return the {@link Builder} for further configuration
		 */
		public Builder registeredClient(RegisteredClient registeredClient) {
			return put(RegisteredClient.class, registeredClient);
		}

		/**
		 * Sets the {@link OAuth2Authorization authorization}.
		 *
		 * @param authorization the {@link OAuth2Authorization}
		 * @return the {@link Builder} for further configuration
		 */
		public Builder authorization(OAuth2Authorization authorization) {
			return put(OAuth2Authorization.class, authorization);
		}

		/**
		 * Sets the {@link OAuth2AuthorizationRequest authorization request}.
		 *
		 * @param authorizationRequest the {@link OAuth2AuthorizationRequest}
		 * @return the {@link Builder} for further configuration
		 */
		public Builder authorizationRequest(OAuth2AuthorizationRequest authorizationRequest) {
			return put(OAuth2AuthorizationRequest.class, authorizationRequest);
		}

		/**
		 * Builds a new {@link OAuth2AuthorizationConsentAuthenticationContext}.
		 *
		 * @return the {@link OAuth2AuthorizationConsentAuthenticationContext}
		 */
		public OAuth2AuthorizationConsentAuthenticationContext build() {
			Assert.notNull(get(OAuth2AuthorizationConsent.Builder.class), "authorizationConsentBuilder cannot be null");
			Assert.notNull(get(RegisteredClient.class), "registeredClient cannot be null");
			Assert.notNull(get(OAuth2Authorization.class), "authorization cannot be null");
			Assert.notNull(get(OAuth2AuthorizationRequest.class), "authorizationRequest cannot be null");
			return new OAuth2AuthorizationConsentAuthenticationContext(getContext());
		}

	}

}

相关信息

spring-authorization-server 源码目录

相关文章

spring-authorization-server ClientSecretAuthenticationProvider 源码

spring-authorization-server CodeVerifierAuthenticator 源码

spring-authorization-server JwtClientAssertionAuthenticationProvider 源码

spring-authorization-server OAuth2AccessTokenAuthenticationToken 源码

spring-authorization-server OAuth2AuthenticationContext 源码

spring-authorization-server OAuth2AuthenticationProviderUtils 源码

spring-authorization-server OAuth2AuthenticationValidator 源码

spring-authorization-server OAuth2AuthorizationCodeAuthenticationProvider 源码

spring-authorization-server OAuth2AuthorizationCodeAuthenticationToken 源码

spring-authorization-server OAuth2AuthorizationCodeRequestAuthenticationException 源码

0  赞