use of io.scalecube.services.exceptions.UnauthorizedException in project scalecube by scalecube.
the class PrincipalMapperAuthExample method authenticateUserProfile.
private static Mono<Map<String, String>> authenticateUserProfile(Map<String, String> headers) {
String username = headers.get("username");
String password = headers.get("password");
if ("Alice".equals(username) && "qwerty".equals(password)) {
HashMap<String, String> authData = new HashMap<>();
authData.put("name", "Alice");
authData.put("role", "ADMIN");
return Mono.just(authData);
}
return Mono.error(new UnauthorizedException("Authentication failed (username or password incorrect)"));
}
use of io.scalecube.services.exceptions.UnauthorizedException in project scalecube by scalecube.
the class PrincipalMapperAuthExample method authenticateApiKey.
private static Mono<Map<String, String>> authenticateApiKey(Map<String, String> headers) {
String apiKey = headers.get("apiKey");
if ("jasds8fjasdfjasd89fa4k9rjn7ahdfasduf".equals(apiKey)) {
HashMap<String, String> authData = new HashMap<>();
authData.put("id", "jasds8fjasdfjasd89fa4k9rjn7ahdfasduf");
authData.put("permissions", "OPERATIONS:EVENTS:ACTIONS");
return Mono.just(authData);
}
return Mono.error(new UnauthorizedException("Authentication failed (apiKey incorrect)"));
}
Aggregations