开启 SpringSecurity 后 Eureka 界面无法访问

2018-04-20 23:22:10 +08:00
 oracle128g

开启 security 之前正常

开启 security 之后无法登录

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);
	}
}
6139 次点击
所在节点    Java
4 条回复
alvinbone88
2018-04-21 00:29:01 +08:00
把 trace 设为 true,然后把日志贴上来

不过我猜的话,应该把 server.tomcat.max-http-post-size 设为一个较大的数
maowu
2018-04-21 00:49:27 +08:00
你这个用的是 Form 登陆方式吧?关掉其余只保留 basic 试试?
yang608
2018-04-21 04:11:12 +08:00
新版本的会自动开 csrf,关掉或者排除 URL 就行了
Zovven
2018-04-21 17:03:59 +08:00
必须用 basic auth

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/448591

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX