use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class UserServiceTest method testServiceTokenInvalidation.
@Test
public void testServiceTokenInvalidation() {
AccessToken token = service.tokens.issueServiceToken();
service.tokens.expire(token);
Assert.assertFalse(service.tokens.isValid(token));
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class UserServiceTest method testAccessTokenIsNotValidIfPasswordChanges.
@Test
public void testAccessTokenIsNotValidIfPasswordChanges() {
ByteBuffer username = getAcceptableUsername();
ByteBuffer password = getSecurePassword();
ByteBuffer password2 = getSecurePassword();
service.create(username, password, Role.ADMIN);
AccessToken token = service.tokens.issue(username);
service.setPassword(username, password2);
Assert.assertFalse(service.tokens.isValid(token));
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class UserServiceTest method testRevokingAccessInvalidatesAllAccessTokens.
@Test
public void testRevokingAccessInvalidatesAllAccessTokens() {
ByteBuffer username = getAcceptableUsername();
ByteBuffer password = getSecurePassword();
service.create(username, password, Role.ADMIN);
List<AccessToken> tokens = Lists.newArrayList();
for (int i = 0; i < TestData.getScaleCount(); i++) {
tokens.add(service.tokens.issue(username));
}
service.delete(username);
for (AccessToken token : tokens) {
Assert.assertFalse(service.tokens.isValid(token));
}
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class UserServiceTest method testAccessTokenAutoExpiration.
@Test
public void testAccessTokenAutoExpiration() throws InterruptedException {
service = UserService.createForTesting(current, 60, TimeUnit.MILLISECONDS);
ByteBuffer username = getAcceptableUsername();
ByteBuffer password = getSecurePassword();
service.create(username, password, Role.ADMIN);
AccessToken token = service.tokens.issue(username);
TimeUnit.MILLISECONDS.sleep(60);
Assert.assertFalse(service.tokens.isValid(token));
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class ConcourseServer method init.
/**
* Initialize this instance. This method MUST always be called after
* constructing the instance.
*
* @param port - the port on which to listen for client connections
* @param bufferStore - the location to store {@link Buffer} files
* @param dbStore - the location to store {@link Database} files
* @throws TTransportException
*/
@Internal
private void init(int port, String bufferStore, String dbStore) throws TTransportException {
Preconditions.checkState(!bufferStore.equalsIgnoreCase(dbStore), "Cannot store buffer and database files in the same directory. " + "Please check concourse.prefs.");
Preconditions.checkState(!Strings.isNullOrEmpty(Environments.sanitize(DEFAULT_ENVIRONMENT)), "Cannot initialize " + "Concourse Server with a default environment of " + "'%s'. Please use a default environment name that " + "contains only alphanumeric characters.", DEFAULT_ENVIRONMENT);
FileSystem.mkdirs(bufferStore);
FileSystem.mkdirs(dbStore);
FileSystem.lock(bufferStore);
FileSystem.lock(dbStore);
TServerSocket socket = new TServerSocket(port);
TMultiplexedProcessor processor = new TMultiplexedProcessor();
TProcessor core = new ConcourseService.Processor<>(this);
processor.registerProcessor("core", core);
processor.registerProcessor("calculate", new ConcourseCalculateService.Processor<>(this));
processor.registerProcessor("navigate", new ConcourseNavigateService.Processor<>(this));
processor.registerDefault(core);
Args args = new TThreadPoolServer.Args(socket);
args.processor(processor);
args.maxWorkerThreads(NUM_WORKER_THREADS);
args.executorService(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Client Worker" + " %d").build()));
// CON-530: Set a lower timeout on the ExecutorService's termination to
// prevent the server from hanging because of active threads that have
// not yet been given a task but won't allow shutdown to proceed (i.e.
// clients from a ConnectionPool).
args.stopTimeoutVal(2);
this.server = new TThreadPoolServer(args);
this.bufferStore = bufferStore;
this.dbStore = dbStore;
this.engines = Maps.newConcurrentMap();
this.users = UserService.create(ACCESS_CREDENTIALS_FILE);
this.inspector = new Inspector() {
@Override
public Role getTokenUserRole(AccessToken token) {
ByteBuffer username = users.tokens.identify(token);
return users.getRole(username);
}
@Override
public boolean isValidToken(AccessToken token) {
return users.tokens.isValid(token);
}
@Override
public boolean isValidTransaction(TransactionToken transaction) {
return transactions.containsKey(transaction);
}
@Override
public boolean tokenUserHasPermission(AccessToken token, Permission permission, String environment) {
ByteBuffer username = users.tokens.identify(token);
return users.can(username, permission, Environments.sanitize(environment));
}
};
this.httpServer = GlobalState.HTTP_PORT > 0 ? HttpServer.create(this, GlobalState.HTTP_PORT) : HttpServer.disabled();
// load the default engine
getEngine();
this.pluginManager = new PluginManager(this, GlobalState.CONCOURSE_HOME + File.separator + "plugins");
// Setup the management server
TServerSocket mgmtSocket = new TServerSocket(GlobalState.MANAGEMENT_PORT);
TSimpleServer.Args mgmtArgs = new TSimpleServer.Args(mgmtSocket);
mgmtArgs.processor(new ConcourseManagementService.Processor<>(this));
this.mgmtServer = new TSimpleServer(mgmtArgs);
}
Aggregations