我正在研究一些弹簧安全代码。我想了解我在互联网1上找到的这个例子 :
http.requestMatchers()
.antMatchers("/management/**") // (1)
.and()
.authorizeRequests() // (2)
.antMatchers("/management/health")
.permitAll()
.antMatchers("/management/info")
.permitAll()
.antMatchers("/management/**")
.hasRole("ACTUATOR")
.anyRequest().permitAll()
.and()
.httpBasic(); (3)
Run Code Online (Sandbox Code Playgroud)
}
我无法理解这个配置,为什么这个代码:
http.requestMatchers()
.antMatchers("/management/**")
.and()
Run Code Online (Sandbox Code Playgroud)
在 .authorizeRequests() 之前?(1)
这意味着什么?
你能解释一下这个例子吗?
2:在第二种情况下,有什么区别?
http.requestMatchers().antMatchers("/rest2/**")
.and()
.authorizeRequests()
.antMatchers("/rest/v1/test/hello").permitAll()
.antMatchers("/rest/v1/test/**").denyAll()
.and()
.requestMatchers().antMatchers("/rest/**")
.and()
.authorizeRequests()
.antMatchers("/rest/v1/test/hello").permitAll();
Run Code Online (Sandbox Code Playgroud)
使用 requestMatchers() 有什么影响?
如果我向 "/rest/v1/test/hello2" 发送请求,我会收到 401 为什么拒绝请求的规则与 antMatchers("/rest2/**") 不匹配?
我在 AWS EC2 中部署了一个应用程序,有时(罕见),我无法连接并执行 redis 中的任何命令,我正在调查此问题的根本原因。
我正在使用 Spring boot + Redis (Elasticcache)。
我正在使用包装器来捕获任何异常以继续请求过程。
我的包装纸:
class RedisCacheWrapper implements Cache {
private final Cache delegate;
public RedisCacheWrapper(Cache redisCache) {
Assert.notNull(redisCache, "delegate cache must not be null");
this.delegate = redisCache;
}
@Override
public String getName() {
try {
return delegate.getName();
} catch (Exception e) {
return handleException(e);
}
}
@Override
public Object getNativeCache() {
try {
return delegate.getNativeCache();
} catch (Exception e) {
return handleException(e);
}
}
@Override
public ValueWrapper get(Object key) { …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring boot2,我正在尝试使用 H2 + Liquibase + JUNIT 配置单元测试。
我认为 liquibase 没有执行 changeLog 文件并应用 SQL 命令,单元测试无法识别我的表。
我将错误的 sql 放在我的文件中以查看是否执行了更改日志文件,但是,似乎没有执行。
为什么我的应用程序无法访问表?也许 liquibase 没有执行?
在我的src/test/resource我有这个文件:application.yml
spring:
application:
name: my-api
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:myDB;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password: sags
liquibase:
enabled: true
user: sa
password: sags
change-log: classpath:/db/changelog/db.changelog-master.xml
jpa:
hibernate:
ddl-auto: none
database-platform: org.hibernate.dialect.H2Dialect
show-sql: true
properties:
hibernate:
use_sql_comments: true
format_sql: true
h2:
console:
enabled: true
path: /console
Run Code Online (Sandbox Code Playgroud)
我的测试课:
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import …
Run Code Online (Sandbox Code Playgroud) 我使用的是elasticsearch 5+,我使用模糊做了一些查询。我了解以下模糊参数:
模糊性,前缀长度。
但是,我无法理解“max_expansions”,我读了很多文章,但这对我来说很难,因为关于它的例子很少。
你能用例子解释一下这个参数吗?它如何与模糊参数一起工作?
写一个例子:我做了这个查询:
GET my-index/my-type/_search
{
"query": {
"fuzzy": {
"my-field": {
"value": "house",
"fuzziness": 1,
"prefix_length": 0,
"max_expansions": 1
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有4个分片,我的查询找到了6个结果,因为“my-field”中有6个带有“hous”的文档。如果 max_expansions 就像数据库中的限制,最大结果应该是 4 (因为我有 4 个分片)?为什么返回6个结果?
我正在使用 Resilience4j 进行大量测试并监视线程的行为。
我使用的是 spring-boot 2.2.5,resilience4j 1.4.0。Ga特林(加载工具)、VisualVM(分析线程)
我意识到:
当我使用舱壁类型 = SEMAPHORE 时。
我意识到异步执行将使用默认的 ExecutorService,在这种情况下,ForkJoinPool 和此配置将起作用:
maxConcurrentCalls, maxWaitDuration
Run Code Online (Sandbox Code Playgroud)
如果您使用的是bulkhead type = THREADPOOL,上述配置将被忽略。
当我使用批量 THREADPOOL 时,这些配置将起作用:
maxThreadPoolSize, coreThreadPoolSize, queueCapacity, keepAliveDuration
Run Code Online (Sandbox Code Playgroud)
这些配置将被忽略:
maxConcurrentCalls, maxWaitDuration
Run Code Online (Sandbox Code Playgroud)我的代码:
@CircuitBreaker(name = MyServiceCommand.BEAN_NAME, fallbackMethod = "fallback")
@TimeLimiter(name = MyServiceCommand.BEAN_NAME)
@Bulkhead(name = MyServiceCommand.BEAN_NAME, type = Bulkhead.Type.THREADPOOL)
@Component
@AllArgsConstructor
@Slf4j
public class MyServiceCommand extends ResilienceAbstractCommand {
protected static final String BEAN_NAME = "MyService";
private SlowService slowService;
public CompletableFuture<String> perform() {
return CompletableFuture.completedFuture(slowService.get());
}
private CompletableFuture<String> fallback() {
return CompletableFuture.completedFuture("fallback");
} …
Run Code Online (Sandbox Code Playgroud) 我的客户向我发送了一个 JWT,我需要使用他们的公钥验证此 JWT。我正在使用 Java 和 JJWT 框架来验证此令牌。我知道使用 HS256 解码此令牌,但使用 RS256 我不知道。
他们的配置是:
在这里编辑以改进我的问题。我正在使用的 jjwt 解析示例:
Claims String secret = "-----BEGIN CERTIFICATE-----myx5ckey-----END CERTIFICATE-----"
byte[] dataBytes = Base64.getEncoder().encode(secret.getBytes());
byte[] byteKey = Base64.getDecoder().decode(dataBytes);
X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey);
KeyFactory kf = KeyFactory.getInstance("RSA");
PublicKey publicKey = kf.generatePublic(X509publicKey);
Claims body = null;
body = Jwts.parser().setSigningKey(publicKey.getEncoded())
.parseClaimsJws(idToken)
.getBody();
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:205)
Run Code Online (Sandbox Code Playgroud)
如何使用我显示的 JWKS 信息验证收到的令牌?(上图)
当我执行:
System.getProperty("networkaddress.cache.ttl");
Security.getProperty("networkaddress.cache.ttl");
Run Code Online (Sandbox Code Playgroud)
结果为空。
我正在使用高山,openJdk8。我做了一些测试,发现我的资源 dns 正在发生变化,这是我想要的行为,解析 dns,而不是永远缓存。
我读到如果安装了 SecurityManager,默认值为:-1,这意味着“永远缓存 dns”
我没有安装 SecurityManager。
这种情况下的正确行为是什么?未安装 SecurityManager 且 networkaddress.cache.ttl 为空时?Dns 缓存是否会刷新?
我JFrog
配置了神器.我想artifactory
只保留我的应用程序的文件(jar,war等),而不是将其他文件保存在磁盘上.例:
(是的,保留在神器的磁盘上)
myapp.1.0-SNAPSHOT
myotherapp.2.0-SNAPSHOT
Run Code Online (Sandbox Code Playgroud)
(不,当执行maven命令时,我希望那个工件不包含这些文件,因此,maven将在中央存储库中搜索)
hibernatexxx
springxxxx
log4jxxxx
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我正在为 JmsFactory 配置并发性以便使用我的队列。
我这样做了:
@Bean(name = "myFactory")
public DefaultJmsListenerContainerFactory sqsFactory(SQSConnectionFactory connectionFactory,
CustomJmsListenerConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, connectionFactory);
factory.setConcurrency("1-3");
return factory;
}
Run Code Online (Sandbox Code Playgroud)
我看到DefaultJmsListenerContainerFactory.setConcurrency后面调用了DefaultMessageListenerContainer。
我在我的应用程序中配置了 2 个队列,我正在使用 spring boot:
@JmsListener(destination = "queue1", containerFactory = "myFactory")
@JmsListener(destination = "queue2", containerFactory = "myFactory")
Run Code Online (Sandbox Code Playgroud)
我正在阅读 spring 文档并遇到一些方法,现在我有一些疑问。
1 - 有什么区别:
setConcurrency(String concurrency)
setConcurrentConsumers(int concurrentConsumers)
Run Code Online (Sandbox Code Playgroud)
即使阅读文档,我也不理解其中的区别以及此配置如何改变应用程序行为。我认为 setConcurrency 应该是每个 @jmsLister 用于从队列获取消息的线程数...您能解释一下我有 100 条消息排队(每个配置队列)的配置映像示例吗?
2 - setMaxMessagesPerTask(int maxMessagesPerTask)
如果队列中有 100 条消息,并发数 = 3,并且该数字为 10(默认),那么行为是什么?
spring-boot ×4
java ×3
artifactory ×1
h2 ×1
java-8 ×1
jjwt ×1
jms ×1
junit ×1
jwt ×1
liquibase ×1
maven ×1
oauth-2.0 ×1
openid ×1
redis ×1
resilience4j ×1
spring ×1
spring-jms ×1