小编Ale*_*isi的帖子

如何在javascript中生成随机的十六进制字符串

如何生成仅包含给定长度的十六进制字符 (0123456789abcdef) 的随机字符串?

javascript lodash

13
推荐指数
6
解决办法
1万
查看次数

使用 ReactiveSecurityContextHolder 手动设置身份验证

我正在尝试使用 Spring Web Flux 设置 Spring Security。我不明白如何手动设置SecurityContextwith ReactiveSecurityContextHolder. 您有任何资源或提示吗?以我编写的这个过滤器为例,它读取 JWT 令牌并需要手动设置身份验证:

@Slf4j
public class JwtTokenAuthenticationFilter implements WebFilter {

    private final JwtAuthenticationConfig config;

    private final JwtParser jwtParser = Jwts.parser();

    public JwtTokenAuthenticationFilter(JwtAuthenticationConfig config) {
        this.config = config;
        jwtParser.setSigningKey(config.getSecret().getBytes());
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {

        String token = exchange.getRequest().getHeaders().getFirst(config.getHeader());
        if (token != null && token.startsWith(config.getPrefix() + " ")) {
            token = token.replace(config.getPrefix() + " ", "");
            try {
                Claims claims = jwtParser.parseClaimsJws(token).getBody();
                String username = claims.getSubject();
                @SuppressWarnings("unchecked") …
Run Code Online (Sandbox Code Playgroud)

spring-security reactive-programming

8
推荐指数
1
解决办法
5948
查看次数

Docker Swarm 模式路由网格不适用于wireguard VPN

我正在尝试在 Hetzner 云上设置一个 3 节点 Docker swarm 集群,使用wireguard VPN(在接口上设置wg0)在节点之间构建本地网络。网络可以跨使用VPN的IP节点罚款(端口7946/tcp7946/udp并且4789/udp是开放的报道在这里)。我使用以下命令启动 docker swarm 集群:

docker swarm init --advertise-addr wg0 --listen-addr wg0
docker swarm join --token SWMTKN-1-xxx --advertise-addr wg0 --listen-addr wg0 10.0.0.1:2377
Run Code Online (Sandbox Code Playgroud)

如果我尝试在这个 swarm 上运行一个服务,它似乎运行正确,每个容器都可以在不同的节点上到达另一个节点并检查它们,它们加入了入口网络和我创建的覆盖网络,正如预期的那样。当我尝试从服务公开端口之外访问时出现问题;它仅在我以容器运行的节点为目标时才有效,因此似乎路由网格无法正常工作。我在 docker 日志或系统日志中没有发现任何错误。

注意:我正在使用 docker 18.06.1-ce

vpn docker docker-swarm docker-swarm-mode

7
推荐指数
1
解决办法
1371
查看次数

docker服务更新vs docker堆栈使用现有堆栈进行部署

在使用部署了一组服务后,我对使用docker swarm模式命令更新现有服务有疑问docker stack deploy。据我了解,每个服务在创建时都固定在映像的SHA256摘要中,因此,如果您重建并推送映像(具有相同标签)并且尝试运行docker service update,则不会更新服务映像(即使SHA256)是不同的)。相反,如果docker stack deploy再次运行,则所有服务都将使用新映像进行更新。我也通过使用来更新了服务映像docker service update --image repository/image:tag <service>。这是这些命令的正常行为,还是我不了解的东西?

我正在使用Docker 17.03.1-ce

docker docker-swarm-mode

6
推荐指数
1
解决办法
5463
查看次数

具有docker堆栈部署的主机环境变量

我想知道是否有办法使用从部署容器的主机获取的环境变量,而不是从docker stack deploy执行命令的位置获取的环境变量.例如,假设docker-compose.yml在三个节点Docker Swarm集群上启动了以下内容:

version: '3.2'
services:
  kafka:
    image: wurstmeister/kafka
    ports:
      - target: 9094
        published: 9094
        protocol: tcp
        mode: host
    deploy:
      mode: global
    environment:
      KAFKA_JMX_OPTS: "-Djava.rmi.server.hostname=${JMX_HOSTNAME} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.rmi.port=1099"
Run Code Online (Sandbox Code Playgroud)

JMX_HOSTNAME应当从容器部署,不应该成为每个容器相同的值主机服用.有没有正确的方法来做到这一点?

docker docker-swarm docker-swarm-mode

6
推荐指数
2
解决办法
7375
查看次数

使用 Eureka / Feign 时 @DataJpaTest 失败

我有以下 Spring Boot 应用程序(使用 Eureka 和 Feign):

@SpringBootApplication
@EnableFeignClients
@EnableRabbit
@EnableDiscoveryClient
@EnableTransactionManagement(proxyTargetClass = true)
public class EventServiceApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(EventServiceApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

和以下测试,用@SpringJpaTest 注释:

@RunWith(SpringRunner.class)
@DataJpaTest(showSql = true)
public class EventRepositoryTest {

    @Autowired
    private TestEntityManager entityManager;

    @Autowired
    private EventRepository repository;

    @Test
    public void testPersist() {
        this.entityManager.persist(new PhoneCall());
        List<Event> list = this.repository.findAll();

        assertEquals(1, list.size());
    }
}
Run Code Online (Sandbox Code Playgroud)

在运行测试时,我收到以下错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.netflix.discovery.EurekaClient] found for dependency [com.netflix.discovery.EurekaClient]: expected at least …
Run Code Online (Sandbox Code Playgroud)

spring spring-test spring-data-jpa spring-boot

5
推荐指数
1
解决办法
1167
查看次数

如何通过 JMX 连接到远程 Docker 容器

我有一个在远程机器上的容器中运行的 Spring Boot 应用程序,我必须使用哪些 JVM 参数通过 Java Mission Control 或 JVisual VM(通过 JMX)连接到它?

java jmx jvisualvm docker java-mission-control

2
推荐指数
1
解决办法
2757
查看次数