Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2015 Zalando SE (http://tech.zalando.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.zalando.stups.tokens;
 
 import java.io.File;
 
 
 
 import  org.springframework.context.SmartLifecycle;
 

Author(s):
jbellmann
 
 public class AccessTokensBean implements AccessTokens, SmartLifecycle {
 
     private final Logger logger = LoggerFactory.getLogger(AccessTokensBean.class);
 
 
 
     private volatile boolean running = false;
 
     public AccessTokensBean(final AccessTokensBeanProperties accessTokensBeanProperties) {
         this. = accessTokensBeanProperties;
     }
 
     @Override
     public String get(final Object tokenIdthrows AccessTokenUnavailableException {
         try {
 
             return .get(tokenId);
         } catch (AccessTokenUnavailableException e) {
             .error("Token unavailable for service : {}"tokenId.toString());
             throw e;
         }
     }
 
     @Override
     public AccessToken getAccessToken(final Object tokenIdthrows AccessTokenUnavailableException {
         try {
 
             return .getAccessToken(tokenId);
         } catch (AccessTokenUnavailableException e) {
             .error("Token unavailable for service : {}"tokenId.toString());
             throw e;
         }
     }
 
     @Override
     public void invalidate(final Object tokenId) {
         .invalidate(tokenId);
     }
 
 
                     .getUserCredentialsFilename()));
     }
 
 
                     .getClientCredentialsFilename()));
     }
 
     protected File getCredentialsFile(final String credentialsFilename) {
         return new File(.getCredentialsDirectory(), credentialsFilename);
     }
 
     @Override
     public synchronized void start() {
         if (isRunning()) {
             return;
         }
 
         .info("Container seems up an running");
 
         // TODO, if something fails here, shall we shutdown the container?
            .info("configure scopes for service {}"tc.getTokenId());
            AccessTokenConfiguration configuration = builder.manageToken(tc.getTokenId());
            configuration.addScopes(new HashSet<Object>(tc.getScopes()));
        }
        .info("Start 'accessTokenRefresher' ...");
         = builder.start();
         = true;
        .info("'accessTokenRefresher' started.");
    }
    @Override
    public synchronized void stop() {
        if (!isRunning()) {
            return;
        }
        .info("Stop 'accessTokenRefresher' ...");
        .stop();
         = false;
        .info("'accessTokenRefresher' stopped.");
    }
    @Override
    public boolean isRunning() {
        return ;
    }
    @Override
    public int getPhase() {
        // default
        return 0;
    }
    @Override
    public boolean isAutoStartup() {
        return true;
    }
    @Override
    public void stop(final Runnable callback) {
        stop();
        callback.run();
    }
New to GrepCode? Check out our FAQ X