这是我的 Spring 配置:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class X509Configuration extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/ws/items.wsdl");
}
@Override
public void configure(final HttpSecurity http) throws Exception {
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.authorizeRequests()
.antMatchers("/ws/items.wsdl").permitAll()
.and()
// require authorization for everything else
.authorizeRequests()
.anyRequest().authenticated()
.and()
.x509()
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(userDetailsService())
.and()
.csrf().disable() …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行参数化 JUnit 5 测试,如何完成以下任务?
@ParametrizedTest
@ValueSource //here it seems only one parameter is supported
public void myTest(String parameter, String expectedOutput)
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用@MethodSource,但我想知道在我的情况下我是否只需要更好地理解@ValueSource。
我有两个没有建模关系的表:
表comm的列:
name
date
code
Run Code Online (Sandbox Code Playgroud)
表persondesc的列:
code
description
Run Code Online (Sandbox Code Playgroud)
这两个表之间的关系是多对一(许多通讯一个persondesc):
com.code = persondesc.code
这两个表使用注释进行映射,但我没有声明关系.
我想要的是选择comm排序的表persondesc.description.
我该怎么做JPA和Hibernate?
我需要就以下问题寻求帮助。我正在从属性文件中读取一些属性并将更改的/最终值分配给另一个变量。我在将 static{ } 块更改为普通块或在构造函数中遇到困难。
我希望所有这些变量在 Web 应用程序加载/部署时从 .properties 文件中获取赋值。有什么帮助吗?
private static String username;
private static String password;
private static String dbURL;
private static String dbPort;
private static String filePath;
private static File localFile;
private static File remoteFile;
@Value("${local.file.name}")
private String localFileName;
@Value("${remote.file.name"})
private String remoteFileName;
static {
File finalFilePath = new File(filePath);
if (!finalFilePath.exists() && !finalFilePath.isDirectory()) {
finalFilePath.mkdirs();
}
localFile = new File(StringBuffer(finalFilePath).append("/").append("localFileName").toString());
remoteFile = new File(StringBuffer(finalFilePath).append("/").append("remoteFileName").toString());
}
Run Code Online (Sandbox Code Playgroud) 我有一个基于 Spring Security OAuth 2.0 的应用程序,配置了 JDBC 和 LDAP。根据 OAuth 2.0 规范,客户端密码必须。
当我使用以下 URL 生成令牌时,它会生成令牌并且工作正常:
/oauth/token?grant_type=password&client_secret=test&client_id=test&username=test&password=test
Run Code Online (Sandbox Code Playgroud)
当我尝试在没有client_secret它的情况下生成令牌时:
401:未经授权
error_description: "错误的用户凭据"
但我想生成没有client_secret像的令牌:
/oauth/token?grant_type=password&client_secret=test&client_id=test&username=test&password=test
Run Code Online (Sandbox Code Playgroud)
securityConfig.java:
/oauth/token?grant_type=password&username=test&password=test
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Spring Boot应用程序添加安全性.我当前的应用程序是使用REST控制器,每次我收到GET或POST请求时,我都会读取HTTP标头以检索用户和密码,以便根据我存储了所有用户的属性文件验证它们.我想将此更改为使用Spring Security,这是我到目前为止所得到的:
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/index.html").permitAll()
.antMatchers("/swagger-ui.html").hasRole("ADMIN")
.anyRequest().authenticated();
}
@Bean
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("admin").password("password").roles("ADMIN").build());
}
}
Run Code Online (Sandbox Code Playgroud)
如何告诉configure方法从头部而不是登录表单中检索用户凭据?
security authentication spring-security http-headers spring-boot
[你好]
我无法通过市场安装上面.丢失依赖项的详细错误如下:
无法完成安装,因为找不到一个或多个必需的项目.正在安装的软件:用于EGit的Maven SCM处理程序0.14.0.201509090157(org.sonatype.m2e.egit.feature.feature.group 0.14.0.201509090157)缺少要求:EGit的Maven SCM处理程序0.14.0.201509090157(org.sonatype.m2e.egit 0.14) .0.201509090157)要求'osgi.bundle; org.eclipse.egit.core [3.0.0,5.0.0)'但无法找到它无法满足依赖性:来自:Mait SCM Handler for EGit 0.14.0.201509090157(org.sonatype.m2e.egit.feature.feature. group 0.14.0.201509090157)收件人:org.eclipse.equinox.p2.iu; org.sonatype.m2e.egit [0.14.0.201509090157,0.14.0.201509090157]
我注意到这种情况发生得比较早,最常见的是当有更新版本的eclipse时.无论如何,我找不到某个软件站点或有效的包来解决它.
除了回氧气,我能做些什么吗?
问候T.
我正在将应用程序从 Spring Boot 1.5 迁移到 2.0.5。我有一个security.enable-csrf=true在 1.5 版本中设置的属性,但在 2.0 版本的 Spring Boot 中不可用。
我阅读了文档,据说在 Spring Boot 2.0 中:
在 Java 配置中默认启用 CSRF 保护。
所以默认情况下它是启用的,但也创建了一个类,它扩展了WebSecurityConfigurerAdapter这意味着 Spring Boot 默认安全配置已被关闭。这是否也意味着security.enable-csrf现在被禁用了?
如果是,我该如何启用它,就像我在 1.5 版本的应用程序中使用它一样。
我没有得到任何文件明确确认如何security.enable-csrf在 Spring Boot 2.0 中处理属性以及在声明WebSecurityConfigurerAdapter.
有人知道吗?此外,我错过阅读有关此内容的任何文档链接都会有很大帮助。
为什么 spring.session.store-type 没有 in memory 选项。?
有什么方法可以在不编写我的 store 实现的情况下使用带有内存选项的 spring 会话吗?
我想使用 spring 会话来使用令牌休息 api
@Bean
public HttpSessionIdResolver httpSessionIdResolver() {
return HeaderHttpSessionIdResolver.xAuthToken();
}
Run Code Online (Sandbox Code Playgroud) 我在詹金斯内部编写了一个声明式管道。该管道应在远程Docker服务器上的Docker容器中运行。
我阅读了定制执行环境:
定制执行环境
Pipeline旨在轻松地将Docker映像用作单个Stage或整个Pipeline的执行环境。这意味着用户可以定义其管道所需的工具,而无需手动配置代理。几乎任何可以打包在Docker容器中的工具。只需对Jenkinsfile进行少量编辑即可轻松使用。
Run Code Online (Sandbox Code Playgroud)pipeline { agent { docker { image 'node:7-alpine' } } stages { stage('Test') { steps { sh 'node --version' } } } }
它可以工作,但是它使用Jenkins服务器作为Docker服务器。
我读过使用远程Docker服务器:
使用远程Docker服务器
默认情况下,Docker Pipeline插件将与本地Docker守护进程通信,该守护进程通常通过/var/run/docker.sock访问。
要选择非默认的Docker服务器(例如Docker Swarm),应使用withServer()方法。
通过使用以下方法将URI以及可选的Jenkins中预先配置的Docker服务器证书身份验证的凭据ID传递给方法:
Run Code Online (Sandbox Code Playgroud)node { checkout scm docker.withServer('tcp://swarm.example.com:2376', 'swarm-certs') { docker.image('mysql:5').withRun('-p 3306:3306') { /* do things */ } } }
这行得通,但它使用脚本管道。
我还阅读了指定Docker标签:
指定Docker标签
默认情况下,管道假定任何已配置的代理都能够运行基于Docker的管道。对于具有macOS,Windows或其他代理程序且无法运行Docker守护程序的Jenkins环境,此默认设置可能会出现问题。管道在“管理Jenkins”页面和“文件夹”级别提供了一个全局选项,用于指定要使用哪些代理(按标签)来运行基于Docker的管道。
但是使用标签将需要一个完整的Jenkins从属服务器和sshd并安装一个Jenkins用户,并且一直在线,而Jenkins的主服务器将安装从属库。仅使用声明性管道而不是脚本化管道听起来有点沉重。
如何使用声明性管道在远程Docker服务器上构建?