Search in sources :

Example 1 with Tokens

use of org.apache.knox.gateway.util.Tokens 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;
}
Also used : KnoxToken(org.apache.knox.gateway.services.security.token.KnoxToken) MessagesFactory(org.apache.knox.gateway.i18n.messages.MessagesFactory) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) JWT(org.apache.knox.gateway.services.security.token.impl.JWT) TokenMetadata(org.apache.knox.gateway.services.security.token.TokenMetadata) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) JWTToken(org.apache.knox.gateway.services.security.token.impl.JWTToken) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) Tokens(org.apache.knox.gateway.util.Tokens) UnknownTokenException(org.apache.knox.gateway.services.security.token.UnknownTokenException) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MBeanRegistrationException(javax.management.MBeanRegistrationException) ManagementFactory(java.lang.management.ManagementFactory) TokenStateServiceStatistics(org.apache.knox.gateway.services.token.TokenStateServiceStatistics) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ObjectName(javax.management.ObjectName) Instant(java.time.Instant) TokenUtils(org.apache.knox.gateway.services.security.token.TokenUtils) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TokenStateService(org.apache.knox.gateway.services.security.token.TokenStateService) TimeUnit(java.util.concurrent.TimeUnit) MalformedObjectNameException(javax.management.MalformedObjectNameException) List(java.util.List) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Collections(java.util.Collections) TreeSet(java.util.TreeSet) KnoxToken(org.apache.knox.gateway.services.security.token.KnoxToken) UnknownTokenException(org.apache.knox.gateway.services.security.token.UnknownTokenException)

Aggregations

ManagementFactory (java.lang.management.ManagementFactory)1 Instant (java.time.Instant)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 ObjectName (javax.management.ObjectName)1 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)1