Skip to content

Instantly share code, notes, and snippets.

@knd
Created August 11, 2014 16:33
Show Gist options
  • Save knd/490cd143aea32fbf22e3 to your computer and use it in GitHub Desktop.
Save knd/490cd143aea32fbf22e3 to your computer and use it in GitHub Desktop.
AccessManager Contructor
@SuppressWarnings("unchecked")
private AccessManager(String backingStore, int accessTokenTtl,
TimeUnit accessTokenTtlUnit) {
this.backingStore = backingStore;
this.tokenManager = AccessTokenManager.create(
accessTokenTtl, accessTokenTtlUnit);
ByteBuffer tableBytes = FileSystem.readBytes(backingStore);
ByteArrayInputStream bais = new ByteArrayInputStream(
ByteBuffers.toByteArray(tableBytes));
try {
BufferedInputStream bis = new BufferedInputStream(bais);
ObjectInput input = new ObjectInputStream(bis);
credentials = (Table<Short, String, Object>) input.readObject();
} catch (IOException e) {
throw Throwables.propagate(e);
} catch (ClassNotFoundException e) {
throw Throwables.propagate(e);
}
// If there are no credentials (which implies this is a new server) add
// the default admin username/password
if(credentials.isEmpty()) {
createUser(ByteBuffers.decodeFromHex(ADMIN_USERNAME),
ByteBuffers.decodeFromHex(ADMIN_PASSWORD));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment