-
Notifications
You must be signed in to change notification settings - Fork 664
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 all commits
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; | ||
|
@@ -943,6 +946,79 @@ public boolean deleteToken(String tokenId) { | |
return result; | ||
} | ||
|
||
@Override | ||
public boolean whiteListToken(String tokenId) { | ||
synchronized (this){ | ||
Token token = getToken(tokenId); | ||
if(token != null && token.isBlackListed()){ | ||
token.setBlackListed(false); | ||
return saveToken(token); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> getBlackListedTokens(){ | ||
ArrayList<String> tokenBlacklist = new ArrayList<>(); | ||
synchronized (this){ | ||
tokenMap.forEach((tokenId, tokenAsJson) -> { | ||
Token token = gson.fromJson(tokenAsJson,Token.class); | ||
if(token.isBlackListed()){ | ||
tokenBlacklist.add(tokenId); | ||
} | ||
}); | ||
return tokenBlacklist; | ||
} | ||
} | ||
|
||
@Override | ||
public Result deleteAllBlacklistedExpiredTokens(ITokenService tokenService){ | ||
logger.info("Deleting all expired JWTs from token storage."); | ||
AtomicInteger deletedTokenCount = new AtomicInteger(); | ||
|
||
synchronized (this) { | ||
|
||
tokenMap.forEach((tokenId, tokenAsJson) -> { | ||
Token token = gson.fromJson(tokenAsJson,Token.class); | ||
if(token.isBlackListed() && !tokenService.verifyJwt(tokenId,token.getStreamId(),token.getType())){ | ||
if(deleteToken(tokenId)){ | ||
deletedTokenCount.getAndIncrement(); | ||
}else{ | ||
logger.warn("Couldn't delete JWT:{}", tokenId); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
if(deletedTokenCount.get() > 0){ | ||
final String successMsg = deletedTokenCount+" JWT deleted successfully from storage."; | ||
logger.info(successMsg); | ||
return new Result(true, successMsg); | ||
}else{ | ||
final String failMsg = "No JWT deleted from storage."; | ||
logger.warn(failMsg); | ||
return new Result(false, failMsg); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public boolean whiteListAllTokens(){ | ||
|
||
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 |
||
tokenMap.forEach((tokenId, tokenAsJson) -> { | ||
Token token = gson.fromJson(tokenAsJson,Token.class); | ||
if(token.isBlackListed()){ | ||
whiteListToken(tokenId); | ||
} | ||
}); | ||
} | ||
return true; | ||
|
||
} | ||
|
||
@Override | ||
public Token getToken(String tokenId) { | ||
return super.getToken(tokenMap, tokenId, gson); | ||
|
@@ -1074,4 +1150,28 @@ public Broadcast getBroadcastFromMap(String streamId) | |
return null; | ||
} | ||
|
||
@Override | ||
public boolean blackListToken(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) { | ||
token.setBlackListed(true); | ||
return saveToken(token); | ||
} | ||
} | ||
return result; | ||
|
||
} | ||
|
||
@Override | ||
public Token getBlackListedToken(String tokenId) { | ||
Token token = getToken(tokenId); | ||
if(token != null && token.isBlackListed()){ | ||
return token; | ||
} | ||
return null; | ||
} | ||
|
||
} |
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.
The concept of allowing only people with valid tokens is implicitly a whitelist, so I think you should not give the impression that there is a separate whitelist and a blacklist. Is it not only clearing the blacklist..?