use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class BlobStoreAPIWordCountTopology method main.
public static void main(String[] args) {
prepare();
BlobStoreAPIWordCountTopology wc = new BlobStoreAPIWordCountTopology();
try {
File file = createFile(fileName);
// Creating blob again before launching topology
createBlobWithContent(key, store, file);
// Blostore launch command with topology blobstore map
// Here we are giving it a local name so that we can read from the file
// bin/storm jar examples/storm-starter/storm-starter-topologies-0.11.0-SNAPSHOT.jar
// org.apache.storm.starter.BlobStoreAPIWordCountTopology bl -c
// topology.blobstore.map='{"key":{"localname":"blacklist.txt", "uncompress":"false"}}'
wc.buildAndLaunchWordCountTopology(args);
// Updating file few times every 5 seconds
for (int i = 0; i < 10; i++) {
updateBlobWithContent(key, store, updateFile(file));
Utils.sleep(5000);
}
} catch (KeyAlreadyExistsException kae) {
LOG.info("Key already exists {}", kae);
} catch (AuthorizationException | KeyNotFoundException | IOException exp) {
throw new RuntimeException(exp);
}
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class BlobStoreAclHandler method hasAnyPermissions.
/**
* Validates if the user has any of the permissions
* mentioned in the mask.
* @param acl ACL for the key.
* @param mask mask holds the cumulative value of
* READ = 1, WRITE = 2 or ADMIN = 4 permissions.
* mask = 1 implies READ privilege.
* mask = 5 implies READ and ADMIN privileges.
* @param who Is the user against whom the permissions
* are validated for a key using the ACL and the mask.
* @param key Key used to identify the blob.
* @throws AuthorizationException
*/
public void hasAnyPermissions(List<AccessControl> acl, int mask, Subject who, String key) throws AuthorizationException {
if (!doAclValidation) {
return;
}
Set<String> user = constructUserFromPrincipals(who);
LOG.debug("user {}", user);
if (checkForValidUsers(who, mask)) {
return;
}
for (AccessControl ac : acl) {
int allowed = getAllowed(ac, user);
LOG.debug(" user: {} allowed: {} key: {}", user, allowed, key);
if ((allowed & mask) > 0) {
return;
}
}
throw new AuthorizationException(user + " does not have access to " + key);
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class Nimbus method uploadChunk.
@SuppressWarnings("deprecation")
@Override
public void uploadChunk(String location, ByteBuffer chunk) throws AuthorizationException, TException {
try {
uploadChunkCalls.mark();
checkAuthorization(null, null, "fileUpload");
WritableByteChannel channel = uploaders.get(location);
if (channel == null) {
throw new RuntimeException("File for that location does not exist (or timed out)");
}
channel.write(chunk);
uploaders.put(location, channel);
} catch (Exception e) {
LOG.warn("uploadChunk exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class Nimbus method uploadNewCredentials.
@Override
public void uploadNewCredentials(String topoName, Credentials credentials) throws NotAliveException, InvalidTopologyException, AuthorizationException, TException {
try {
uploadNewCredentialsCalls.mark();
IStormClusterState state = stormClusterState;
String topoId = toTopoId(topoName);
if (topoId == null) {
throw new NotAliveException(topoName + " is not alive");
}
Map<String, Object> topoConf = tryReadTopoConf(topoId, blobStore);
if (credentials == null) {
credentials = new Credentials(Collections.emptyMap());
}
checkAuthorization(topoName, topoConf, "uploadNewCredentials");
synchronized (credUpdateLock) {
state.setCredentials(topoId, credentials, topoConf);
}
} catch (Exception e) {
LOG.warn("Upload Creds topology exception. (topology name='{}')", topoName, e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class Nimbus method downloadBlobChunk.
@SuppressWarnings("deprecation")
@Override
public ByteBuffer downloadBlobChunk(String session) throws AuthorizationException, TException {
try {
BufferInputStream is = blobDownloaders.get(session);
if (is == null) {
throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)");
}
byte[] ret = is.read();
if (ret.length == 0) {
is.close();
blobDownloaders.remove(session);
} else {
blobDownloaders.put(session, is);
}
LOG.debug("Sending {} bytes", ret.length);
return ByteBuffer.wrap(ret);
} catch (Exception e) {
LOG.warn("download blob chunk exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
Aggregations