Search in sources :

Example 1 with DatawavePrincipal

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));
}
Also used : SubjectIssuerDNPair(datawave.security.authorization.SubjectIssuerDNPair) DatawaveUser(datawave.security.authorization.DatawaveUser) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Before(org.junit.Before)

Example 2 with DatawavePrincipal

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;
}
Also used : DatawavePrincipal(datawave.security.authorization.DatawavePrincipal)

Example 3 with DatawavePrincipal

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);
            }
        }
    }
}
Also used : NoResultsException(datawave.webservice.common.exception.NoResultsException) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) Categories(org.apache.abdera.model.Categories) HashMap(java.util.HashMap) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) NoResultsException(datawave.webservice.common.exception.NoResultsException) QueryException(datawave.webservice.query.exception.QueryException) QueryException(datawave.webservice.query.exception.QueryException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) VoidResponse(datawave.webservice.result.VoidResponse) DefaultValue(javax.ws.rs.DefaultValue) Value(org.apache.accumulo.core.data.Value) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) Map(java.util.Map) HashMap(java.util.HashMap) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 4 with DatawavePrincipal

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);
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) MapReduceInfoResponseList(datawave.webservice.results.mr.MapReduceInfoResponseList) IOException(java.io.IOException) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) QueryException(datawave.webservice.query.exception.QueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) MapReduceInfoResponse(datawave.webservice.results.mr.MapReduceInfoResponse) Value(org.apache.accumulo.core.data.Value) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Example 5 with DatawavePrincipal

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);
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) MapReduceInfoResponseList(datawave.webservice.results.mr.MapReduceInfoResponseList) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) QueryException(datawave.webservice.query.exception.QueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) MapReduceInfoResponse(datawave.webservice.results.mr.MapReduceInfoResponse) Principal(java.security.Principal) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) HashSet(java.util.HashSet)

Aggregations

DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)93 DatawaveUser (datawave.security.authorization.DatawaveUser)41 Principal (java.security.Principal)37 HashSet (java.util.HashSet)33 Test (org.junit.Test)29 QueryException (datawave.webservice.query.exception.QueryException)24 Connector (org.apache.accumulo.core.client.Connector)23 IOException (java.io.IOException)19 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)18 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)18 Authorizations (org.apache.accumulo.core.security.Authorizations)17 Query (datawave.webservice.query.Query)16 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)15 NoResultsException (datawave.webservice.common.exception.NoResultsException)13 ArrayList (java.util.ArrayList)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13 SubjectIssuerDNPair (datawave.security.authorization.SubjectIssuerDNPair)12 WebApplicationException (javax.ws.rs.WebApplicationException)12 BadRequestException (datawave.webservice.common.exception.BadRequestException)11