开启 SpringSecurity 后 Eureka 界面无法访问

开启 SpringSecurity 后 Eureka 界面无法访问,第1张

开启 SpringSecurity 后 Eureka 界面无法访问,第2张

开启 security 之前正常

开启 SpringSecurity 后 Eureka 界面无法访问,开启 security 之前正常,第3张

开启 security 之后无法登录

开启 SpringSecurity 后 Eureka 界面无法访问,开启 security 之后无法登录,第4张

pom.xml

<?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>org.zhl.frame</groupId>
	<artifactId>zhl-frame</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>zhl-frame</name>
	<description>Demo project for Spring Boot</description>

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

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>10</java.version>
		<spring-cloud.version>Finchley.M9</spring-cloud.version>
	</properties>

	<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.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
		</dependency>

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

		<dependency>
			<groupId>javax.xml.bind</groupId>
			<artifactId>jaxb-api</artifactId>
			<version>2.3.0</version>
		</dependency>
		<dependency>
			<groupId>com.sun.xml.bind</groupId>
			<artifactId>jaxb-impl</artifactId>
			<version>2.3.0</version>
		</dependency>
		<dependency>
			<groupId>org.glassfish.jaxb</groupId>
			<artifactId>jaxb-runtime</artifactId>
			<version>2.3.0</version>
		</dependency>
		<dependency>
			<groupId>javax.activation</groupId>
			<artifactId>activation</artifactId>
			<version>1.1.1</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>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>


</project>

application.yml

# eureka.client.registerWithEureka:表示是否将自己注册到 Eureka Server,默认为 true。由于当前这个应用就是 Eureka Server,故而设为 false
# eureka.client.fetchRegistry:表示是否从 Eureka Server 获取注册信息,默认为 true。因为这是一个单点的 Eureka Server,不需要同步其他的 Eureka Server 节点的数据,故而设为 false。
# eureka.client.serviceUrl.defaultZone:设置与 Eureka Server 交互的地址,查询服务和注册服务都需要依赖这个地址。默认是 http://localhost:8761/eureka ;多个地址可使用 , 分隔。
server:
  port: 8764

# 安全认证的配置
security:
  basic:
    enabled: true
  user:
    name: chhliu  # 用户名
    password: chhliu123456   # 用户密码
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://chhliu:chhliu123456@localhost:8761/eureka  # 安全的注册地址

启动方法

package org.zhl.frame.zhlframe;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class ZhlFrameApplication {

	public static void main(String[] args) {
		SpringApplication.run(ZhlFrameApplication.class, args);
	}
}
----------------------- 以下是精选回复-----------------------

答:把 trace 设为 true,然后把日志贴上来

不过我猜的话,应该把 server.tomcat.max-http-post-size 设为一个较大的数
答:你这个用的是 Form 登陆方式吧?关掉其余只保留 basic 试试?
答:新版本的会自动开 csrf,关掉或者排除 URL 就行了
答:必须用 basic auth

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » 开启 SpringSecurity 后 Eureka 界面无法访问

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情