- 
                Notifications
    
You must be signed in to change notification settings  - Fork 671
 
jwt blacklist stop play/publish using jwt #4847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
fc28eed
              7543ea1
              02841c6
              2f5971d
              9002d6c
              2fc0ea8
              c128bc6
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -9,8 +9,11 @@ | |
| import java.util.Map; | ||
| import java.util.Map.Entry; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.regex.Pattern; | ||
| 
     | 
||
| import io.antmedia.rest.model.Result; | ||
| import io.antmedia.security.ITokenService; | ||
| import org.apache.commons.io.FilenameUtils; | ||
| import org.apache.commons.lang3.RandomStringUtils; | ||
| import org.apache.commons.lang3.exception.ExceptionUtils; | ||
| 
          
            
          
           | 
    @@ -41,6 +44,8 @@ public abstract class MapBasedDataStore extends DataStore { | |
| protected Map<String, String> vodMap; | ||
| protected Map<String, String> detectionMap; | ||
| protected Map<String, String> tokenMap; | ||
| protected Map<String, String> tokenBlacklistMap; | ||
| 
     | 
||
| protected Map<String, String> subscriberMap; | ||
| protected Map<String, String> conferenceRoomMap; | ||
| protected Map<String, String> webRTCViewerMap; | ||
| 
          
            
          
           | 
    @@ -943,6 +948,65 @@ public boolean deleteToken(String tokenId) { | |
| return result; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public boolean deleteTokenFromBlacklist(String tokenId) { | ||
| boolean result; | ||
| 
     | 
||
| synchronized (this) { | ||
| result = tokenBlacklistMap.remove(tokenId) != null; | ||
| } | ||
| return result; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public List<String> getJwtBlacklist(){ | ||
| 
     | 
||
| synchronized (this){ | ||
| return new ArrayList<>(tokenBlacklistMap.keySet()); | ||
| 
     | 
||
| } | ||
| 
     | 
||
| } | ||
| 
     | 
||
| @Override | ||
| public Result deleteAllExpiredJwtFromBlacklist(ITokenService tokenService){ | ||
| logger.info("Deleting all expired JWTs from black list."); | ||
| AtomicInteger deletedTokenCount = new AtomicInteger(); | ||
| 
     | 
||
| synchronized (this){ | ||
| tokenBlacklistMap.forEach((key, value) -> { | ||
| Token token = gson.fromJson(value,Token.class); | ||
| String tokenId = token.getTokenId(); | ||
| if(!tokenService.verifyJwt(tokenId,token.getStreamId(),token.getType())){ | ||
| if(deleteTokenFromBlacklist(tokenId)){ | ||
| deletedTokenCount.getAndIncrement(); | ||
| }else{ | ||
| logger.warn("Couldn't delete JWT:{}", tokenId); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| 
     | 
||
| if(deletedTokenCount.get() > 0){ | ||
| final String successMsg = deletedTokenCount+" JWT deleted successfully from black list."; | ||
| logger.info(successMsg); | ||
| return new Result(true, successMsg); | ||
| }else{ | ||
| final String failMsg = "No JWT deleted from black list."; | ||
| logger.warn(failMsg); | ||
| return new Result(false, failMsg); | ||
| 
     | 
||
| } | ||
| 
     | 
||
| } | ||
| 
     | 
||
| @Override | ||
| public void clearJwtBlacklist(){ | ||
| synchronized (this) { | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using   | 
||
| tokenBlacklistMap.clear(); | ||
| } | ||
| } | ||
| 
     | 
||
| @Override | ||
| public Token getToken(String tokenId) { | ||
| return super.getToken(tokenMap, tokenId, gson); | ||
| 
          
            
          
           | 
    @@ -1055,4 +1119,30 @@ public Broadcast getBroadcastFromMap(String streamId) | |
| return null; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public boolean addTokenToBlacklist(Token token) { | ||
| boolean result = false; | ||
| 
     | 
||
| synchronized (this) { | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd revisit the usage of  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree  | 
||
| 
     | 
||
| if (token.getStreamId() != null && token.getTokenId() != null) { | ||
| 
     | 
||
| try { | ||
| tokenBlacklistMap.put(token.getTokenId(), gson.toJson(token)); | ||
| result = true; | ||
| } catch (Exception e) { | ||
| logger.error(ExceptionUtils.getStackTrace(e)); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| 
     | 
||
| } | ||
| 
     | 
||
| @Override | ||
| public Token getTokenFromBlacklist(String tokenId) { | ||
| return super.getToken(tokenBlacklistMap, tokenId, gson); | ||
| 
     | 
||
| } | ||
| 
     | 
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THREAD_SAFETY_VIOLATION: Read/Write race. Non-private method
MapBasedDataStore.deleteAllExpiredJwtFromBlacklist(...)reads without synchronization from containerthis.tokenBlacklistMapvia call toMap.forEach(...). Potentially races with write in methodMapBasedDataStore.deleteTokenFromBlacklist(...).Reporting because another access to the same memory occurs on a background thread, although this access may not.
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore@sonatype-lift ignoreall@sonatype-lift exclude <file|issue|path|tool>file|issue|path|toolfrom Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Help us improve LIFT! (Sonatype LiftBot external survey)
Was this a good recommendation for you? Answering this survey will not impact your Lift settings.
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]