Spring boot security перенаправляет любой URL на страницу входа - PullRequest
0 голосов
/ 16 апреля 2019

Я использую весеннюю загрузку 2.1.1 с версией Spring Cloud по Гринвичу. Я аутентифицирую свою службу шлюза, т.е. zuul proxy, используя аутентификацию jwt. Вот pom.xml для нее

 <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.interra.ocm.parent</groupId>
    <artifactId>OcmParentModule</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>com.interra.ocm.parent</groupId>
  <artifactId>OCMGatewayModule</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>OCMGatewayModule</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
    <dependencies>


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

        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

            <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>



        <!-- https://mvnrepository.com/artifact/com.netflix.zuul/zuul-netflix -->

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>

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

<dependency>
  <groupId>io.jsonwebtoken</groupId>
  <artifactId>jjwt</artifactId>
  <version>0.9.0</version>
</dependency>

                <dependency>
            <groupId>com.interra.ocm.globalentities</groupId>
            <artifactId>OCMGlobalEntities</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>


    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
                   <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
            </dependency>

            <!-- https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-starter-client -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.1.1</version>
</dependency>

        </dependencies>
    </dependencyManagement>

<build>
      <!-- Turn on filtering by default for application properties -->
      <resources>
         <resource>
            <directory>${basedir}/src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
               <include>**/application*.yml</include>
               <include>**/application*.yaml</include>
               <include>**/application*.properties</include>
            </includes>
         </resource>
         <resource>
            <directory>${basedir}/src/main/resources</directory>
            <excludes>
               <exclude>**/application*.yml</exclude>
               <exclude>**/application*.yaml</exclude>
               <exclude>**/application*.properties</exclude>
            </excludes>
         </resource>
      </resources>
      <pluginManagement>
         <plugins>
            <!-- Apply more sensible defaults for user projects -->
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-failsafe-plugin</artifactId>
               <executions>
                  <execution>
                     <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                     </goals>
                  </execution>
               </executions>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-jar-plugin</artifactId>
               <configuration>
                  <archive>
                     <manifest>
                        <mainClass>${start-class}</mainClass>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                     </manifest>
                  </archive>
               </configuration>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <configuration>
                  <includes>
                     <include>**/*Tests.java</include>
                     <include>**/*Test.java</include>
                  </includes>
                  <excludes>
                     <exclude>**/Abstract*.java</exclude>
                  </excludes>
               </configuration>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-war-plugin</artifactId>
               <configuration>
                  <failOnMissingWebXml>false</failOnMissingWebXml>
                  <archive>
                     <manifest>
                        <mainClass>${start-class}</mainClass>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                     </manifest>
                  </archive>
               </configuration>
            </plugin>
            <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>exec-maven-plugin</artifactId>
               <configuration>
                  <mainClass>${start-class}</mainClass>
               </configuration>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-resources-plugin</artifactId>
               <version>2.6</version>
               <configuration>
                  <delimiters>
                     <delimiter>${resource.delimiter}</delimiter>
                  </delimiters>
                  <useDefaultDelimiters>false</useDefaultDelimiters>
               </configuration>
            </plugin>
            <plugin>
               <groupId>pl.project13.maven</groupId>
               <artifactId>git-commit-id-plugin</artifactId>
               <executions>
                  <execution>
                     <goals>
                        <goal>revision</goal>
                     </goals>
                  </execution>
               </executions>
               <configuration>
                  <verbose>true</verbose>
                  <dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
                  <generateGitPropertiesFile>true</generateGitPropertiesFile>
                  <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
               </configuration>
            </plugin>
            <!-- Support our own plugin -->
            <plugin>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
               <executions>
                  <execution>
                     <goals>
                        <goal>repackage</goal>
                     </goals>
                  </execution>
               </executions>
               <configuration>
                  <mainClass>${start-class}</mainClass>
               </configuration>
            </plugin>
            <!-- Support shade packaging (if the user does not want to use our plugin) -->
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-shade-plugin</artifactId>
               <dependencies>
                  <dependency>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-maven-plugin</artifactId>
                     <version>1.5.6.RELEASE</version>
                  </dependency>
               </dependencies>
               <configuration>
                  <keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
                  <createDependencyReducedPom>true</createDependencyReducedPom>
                  <filters>
                     <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                           <exclude>META-INF/*.SF</exclude>
                           <exclude>META-INF/*.DSA</exclude>
                           <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                     </filter>
                  </filters>
               </configuration>
               <executions>
                  <execution>
                     <phase>package</phase>
                     <goals>
                        <goal>shade</goal>
                     </goals>
                     <configuration>
                        <transformers>
                           <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                              <resource>META-INF/spring.handlers</resource>
                           </transformer>
                           <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                              <resource>META-INF/spring.factories</resource>
                           </transformer>
                           <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                              <resource>META-INF/spring.schemas</resource>
                           </transformer>
                           <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                           <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                              <mainClass>${start-class}</mainClass>
                           </transformer>
                        </transformers>
                     </configuration>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </pluginManagement>
   </build>
</project>

, и вотнастроить метод websecurityadapter

   @Override
   protected void configure(HttpSecurity http) throws Exception {
       http.cors().and().csrf().disable().
               authorizeRequests()
               .antMatchers(HttpMethod.POST,"/api/auth/**").permitAll()
               .anyRequest().anonymous()
               .and()
               .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
               .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

       http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
       http.formLogin().disable();
   }

Я попытался сделать все запросы анонимно, но все же он перенаправляет на страницу входа. Что я нахожу удивительным, если я пишу тот же код в другом микросервисе, т.е. клиент eureka, код работает хорошо.Пожалуйста, руководство

...