@Test public void testAccessControlInterceptor() { accessController = new AxonServerAccessController() { @Override public boolean allowed(String fullMethodName, String context, String token) { return "1234".equals(token) && Topology.DEFAULT_CONTEXT.equals(context); } @Override public boolean isRoleBasedAuthentication() { return false; } @Override public Set<String> getRoles(String token) { return Collections.emptySet(); } }; AxonServerClientService dummyPlatformService = new DummyPlatformService(); testSubject = new Gateway(routingConfiguration, Collections.singletonList(dummyPlatformService), accessController, licenseAccessController); testSubject.start(); Channel channel = NettyChannelBuilder.forAddress("localhost", routingConfiguration.getPort()).usePlaintext() .build(); try { PlatformServiceGrpc.newBlockingStub(channel).getPlatformServer(ClientIdentification .newBuilder() .build()); fail("Expected exception"); } catch (StatusRuntimeException sre) { assertEquals(ErrorCode.AUTHENTICATION_TOKEN_MISSING.getCode(), sre.getTrailers().get(GrpcMetadataKeys.ERROR_CODE_KEY)); } try { PlatformServiceGrpc.newBlockingStub(channel) .withInterceptors(getClientInterceptor(GrpcMetadataKeys.TOKEN_KEY, "2345")) .withInterceptors(getClientInterceptor(GrpcMetadataKeys.CONTEXT_MD_KEY, Topology.DEFAULT_CONTEXT)) .getPlatformServer(ClientIdentification.newBuilder().build()); fail("Expected exception"); } catch (StatusRuntimeException sre) { assertEquals(ErrorCode.AUTHENTICATION_INVALID_TOKEN.getCode(), sre.getTrailers().get(GrpcMetadataKeys.ERROR_CODE_KEY)); } PlatformInfo result = PlatformServiceGrpc.newBlockingStub(channel) .withInterceptors(getClientInterceptor(GrpcMetadataKeys.TOKEN_KEY, "1234")) .withInterceptors(getClientInterceptor(GrpcMetadataKeys.CONTEXT_MD_KEY, Topology.DEFAULT_CONTEXT)) .getPlatformServer(ClientIdentification.newBuilder().build()); assertEquals(Topology.DEFAULT_CONTEXT, result.getPrimary().getNodeName()); }
@Override public void start() { NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(routingConfiguration.getPort()) .permitKeepAliveWithoutCalls(true) .permitKeepAliveTime(routingConfiguration.getMinKeepAliveTime(), TimeUnit.MILLISECONDS); if( routingConfiguration.getMaxMessageSize() > 0) { serverBuilder.maxInboundMessageSize(routingConfiguration.getMaxMessageSize()); } String sslMessage = "no SSL"; if( routingConfiguration.getSsl() != null && routingConfiguration.getSsl().isEnabled()) { if( routingConfiguration.getSsl().getCertChainFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.cert-chain-file"); } if( routingConfiguration.getSsl().getPrivateKeyFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.private-key-file"); } serverBuilder.useTransportSecurity(new File(routingConfiguration.getSsl().getCertChainFile()), new File(routingConfiguration.getSsl().getPrivateKeyFile())); sslMessage = "SSL enabled"; } axonServerClientServices.forEach(serverBuilder::addService); serverBuilder.intercept(new GrpcBufferingInterceptor(routingConfiguration.getGrpcBufferedMessages())); if( routingConfiguration.getAccesscontrol().isEnabled()) { serverBuilder.intercept(new AuthenticationInterceptor(axonServerAccessController)); } serverBuilder.intercept(new LicenseInterceptor(licenseAccessController)); serverBuilder.intercept(new ContextInterceptor()); if( routingConfiguration.getKeepAliveTime() > 0) { serverBuilder.keepAliveTime(routingConfiguration.getKeepAliveTime(), TimeUnit.MILLISECONDS) .keepAliveTimeout(routingConfiguration.getKeepAliveTimeout(), TimeUnit.MILLISECONDS); } serverBuilder.executor(Executors.newFixedThreadPool(routingConfiguration.getExecutorThreadCount(), new CustomizableThreadFactory("grpc-executor-"))); server = serverBuilder.build(); try { server.start(); logger.info("Axon Server Gateway started on port: {} - {}", routingConfiguration.getPort(), sslMessage); started = true; } catch (IOException e) { logger.error("Starting Axon Server Gateway failed - {}", e.getMessage(), e); } }
Gateway implements SmartLifecycle { @Override public void start() { NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(routingConfiguration.getPort()) .permitKeepAliveWithoutCalls(true) .permitKeepAliveTime(routingConfiguration.getMinKeepAliveTime(), TimeUnit.MILLISECONDS); if( routingConfiguration.getMaxMessageSize() > 0) { serverBuilder.maxInboundMessageSize(routingConfiguration.getMaxMessageSize()); } String sslMessage = "no SSL"; if( routingConfiguration.getSsl() != null && routingConfiguration.getSsl().isEnabled()) { if( routingConfiguration.getSsl().getCertChainFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.cert-chain-file"); } if( routingConfiguration.getSsl().getPrivateKeyFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.private-key-file"); } serverBuilder.useTransportSecurity(new File(routingConfiguration.getSsl().getCertChainFile()), new File(routingConfiguration.getSsl().getPrivateKeyFile())); sslMessage = "SSL enabled"; } axonServerClientServices.forEach(serverBuilder::addService); serverBuilder.intercept(new GrpcBufferingInterceptor(routingConfiguration.getGrpcBufferedMessages())); if( routingConfiguration.getAccesscontrol().isEnabled()) { serverBuilder.intercept(new AuthenticationInterceptor(axonServerAccessController)); } serverBuilder.intercept(new LicenseInterceptor(licenseAccessController)); serverBuilder.intercept(new ContextInterceptor()); if( routingConfiguration.getKeepAliveTime() > 0) { serverBuilder.keepAliveTime(routingConfiguration.getKeepAliveTime(), TimeUnit.MILLISECONDS) .keepAliveTimeout(routingConfiguration.getKeepAliveTimeout(), TimeUnit.MILLISECONDS); } serverBuilder.executor(Executors.newFixedThreadPool(routingConfiguration.getExecutorThreadCount(), new CustomizableThreadFactory("grpc-executor-"))); server = serverBuilder.build(); try { server.start(); logger.info("Axon Server Gateway started on port: {} - {}", routingConfiguration.getPort(), sslMessage); started = true; } catch (IOException e) { logger.error("Starting Axon Server Gateway failed - {}", e.getMessage(), e); } } }
Gateway implements SmartLifecycle { @Override public void start() { NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(routingConfiguration.getPort()) .permitKeepAliveWithoutCalls(true) .permitKeepAliveTime(routingConfiguration.getMinKeepAliveTime(), TimeUnit.MILLISECONDS); if( routingConfiguration.getMaxMessageSize() > 0) { serverBuilder.maxInboundMessageSize(routingConfiguration.getMaxMessageSize()); } String sslMessage = "no SSL"; if( routingConfiguration.getSsl() != null && routingConfiguration.getSsl().isEnabled()) { if( routingConfiguration.getSsl().getCertChainFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.cert-chain-file"); } if( routingConfiguration.getSsl().getPrivateKeyFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.private-key-file"); } serverBuilder.useTransportSecurity(new File(routingConfiguration.getSsl().getCertChainFile()), new File(routingConfiguration.getSsl().getPrivateKeyFile())); sslMessage = "SSL enabled"; } axonServerClientServices.forEach(serverBuilder::addService); serverBuilder.intercept(new GrpcBufferingInterceptor(routingConfiguration.getGrpcBufferedMessages())); if( routingConfiguration.getAccesscontrol().isEnabled()) { serverBuilder.intercept(new AuthenticationInterceptor(axonServerAccessController)); } serverBuilder.intercept(new LicenseInterceptor(licenseAccessController)); serverBuilder.intercept(new ContextInterceptor()); if( routingConfiguration.getKeepAliveTime() > 0) { serverBuilder.keepAliveTime(routingConfiguration.getKeepAliveTime(), TimeUnit.MILLISECONDS) .keepAliveTimeout(routingConfiguration.getKeepAliveTimeout(), TimeUnit.MILLISECONDS); } serverBuilder.executor(Executors.newFixedThreadPool(routingConfiguration.getExecutorThreadCount(), new CustomizableThreadFactory("grpc-executor-"))); server = serverBuilder.build(); try { server.start(); logger.info("Axon Server Gateway started on port: {} - {}", routingConfiguration.getPort(), sslMessage); started = true; } catch (IOException e) { logger.error("Starting Axon Server Gateway failed - {}", e.getMessage(), e); } } Gateway(MessagingPlatformConfiguration messagingPlatformConfiguration, List<AxonServerClientService> axonServerClientServices,
                   AxonServerAccessController axonServerAccessController, LicenseAccessController licenseAccessController); }
