From a38b66adf2329e29c05a5224097fc600aad20ea4 Mon Sep 17 00:00:00 2001 From: Joe Grandja Date: Fri, 29 Jul 2022 04:43:40 -0400 Subject: [PATCH] Remove unused code --- .../java/sample/test/SpringTestContext.java | 6 - ...Auth2AuthorizationRequestDeserializer.java | 18 +-- .../authorization/jackson2/StdConverters.java | 109 ------------------ .../config/test/SpringTestContext.java | 7 -- .../util/InMemoryXmlApplicationContext.java | 77 ------------- .../InMemoryXmlWebApplicationContext.java | 57 --------- 6 files changed, 10 insertions(+), 264 deletions(-) delete mode 100644 oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/jackson2/StdConverters.java delete mode 100644 oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java delete mode 100644 oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlWebApplicationContext.java diff --git a/docs/src/docs/asciidoc/examples/src/test/java/sample/test/SpringTestContext.java b/docs/src/docs/asciidoc/examples/src/test/java/sample/test/SpringTestContext.java index 96e674d4..1153de82 100644 --- a/docs/src/docs/asciidoc/examples/src/test/java/sample/test/SpringTestContext.java +++ b/docs/src/docs/asciidoc/examples/src/test/java/sample/test/SpringTestContext.java @@ -95,12 +95,6 @@ public class SpringTestContext implements Closeable { return this; } -// public SpringTestContext context(String configuration) { -// InMemoryXmlWebApplicationContext context = new InMemoryXmlWebApplicationContext(configuration); -// this.context = context; -// return this; -// } - public SpringTestContext mockMvcAfterSpringSecurityOk() { return addFilter(new OncePerRequestFilter() { @Override diff --git a/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationRequestDeserializer.java b/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationRequestDeserializer.java index 3fe9ed19..ec8a6ab3 100644 --- a/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationRequestDeserializer.java +++ b/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationRequestDeserializer.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.util.StdConverter; import org.springframework.security.oauth2.core.AuthorizationGrantType; import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; @@ -39,8 +38,6 @@ import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequ */ final class OAuth2AuthorizationRequestDeserializer extends JsonDeserializer { - private static final StdConverter AUTHORIZATION_GRANT_TYPE_CONVERTER = new StdConverters.AuthorizationGrantTypeConverter(); - @Override public OAuth2AuthorizationRequest deserialize(JsonParser parser, DeserializationContext context) throws IOException { @@ -51,8 +48,8 @@ final class OAuth2AuthorizationRequestDeserializer extends JsonDeserializer { - - @Override - public OAuth2AccessToken.TokenType convert(JsonNode jsonNode) { - String value = JsonNodeUtils.findStringValue(jsonNode, "value"); - if (OAuth2AccessToken.TokenType.BEARER.getValue().equalsIgnoreCase(value)) { - return OAuth2AccessToken.TokenType.BEARER; - } - return null; - } - - } - - static final class ClientAuthenticationMethodConverter extends StdConverter { - - @Override - public ClientAuthenticationMethod convert(JsonNode jsonNode) { - String value = JsonNodeUtils.findStringValue(jsonNode, "value"); - if (ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue().equalsIgnoreCase(value) - || ClientAuthenticationMethod.BASIC.getValue().equalsIgnoreCase(value)) { - return ClientAuthenticationMethod.CLIENT_SECRET_BASIC; - } - if (ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue().equalsIgnoreCase(value) - || ClientAuthenticationMethod.POST.getValue().equalsIgnoreCase(value)) { - return ClientAuthenticationMethod.CLIENT_SECRET_POST; - } - if (ClientAuthenticationMethod.NONE.getValue().equalsIgnoreCase(value)) { - return ClientAuthenticationMethod.NONE; - } - return null; - } - - } - - static final class AuthorizationGrantTypeConverter extends StdConverter { - - @Override - public AuthorizationGrantType convert(JsonNode jsonNode) { - String value = JsonNodeUtils.findStringValue(jsonNode, "value"); - if (AuthorizationGrantType.AUTHORIZATION_CODE.getValue().equalsIgnoreCase(value)) { - return AuthorizationGrantType.AUTHORIZATION_CODE; - } - if (AuthorizationGrantType.IMPLICIT.getValue().equalsIgnoreCase(value)) { - return AuthorizationGrantType.IMPLICIT; - } - if (AuthorizationGrantType.CLIENT_CREDENTIALS.getValue().equalsIgnoreCase(value)) { - return AuthorizationGrantType.CLIENT_CREDENTIALS; - } - if (AuthorizationGrantType.PASSWORD.getValue().equalsIgnoreCase(value)) { - return AuthorizationGrantType.PASSWORD; - } - return null; - } - - } - - static final class AuthenticationMethodConverter extends StdConverter { - - @Override - public AuthenticationMethod convert(JsonNode jsonNode) { - String value = JsonNodeUtils.findStringValue(jsonNode, "value"); - if (AuthenticationMethod.HEADER.getValue().equalsIgnoreCase(value)) { - return AuthenticationMethod.HEADER; - } - if (AuthenticationMethod.FORM.getValue().equalsIgnoreCase(value)) { - return AuthenticationMethod.FORM; - } - if (AuthenticationMethod.QUERY.getValue().equalsIgnoreCase(value)) { - return AuthenticationMethod.QUERY; - } - return null; - } - - } - -} diff --git a/oauth2-authorization-server/src/test/java/org/springframework/security/config/test/SpringTestContext.java b/oauth2-authorization-server/src/test/java/org/springframework/security/config/test/SpringTestContext.java index be3e3f00..4fd1725a 100644 --- a/oauth2-authorization-server/src/test/java/org/springframework/security/config/test/SpringTestContext.java +++ b/oauth2-authorization-server/src/test/java/org/springframework/security/config/test/SpringTestContext.java @@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; import org.springframework.mock.web.MockServletConfig; import org.springframework.mock.web.MockServletContext; -import org.springframework.security.config.util.InMemoryXmlWebApplicationContext; import org.springframework.test.context.web.GenericXmlWebContextLoader; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.RequestPostProcessor; @@ -90,12 +89,6 @@ public class SpringTestContext implements Closeable { return this; } - public SpringTestContext context(String configuration) { - InMemoryXmlWebApplicationContext context = new InMemoryXmlWebApplicationContext(configuration); - this.context = context; - return this; - } - public SpringTestContext mockMvcAfterSpringSecurityOk() { return addFilter(new OncePerRequestFilter() { @Override diff --git a/oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java b/oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java deleted file mode 100644 index 4b163248..00000000 --- a/oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.config.util; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.AbstractXmlApplicationContext; -import org.springframework.core.io.Resource; -import org.springframework.security.util.InMemoryResource; - -/** - * @author Luke Taylor - * @author EddĂș MelĂ©ndez - */ -public class InMemoryXmlApplicationContext extends AbstractXmlApplicationContext { - static final String BEANS_OPENING = "\n" + xml + BEANS_CLOSE; - inMemoryXml = new InMemoryResource(fullXml); - setAllowBeanDefinitionOverriding(true); - setParent(parent); - refresh(); - } - - @Override - protected DefaultListableBeanFactory createBeanFactory() { - return new DefaultListableBeanFactory(getInternalParentBeanFactory()) { - @Override - protected boolean allowAliasOverriding() { - return true; - } - }; - } - - protected Resource[] getConfigResources() { - return new Resource[] { inMemoryXml }; - } -} diff --git a/oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlWebApplicationContext.java b/oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlWebApplicationContext.java deleted file mode 100644 index 759f1be6..00000000 --- a/oauth2-authorization-server/src/test/java/org/springframework/security/config/util/InMemoryXmlWebApplicationContext.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.config.util; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.context.ApplicationContext; -import org.springframework.core.io.Resource; -import org.springframework.security.util.InMemoryResource; -import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext; - -import static org.springframework.security.config.util.InMemoryXmlApplicationContext.BEANS_CLOSE; -import static org.springframework.security.config.util.InMemoryXmlApplicationContext.BEANS_OPENING; -import static org.springframework.security.config.util.InMemoryXmlApplicationContext.SPRING_SECURITY_VERSION; - -/** - * @author Joe Grandja - */ -public class InMemoryXmlWebApplicationContext extends AbstractRefreshableWebApplicationContext { - private Resource inMemoryXml; - - public InMemoryXmlWebApplicationContext(String xml) { - this(xml, SPRING_SECURITY_VERSION, null); - } - - public InMemoryXmlWebApplicationContext(String xml, ApplicationContext parent) { - this(xml, SPRING_SECURITY_VERSION, parent); - } - - public InMemoryXmlWebApplicationContext(String xml, String secVersion, ApplicationContext parent) { - String fullXml = BEANS_OPENING + secVersion + ".xsd'>\n" + xml + BEANS_CLOSE; - inMemoryXml = new InMemoryResource(fullXml); - setAllowBeanDefinitionOverriding(true); - setParent(parent); - } - - @Override - protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException { - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - reader.loadBeanDefinitions(new Resource[] { inMemoryXml }); - } - -}