[
https://issues.apache.org/jira/browse/KNOX-2650?focusedWorklogId=643325&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-643325
]
ASF GitHub Bot logged work on KNOX-2650:
----------------------------------------
Author: ASF GitHub Bot
Created on: 30/Aug/21 08:03
Start Date: 30/Aug/21 08:03
Worklog Time Spent: 10m
Work Description: smolnar82 commented on a change in pull request #486:
URL: https://github.com/apache/knox/pull/486#discussion_r698049332
##########
File path:
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateDatabase.java
##########
@@ -192,24 +191,34 @@ TokenMetadata getTokenMetadata(String tokenId) throws
SQLException {
final Map<String, String> metadataMap = new HashMap<>();
while (rs.next()) {
String metadataName = rs.getString(1);
- metadataMap.put(metadataName,
metadataName.equals(TokenMetadata.PASSCODE) ? new
String(Base64.decodeBase64(rs.getString(2).getBytes(UTF_8)), UTF_8) :
rs.getString(2));
+ metadataMap.put(metadataName, decodeMetadata(metadataName,
rs.getString(2)));
}
return metadataMap.isEmpty() ? null : new TokenMetadata(metadataMap);
}
}
}
+ private static String decodeMetadata(String metadataName, String
metadataValue) {
+ return metadataName.equals(TokenMetadata.PASSCODE) ? new
String(Base64.decodeBase64(metadataValue.getBytes(UTF_8)), UTF_8) :
metadataValue;
+ }
+
Collection<KnoxToken> getTokens(String userName) throws SQLException {
- final Collection<KnoxToken> tokens = new TreeSet<>();
+ Map<String, KnoxToken> tokenMap = new LinkedHashMap<>();
try (Connection connection = dataSource.getConnection(); PreparedStatement
getTokenIdsStatement =
connection.prepareStatement(GET_TOKENS_BY_USER_NAME_SQL)) {
getTokenIdsStatement.setString(1, userName);
try (ResultSet rs = getTokenIdsStatement.executeQuery()) {
while(rs.next()) {
- tokens.add(new KnoxToken(rs.getString(1), rs.getLong(2),
rs.getLong(3), rs.getLong(4)));
+ String tokenId = rs.getString(1);
+ long issueTime = rs.getLong(2);
+ long expiration = rs.getLong(3);
+ long maxLifeTime = rs.getLong(4);
+ String metaName = rs.getString(5);
+ String metaValue = rs.getString(6);
+ KnoxToken token = tokenMap.computeIfAbsent(tokenId, id -> new
KnoxToken(tokenId, issueTime, expiration, maxLifeTime));
Review comment:
There is a KnoxToken constructor that takes a TokenMetadata; I'd use
that one and remove the constructor being used here (in fact I added the one
w/o metadata to support the 'poor performance' getTokens method which you are
fixing now).
In that case, a simple TressEt is enough instead of the LinkedHashMap.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 643325)
Time Spent: 1h 20m (was: 1h 10m)
> Loading token management page can be slow if there are lots of tokens
> ---------------------------------------------------------------------
>
> Key: KNOX-2650
> URL: https://issues.apache.org/jira/browse/KNOX-2650
> Project: Apache Knox
> Issue Type: Task
> Reporter: Attila Magyar
> Assignee: Attila Magyar
> Priority: Major
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)