Gateway implements SmartLifecycle { @Override public void start() { NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(routingConfiguration.getPort()) .permitKeepAliveWithoutCalls(true) .permitKeepAliveTime(routingConfiguration.getMinKeepAliveTime(), TimeUnit.MILLISECONDS); if( routingConfiguration.getMaxMessageSize() > 0) { serverBuilder.maxInboundMessageSize(routingConfiguration.getMaxMessageSize()); } String sslMessage = "no SSL"; if( routingConfiguration.getSsl() != null && routingConfiguration.getSsl().isEnabled()) { if( routingConfiguration.getSsl().getCertChainFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.cert-chain-file"); } if( routingConfiguration.getSsl().getPrivateKeyFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.private-key-file"); } serverBuilder.useTransportSecurity(new File(routingConfiguration.getSsl().getCertChainFile()), new File(routingConfiguration.getSsl().getPrivateKeyFile())); sslMessage = "SSL enabled"; } axonServerClientServices.forEach(serverBuilder::addService); serverBuilder.intercept(new GrpcBufferingInterceptor(routingConfiguration.getGrpcBufferedMessages())); if( routingConfiguration.getAccesscontrol().isEnabled()) { serverBuilder.intercept(new AuthenticationInterceptor(axonServerAccessController)); } serverBuilder.intercept(new LicenseInterceptor(licenseAccessController)); serverBuilder.intercept(new ContextInterceptor()); if( routingConfiguration.getKeepAliveTime() > 0) { serverBuilder.keepAliveTime(routingConfiguration.getKeepAliveTime(), TimeUnit.MILLISECONDS) .keepAliveTimeout(routingConfiguration.getKeepAliveTimeout(), TimeUnit.MILLISECONDS); } serverBuilder.executor(Executors.newFixedThreadPool(routingConfiguration.getExecutorThreadCount(), new CustomizableThreadFactory("grpc-executor-"))); server = serverBuilder.build(); try { server.start(); logger.info("Axon Server Gateway started on port: {} - {}", routingConfiguration.getPort(), sslMessage); started = true; } catch (IOException e) { logger.error("Starting Axon Server Gateway failed - {}", e.getMessage(), e); } } Gateway(MessagingPlatformConfiguration messagingPlatformConfiguration, List<AxonServerClientService> axonServerClientServices,
                   AxonServerAccessController axonServerAccessController, LicenseAccessController licenseAccessController); @Override boolean isAutoStartup(); @Override void stop(Runnable callback); @Override void start(); @Override void stop(); @Override boolean isRunning(); @Override int getPhase(); }
