Исправьте путь к классу вашего приложения, чтобы он содержал одну совместимую версию oauth2.client.registration.ClientRegistrations - PullRequest
2 голосов
/ 13 января 2020

Я пытаюсь развернуть свое веб-приложение на сервере Tomcat локально, и это очень простое приложение аутентификации Keycloak, но я получаю ошибку ниже даже после удаления всех локальных репозиториев по этому пути (.m2 \ repository \ org \ hibernate). Затем Я сделал mvn clean install и попытался повторно развернуть снова

Сообщение об ошибке:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getBuilderFromIssuerIfPossible(OAuth2ClientPropertiesRegistrationAdapter.java:83)

The following method did not exist:

    org.springframework.security.oauth2.client.registration.ClientRegistrations.fromIssuerLocation(Ljava/lang/String;)Lorg/springframework/security/oauth2/client/registration/ClientRegistration$Builder;

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.security.oauth2.client.registration.ClientRegistrations

вот мой код:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                    .anyRequest().authenticated()
                    .and()
                    .oauth2Login();
        }
}

ОБНОВЛЕННЫЙ POM-файл:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.baeldung.keycloak</groupId>
    <artifactId>E-Services-Portal</artifactId>
    <packaging>war</packaging>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>


    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.keycloak.bom</groupId>
                <artifactId>keycloak-adapter-bom</artifactId>
                <version>3.3.0.Final</version>
                <type>pom</type>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-client</artifactId>
             </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.glassfish.web</groupId>
                <artifactId>el-impl</artifactId>
                <version>2.2</version>
            </dependency>
            <dependency>
                <groupId>org.axonframework</groupId>
                <artifactId>axon-spring-boot-starter</artifactId>
                <version>3.4</version>
            </dependency>
        </dependencies>


    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Plugin Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
        </repository>

    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

ПРИМЕЧАНИЕ. Я использую Spring 2.2.2

1 Ответ

0 голосов
/ 13 января 2020

У вас есть дубликаты зависимостей, и вы смешиваете старый проект Spring Security OAuth с новой поддержкой Spring Security 5 OAuth. Начните с удаления всех артефактов, связанных с безопасностью:

  • spring-boot-starter-oauth2-client
  • spring-security-config
  • spring-security-oauth2
  • spring-security-oauth2-autoconfigure
  • spring-security-core

Добавить:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

Это даст правильные версии Spring-security-core и spring-security-config, среди прочих зависимостей.

Также добавьте:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-client</artifactId>
</dependency>
...