diff --git a/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/UserProvider.java b/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/UserProvider.java index 56b73bee6f..a23b307419 100644 --- a/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/UserProvider.java +++ b/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/UserProvider.java @@ -30,14 +30,6 @@ import java.util.function.Function; public interface UserProvider { - Optional getUser( String email ); - - Result getAuthenticated( String email, String password, Optional tfaCode ); - - Result getAuthenticated( String email, Optional tfaCode ); - - Optional getAuthenticatedByApiKey( String accessKey, String apiKey ); - //eliminating most used letters in english from source static String toAccessKey( String email ) { int[] transitions = { 6, 11, 3, 10, 4, 1, 5, 0, 7, 2, 9, 8 }; @@ -60,4 +52,14 @@ static String toAccessKey( String email ) { } return result.toString(); } + + Optional getUser( String email ); + + Result getValidUser( String email ); + + Result getAuthenticated( String email, String password, Optional tfaCode ); + + Result getAuthenticated( String email, Optional tfaCode ); + + Optional getAuthenticatedByApiKey( String accessKey, String apiKey ); } diff --git a/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/interceptor/JWTSecurityInterceptor.java b/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/interceptor/JWTSecurityInterceptor.java index 1ecfc45e38..86f2d433f4 100644 --- a/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/interceptor/JWTSecurityInterceptor.java +++ b/oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/interceptor/JWTSecurityInterceptor.java @@ -25,6 +25,7 @@ package oap.ws.sso.interceptor; import lombok.extern.slf4j.Slf4j; +import oap.util.Result; import oap.ws.InvocationContext; import oap.ws.Response; import oap.ws.interceptor.Interceptor; @@ -87,11 +88,11 @@ public Optional before( InvocationContext context ) { final String email = jwtExtractor.getUserEmail( token ); organization = jwtExtractor.getOrganizationId( token ); - User user = userProvider.getUser( email ).orElse( null ); - if( user == null ) { - return Optional.of( new Response( FORBIDDEN, "User not found with email: " + email ) ); + Result validUser = userProvider.getValidUser( email ); + if( !validUser.isSuccess() ) { + return Optional.of( new Response( FORBIDDEN, validUser.failureValue ) ); } - context.session.set( SESSION_USER_KEY, user ); + context.session.set( SESSION_USER_KEY, validUser.successValue ); context.session.set( ISSUER, issuerName ); } Optional wss = context.method.findAnnotation( WsSecurity.class ); diff --git a/pom.xml b/pom.xml index fa06e9e5aa..acb0587e6a 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ - 22.1.5 + 22.2.0 21.0.0 21.0.1