use of org.apache.knox.gateway.services.security.token.KnoxToken in project knox by apache.
the class DefaultTokenStateService method getTokens.
@Override
public Collection<KnoxToken> getTokens(String userName) {
final Collection<KnoxToken> tokens = new TreeSet<>();
metadataMap.entrySet().stream().filter(entry -> entry.getValue().getUserName().equals(userName)).forEach(metadata -> {
String tokenId = metadata.getKey();
try {
tokens.add(new KnoxToken(tokenId, getTokenIssueTime(tokenId), getTokenExpiration(tokenId), getMaxLifetime(tokenId), metadata.getValue()));
} catch (UnknownTokenException e) {
// NOP: since this is coming from memory the only reason an UTE is thrown that the token got removed/revoked.
// In that case we would not want to return it anyway
}
});
return tokens;
}
use of org.apache.knox.gateway.services.security.token.KnoxToken in project knox by apache.
the class TokenStateDatabase method getTokens.
Collection<KnoxToken> getTokens(String userName) throws SQLException {
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()) {
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));
token.addMetadata(metaName, decodeMetadata(metaName, metaValue));
}
return tokenMap.values();
}
}
}
Aggregations