use of datawave.security.authorization.DatawavePrincipal in project datawave by NationalSecurityAgency.
the class AuthorizationsUtilTest method initialize.
@Before
public void initialize() {
System.setProperty(NpeUtils.NPE_OU_PROPERTY, "iamnotaperson");
methodAuths = "A,C";
userAuths = new HashSet<>();
userAuths.add(Sets.newHashSet("A", "C", "D"));
userAuths.add(Sets.newHashSet("A", "B", "E"));
SubjectIssuerDNPair userDN = SubjectIssuerDNPair.of(USER_DN, ISSUER_DN);
SubjectIssuerDNPair p1dn = SubjectIssuerDNPair.of("entity1UserDN", "entity1IssuerDN");
SubjectIssuerDNPair p2dn = SubjectIssuerDNPair.of("entity2UserDN", "entity2IssuerDN");
SubjectIssuerDNPair p3dn = SubjectIssuerDNPair.of("entity3UserDN", "entity3IssuerDN");
DatawaveUser user = new DatawaveUser(userDN, UserType.USER, Sets.newHashSet("A", "C", "D"), null, null, System.currentTimeMillis());
DatawaveUser p1 = new DatawaveUser(p1dn, UserType.SERVER, Sets.newHashSet("A", "B", "E"), null, null, System.currentTimeMillis());
DatawaveUser p2 = new DatawaveUser(p2dn, UserType.SERVER, Sets.newHashSet("A", "F", "G"), null, null, System.currentTimeMillis());
DatawaveUser p3 = new DatawaveUser(p3dn, UserType.SERVER, Sets.newHashSet("A", "B", "G"), null, null, System.currentTimeMillis());
proxiedUserPrincipal = new DatawavePrincipal(Lists.newArrayList(user, p1, p2));
proxiedServerPrincipal1 = new DatawavePrincipal(Lists.newArrayList(p1, p3));
proxiedServerPrincipal2 = new DatawavePrincipal(Lists.newArrayList(p1, p2, p3));
}
use of datawave.security.authorization.DatawavePrincipal in project datawave by NationalSecurityAgency.
the class CachedResultsBean method getOwnerFromPrincipal.
private String getOwnerFromPrincipal(Principal p) {
String owner = p.getName();
if (p instanceof DatawavePrincipal) {
DatawavePrincipal cp = (DatawavePrincipal) p;
owner = cp.getShortName();
}
return owner;
}
use of datawave.security.authorization.DatawavePrincipal in project datawave by NationalSecurityAgency.
the class AtomServiceBean method getCategories.
/**
* @return Atom Categories document that lists category names
*/
@GET
@GZIP
@Produces("application/atomcat+xml")
@Path("/categories")
public Categories getCategories() {
Principal p = ctx.getCallerPrincipal();
Set<Authorizations> auths = new HashSet<>();
if (p instanceof DatawavePrincipal) {
DatawavePrincipal dp = (DatawavePrincipal) p;
for (Collection<String> cbAuths : dp.getAuthorizations()) auths.add(new Authorizations(cbAuths.toArray(new String[cbAuths.size()])));
}
Categories result;
Connector connection = null;
try {
result = abdera.newCategories();
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
connection = connectionFactory.getConnection(poolName, Priority.NORMAL, trackingMap);
try (Scanner scanner = ScannerHelper.createScanner(connection, tableName + "Categories", auths)) {
Map<String, String> props = new HashMap<>();
props.put(MatchingKeySkippingIterator.ROW_DELIMITER_OPTION, "\0");
props.put(MatchingKeySkippingIterator.NUM_SCANS_STRING_NAME, "5");
IteratorSetting setting = new IteratorSetting(30, MatchingKeySkippingIterator.class, props);
scanner.addScanIterator(setting);
for (Map.Entry<Key, Value> entry : scanner) {
String collectionName = entry.getKey().getRow().toString();
result.addCategory(collectionName);
}
}
if (result.getCategories().isEmpty())
throw new NoResultsException(null);
else
return result;
} catch (WebApplicationException web) {
throw web;
} catch (Exception e) {
VoidResponse response = new VoidResponse();
QueryException qe = new QueryException(DatawaveErrorCode.COLLECTION_ERROR, e);
log.error(qe);
response.addException(qe.getBottomQueryException());
throw new DatawaveWebApplicationException(qe, response);
} finally {
if (null != connection) {
try {
connectionFactory.returnConnection(connection);
} catch (Exception e) {
log.error("Error returning connection to factory", e);
}
}
}
}
use of datawave.security.authorization.DatawavePrincipal in project datawave by NationalSecurityAgency.
the class MapReduceStatePersisterBean method find.
/**
* Returns all MapReduce jobs for the current user
*
* @return list of map reduce information
*/
public MapReduceInfoResponseList find() {
// Find out who/what called this method
Principal p = ctx.getCallerPrincipal();
String sid = p.getName();
Set<Authorizations> auths = new HashSet<>();
if (p instanceof DatawavePrincipal) {
DatawavePrincipal dp = (DatawavePrincipal) p;
sid = dp.getShortName();
for (Collection<String> cbAuths : dp.getAuthorizations()) auths.add(new Authorizations(cbAuths.toArray(new String[cbAuths.size()])));
}
log.trace(sid + " has authorizations " + auths);
MapReduceInfoResponseList result = new MapReduceInfoResponseList();
Connector c = null;
try {
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
c = connectionFactory.getConnection(AccumuloConnectionFactory.Priority.ADMIN, trackingMap);
tableCheck(c);
try (Scanner scanner = ScannerHelper.createScanner(c, TABLE_NAME, auths)) {
scanner.fetchColumnFamily(new Text(sid));
// We need to create a response for each job
String previousRow = sid;
Map<Key, Value> batch = new HashMap<>();
for (Entry<Key, Value> entry : scanner) {
if (!previousRow.equals(entry.getKey().getRow().toString()) && !batch.isEmpty()) {
MapReduceInfoResponse response = populateResponse(batch.entrySet());
if (null != response)
result.getResults().add(response);
batch.clear();
} else {
batch.put(entry.getKey(), entry.getValue());
}
previousRow = entry.getKey().getRow().toString();
}
if (!batch.isEmpty()) {
MapReduceInfoResponse response = populateResponse(batch.entrySet());
if (null != response)
result.getResults().add(response);
batch.clear();
}
return result;
}
} catch (IOException ioe) {
QueryException qe = new QueryException(DatawaveErrorCode.RESPONSE_POPULATION_ERROR, ioe);
log.error(qe);
result.addException(qe);
return result;
} catch (Exception e) {
QueryException qe = new QueryException(DatawaveErrorCode.QUERY_SETUP_ERROR, e);
log.error(qe);
result.addException(qe.getBottomQueryException());
return result;
} finally {
try {
connectionFactory.returnConnection(c);
} catch (Exception e) {
log.error("Error returning connection to connection pool", e);
}
}
}
use of datawave.security.authorization.DatawavePrincipal in project datawave by NationalSecurityAgency.
the class MapReduceStatePersisterBean method findById.
/**
* Information for a specific map reduce id
*
* @param id
* map reduce id
* @return list of map reduce information
*/
public MapReduceInfoResponseList findById(String id) {
// Find out who/what called this method
Principal p = ctx.getCallerPrincipal();
String sid = p.getName();
Set<Authorizations> auths = new HashSet<>();
if (p instanceof DatawavePrincipal) {
DatawavePrincipal dp = (DatawavePrincipal) p;
sid = dp.getShortName();
for (Collection<String> cbAuths : dp.getAuthorizations()) auths.add(new Authorizations(cbAuths.toArray(new String[cbAuths.size()])));
}
log.trace(sid + " has authorizations " + auths);
MapReduceInfoResponseList result = new MapReduceInfoResponseList();
Connector c = null;
try {
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
c = connectionFactory.getConnection(AccumuloConnectionFactory.Priority.ADMIN, trackingMap);
tableCheck(c);
try (Scanner scanner = ScannerHelper.createScanner(c, TABLE_NAME, auths)) {
Range range = new Range(id);
scanner.setRange(range);
scanner.fetchColumnFamily(new Text(sid));
MapReduceInfoResponse response = populateResponse(scanner);
if (null != response)
result.getResults().add(response);
return result;
}
} catch (IOException ioe) {
QueryException qe = new QueryException(DatawaveErrorCode.RESPONSE_POPULATION_ERROR, ioe);
log.error(qe);
result.addException(qe);
return result;
} catch (Exception e) {
QueryException qe = new QueryException(DatawaveErrorCode.QUERY_SETUP_ERROR, e);
log.error(qe);
result.addException(qe.getBottomQueryException());
return result;
} finally {
try {
connectionFactory.returnConnection(c);
} catch (Exception e) {
log.error("Error returning connection to connection pool", e);
}
}
}
Aggregations