如何解决无法登录 togglz 管理控制台
我正在学习 togglz。我的简单程序运行良好,我正在尝试添加内存中的 spring 安全用户名和密码,但我无法登录管理控制台。
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.togglz.core.manager.FeatureManager;
import org.togglz.core.util.NamedFeature;
import java.util.HashMap;
import java.util.Map;
@SpringBootApplication
@RestController
public class ApiTestApplication {
@Autowired
private FeatureManager featureManager;
public static void main(String[] args) {
SpringApplication.run(ApiTestApplication.class,args);
}
@GetMapping
public Map<String,Boolean> test1() {
Map<String,Boolean> enumMap = new HashMap<>();
enumMap.put("FEATURE_ONE",featureManager.isActive(new NamedFeature("FEATURE_ONE")));
enumMap.put("FEATURE_TWO",featureManager.isActive(new NamedFeature("FEATURE_TWO")));
return enumMap;
}
}
应用属性
togglz.console.feature-admin-authority=ADMIN
togglz.features.FEATURE_ONE.enabled=false
togglz.features.FEATURE_TWO.enabled=false
togglz.console.enabled=true
togglz.console.path=/togglz-console
togglz.console.secured=true
management.endpoints.web.exposure.include=*
logging.level.org.togglz=DEBUG
安全等级
package com.example.demo;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
public class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.csrf()
.disable()
.formLogin()
.and()
.logout();
// @@formatter:on
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth.inMemoryAuthentication()
.withUser("admin")
.password("{noop}admin")
.roles("ADMIN");
}
}
构建gradle
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.togglz:togglz-spring-boot-starter:+'
implementation 'org.togglz:togglz-console:+'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.togglz:togglz-spring-security:+'
implementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
http://localhost:8080/ 带有 un/pass -admin/admin 我能够看到布尔值。 但要切换它, http://localhost:8080/togglz-console/index 是说 type=Forbidden,status=403
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。