Skip to content

Commit

Permalink
Add more to auth api (#851)
Browse files Browse the repository at this point in the history
* Added more classes to api.auth package,  removed dep on slf4j-api  from services-api
  • Loading branch information
artem-v authored Sep 28, 2024
1 parent f56e900 commit 7b6fda5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 28 deletions.
4 changes: 0 additions & 4 deletions services-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

</project>
16 changes: 5 additions & 11 deletions services-api/src/main/java/io/scalecube/services/ServiceCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@
import java.util.Optional;
import java.util.function.Function;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public class ServiceCall {

private static final Logger LOGGER = LoggerFactory.getLogger(ServiceCall.class);

private ClientTransport transport;
private ServiceRegistry serviceRegistry;
private Router router;
Expand Down Expand Up @@ -355,14 +351,12 @@ private ServiceMessage toServiceMessage(MethodInfo methodInfo, Object request) {
.build();
}

private ServiceUnavailableException noReachableMemberException(ServiceMessage request) {
LOGGER.error(
"Failed to invoke service, "
+ "No reachable member with such service definition [{}], args [{}]",
request.qualifier(),
request);
private static ServiceUnavailableException noReachableMemberException(ServiceMessage request) {
return new ServiceUnavailableException(
"No reachable member with such service: " + request.qualifier());
"No reachable member with such service: "
+ request.qualifier()
+ ", failed request: "
+ request);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.scalecube.services.auth;

import java.util.Map;
import reactor.core.publisher.Mono;

public interface CredentialsSupplier {

Mono<Map<String, String>> credentials(Map<String, String> tags);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.scalecube.services.auth;

public interface CredentialsSuppliers {

CredentialsSupplier forServiceRole(String serviceRole);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
import java.util.Optional;
import java.util.StringJoiner;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;

public final class ServiceMethodInvoker {

private static final Logger LOGGER = LoggerFactory.getLogger(ServiceMethodInvoker.class);

private final Method method;
private final Object service;
private final MethodInfo methodInfo;
Expand Down Expand Up @@ -164,7 +160,6 @@ private Mono<Object> authenticate(ServiceMessage message, Context context) {
if (context.hasKey(AUTH_CONTEXT_KEY)) {
return Mono.just(context.get(AUTH_CONTEXT_KEY));
} else {
LOGGER.error("Authentication failed (auth context not found and authenticator not set)");
throw new UnauthorizedException("Authentication failed");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package io.scalecube.services.routing;

import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.Exceptions;

public final class Routers {
private static final Logger LOGGER = LoggerFactory.getLogger(Routers.class);

private static final ConcurrentHashMap<Class<? extends Router>, Router> routers =
new ConcurrentHashMap<>();
Expand All @@ -28,7 +25,6 @@ private static Router create(Class<? extends Router> routerType) {
try {
return routerType.newInstance();
} catch (Exception ex) {
LOGGER.error("Create router type: {} failed: {}", routerType, ex);
throw Exceptions.propagate(ex);
}
}
Expand Down
9 changes: 7 additions & 2 deletions services/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -22,7 +24,10 @@
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.jctools</groupId>
<artifactId>jctools-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.scalecube.services.api.ServiceMessage;
import io.scalecube.services.discovery.ScalecubeServiceDiscovery;
import io.scalecube.services.exceptions.ServiceException;
import io.scalecube.services.exceptions.ServiceUnavailableException;
import io.scalecube.services.registry.api.ServiceRegistry;
import io.scalecube.services.routing.RoundRobinServiceRouter;
import io.scalecube.services.sut.EmptyGreetingResponse;
Expand Down Expand Up @@ -183,8 +184,11 @@ public void test_async_greeting_return_string_service_not_found_error_case() {
Mono.from(service.requestOne(NOT_FOUND_REQ)).block(timeout);
fail("Expected no-service-found exception");
} catch (Exception ex) {
assertEquals(
ex.getMessage(), "No reachable member with such service: " + NOT_FOUND_REQ.qualifier());
assertEquals(ServiceUnavailableException.class, ex.getClass());
assertNotNull(ex.getMessage());
assertTrue(
ex.getMessage()
.startsWith("No reachable member with such service: " + NOT_FOUND_REQ.qualifier()));
}
}

Expand Down

0 comments on commit 7b6fda5

Please sign in to comment.