Gateway implements SmartLifecycle { @Override public void start() { NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(routingConfiguration.getPort()) .permitKeepAliveWithoutCalls(true) .permitKeepAliveTime(routingConfiguration.getMinKeepAliveTime(), TimeUnit.MILLISECONDS); if( routingConfiguration.getMaxMessageSize() > 0) { serverBuilder.maxInboundMessageSize(routingConfiguration.getMaxMessageSize()); } String sslMessage = "no SSL"; if( routingConfiguration.getSsl() != null && routingConfiguration.getSsl().isEnabled()) { if( routingConfiguration.getSsl().getCertChainFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.cert-chain-file"); } if( routingConfiguration.getSsl().getPrivateKeyFile() == null) { throw new RuntimeException("axoniq.axonserver.ssl.private-key-file"); } serverBuilder.useTransportSecurity(new File(routingConfiguration.getSsl().getCertChainFile()), new File(routingConfiguration.getSsl().getPrivateKeyFile())); sslMessage = "SSL enabled"; } axonServerClientServices.forEach(serverBuilder::addService); serverBuilder.intercept(new GrpcBufferingInterceptor(routingConfiguration.getGrpcBufferedMessages())); if( routingConfiguration.getAccesscontrol().isEnabled()) { serverBuilder.intercept(new AuthenticationInterceptor(axonServerAccessController)); } serverBuilder.intercept(new LicenseInterceptor(licenseAccessController)); serverBuilder.intercept(new ContextInterceptor()); if( routingConfiguration.getKeepAliveTime() > 0) { serverBuilder.keepAliveTime(routingConfiguration.getKeepAliveTime(), TimeUnit.MILLISECONDS) .keepAliveTimeout(routingConfiguration.getKeepAliveTimeout(), TimeUnit.MILLISECONDS); } serverBuilder.executor(Executors.newFixedThreadPool(routingConfiguration.getExecutorThreadCount(), new CustomizableThreadFactory("grpc-executor-"))); server = serverBuilder.build(); try { server.start(); logger.info("Axon Server Gateway started on port: {} - {}", routingConfiguration.getPort(), sslMessage); started = true; } catch (IOException e) { logger.error("Starting Axon Server Gateway failed - {}", e.getMessage(), e); } } Gateway(MessagingPlatformConfiguration messagingPlatformConfiguration, List<AxonServerClientService> axonServerClientServices,
                   AxonServerAccessController axonServerAccessController, LicenseAccessController licenseAccessController); @Override boolean isAutoStartup(); @Override void stop(Runnable callback); @Override void start(); @Override void stop(); @Override boolean isRunning(); @Override int getPhase();  }