Skip to content

Commit

Permalink
OAP-128 SSO: verify user validity during cookie validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nofateg authored May 8, 2024
1 parent 81a20cb commit a170ad0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
18 changes: 10 additions & 8 deletions oap-ws/oap-ws-sso-api/src/main/java/oap/ws/sso/UserProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
import java.util.function.Function;

public interface UserProvider {
Optional<? extends User> getUser( String email );

Result<? extends User, AuthenticationFailure> getAuthenticated( String email, String password, Optional<String> tfaCode );

Result<? extends User, AuthenticationFailure> getAuthenticated( String email, Optional<String> tfaCode );

Optional<? extends User> 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 };
Expand All @@ -60,4 +52,14 @@ static String toAccessKey( String email ) {
}
return result.toString();
}

Optional<? extends User> getUser( String email );

Result<? extends User, String> getValidUser( String email );

Result<? extends User, AuthenticationFailure> getAuthenticated( String email, String password, Optional<String> tfaCode );

Result<? extends User, AuthenticationFailure> getAuthenticated( String email, Optional<String> tfaCode );

Optional<? extends User> getAuthenticatedByApiKey( String accessKey, String apiKey );
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,11 +88,11 @@ public Optional<Response> 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<? extends User, String> 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<WsSecurity> wss = context.method.findAnnotation( WsSecurity.class );
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</distributionManagement>

<properties>
<oap.project.version>22.1.5</oap.project.version>
<oap.project.version>22.2.0</oap.project.version>

<oap.deps.config.version>21.0.0</oap.deps.config.version>
<oap.deps.oap-teamcity.version>21.0.1</oap.deps.oap-teamcity.version>
Expand Down

0 comments on commit a170ad0

Please sign in to comment.