我们遇到了Spring web服务的问题。 我们使用Spring Security来保护我们的管理后台,以便生成api密钥。当我们在本地机器(Windows和MacOS)上部署它时,它可以正常工作并加载页面。如果我们尝试将它部署到使用Debian或Ubuntu的虚拟机上,那么未加密的端点加载正常,但只要我们点击管理后端,服务器就会锁定并不加载页面。我们尝试使用git repo中的gradle任务bootRun进行部署,编译一个war并将其加载到tomcat实例中,然后编译一个jar并运行它,但都没有成功。我们没有在控制台中看到任何例外情况,但它看起来运行良好,但是,在我们点击后端后,没有其他页面加载,甚至是之前运行的页面。部署在Linux服务器上的Spring Security崩溃
这是安全配置
package me.probE466.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.*;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.*;
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// auth
// .inMemoryAuthentication()
// .withUser("user").password("password").roles("ADMIN");
}
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/post");
http.authorizeRequests()
.antMatchers("/admin/**")
.authenticated()
.antMatchers("/**").permitAll().and().httpBasic();
}
}
这是控制器
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public ModelAndView getTest() {
return new ModelAndView("addapi");
}
@RequestMapping(value = "/admin", method = RequestMethod.POST)
public
@ResponseBody
String addApiKey(@RequestParam("userName") String userName) {
User user = new User();
String key = generateSecureApiKey(32);
user.setUserKey(key);
user.setUserName(userName);
userRepository.save(user);
return key;
}
这是我们的build.gradle
buildscript {
ext {
springBootVersion = '1.4.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
jar {
baseName = 'push'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile("mysql:mysql-connector-java:5.1.34")
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.thymeleaf:thymeleaf-spring4')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
// https://mvnrepository.com/artifact/commons-lang/commons-lang
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
任何帮助,将不胜感激