Search in sources :

Example 1 with DatawaveUser

use of datawave.security.authorization.DatawaveUser 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 DatawaveUser

use of datawave.security.authorization.DatawaveUser in project datawave by NationalSecurityAgency.

the class MapReduceBeanTest method setup.

@Before
public void setup() throws Exception {
    System.setProperty(NpeUtils.NPE_OU_PROPERTY, "iamnotaperson");
    System.setProperty("dw.metadatahelper.all.auths", "A,B,C,D");
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of(userDN, "CN=ca, OU=acme"), UserType.USER, Arrays.asList(auths), Collections.singleton("AuthorizedUser"), null, 0L);
    principal = new DatawavePrincipal(Collections.singletonList(user));
    applicationContext = new ClassPathXmlApplicationContext("classpath:*datawave/mapreduce/MapReduceJobs.xml");
    Whitebox.setInternalState(bean, MapReduceConfiguration.class, applicationContext.getBean(MapReduceConfiguration.class));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DatawaveUser(datawave.security.authorization.DatawaveUser) MapReduceConfiguration(datawave.webservice.mr.configuration.MapReduceConfiguration) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Before(org.junit.Before)

Example 3 with DatawaveUser

use of datawave.security.authorization.DatawaveUser in project datawave by NationalSecurityAgency.

the class MapReduceBeanTest method testInvalidUserAuthorization.

@Test(expected = UnauthorizedException.class)
public void testInvalidUserAuthorization() throws Exception {
    // Create principal that does not have AuthorizedUser role
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of(userDN, "CN=ca, OU=acme"), UserType.USER, Arrays.asList(auths), Collections.singleton("Administrator"), null, 0L);
    DatawavePrincipal p = new DatawavePrincipal(Collections.singletonList(user));
    expect(ctx.getCallerPrincipal()).andReturn(p);
    replayAll();
    bean.submit("TestJob", "queryId:1243");
    verifyAll();
}
Also used : DatawaveUser(datawave.security.authorization.DatawaveUser) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with DatawaveUser

use of datawave.security.authorization.DatawaveUser in project datawave by NationalSecurityAgency.

the class MapReduceStatePersisterTest method testDontFindSomeoneElsesJob.

@Test
public void testDontFindSomeoneElsesJob() throws Exception {
    // create some entries
    testPersistentCreate();
    PowerMock.resetAll();
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of("CN=Gal Some Other sogal, OU=acme", "CN=ca, OU=acme"), UserType.USER, Arrays.asList(auths), null, null, 0L);
    principal = new DatawavePrincipal(Collections.singletonList(user));
    EasyMock.expect(ctx.getCallerPrincipal()).andReturn(principal);
    HashMap<String, String> trackingMap = new HashMap<>();
    expect(connectionFactory.getTrackingMap(EasyMock.anyObject())).andReturn(trackingMap);
    expect(connectionFactory.getConnection(EasyMock.eq(AccumuloConnectionFactory.Priority.ADMIN), EasyMock.eq(trackingMap))).andReturn(connection);
    connectionFactory.returnConnection(connection);
    replayAll();
    MapReduceInfoResponseList result = bean.findById(id);
    verifyAll();
    assertEquals(0, result.getResults().size());
}
Also used : HashMap(java.util.HashMap) DatawaveUser(datawave.security.authorization.DatawaveUser) MapReduceInfoResponseList(datawave.webservice.results.mr.MapReduceInfoResponseList) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Test(org.junit.Test)

Example 5 with DatawaveUser

use of datawave.security.authorization.DatawaveUser in project datawave by NationalSecurityAgency.

the class MapReduceStatePersisterTest method setup.

@Before
public void setup() throws Exception {
    System.setProperty(NpeUtils.NPE_OU_PROPERTY, "iamnotaperson");
    System.setProperty("dw.metadatahelper.all.auths", "A,B,C,D");
    connection = instance.getConnector("root", new PasswordToken(""));
    if (connection.tableOperations().exists(TABLE_NAME))
        connection.tableOperations().delete(TABLE_NAME);
    if (connection.tableOperations().exists(INDEX_TABLE_NAME))
        connection.tableOperations().delete(INDEX_TABLE_NAME);
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of(userDN, "CN=ca, OU=acme"), UserType.USER, Arrays.asList(auths), null, null, 0L);
    principal = new DatawavePrincipal(Collections.singletonList(user));
    connectionFactory = createMock(AccumuloConnectionFactory.class);
    ctx = createStrictMock(EJBContext.class);
    bean = new MapReduceStatePersisterBean();
    field(MapReduceStatePersisterBean.class, "connectionFactory").set(bean, connectionFactory);
    field(MapReduceStatePersisterBean.class, "ctx").set(bean, ctx);
    Logger.getLogger(MapReduceStatePersisterBean.class).setLevel(Level.OFF);
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) EJBContext(javax.ejb.EJBContext) DatawaveUser(datawave.security.authorization.DatawaveUser) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) AccumuloConnectionFactory(datawave.webservice.common.connection.AccumuloConnectionFactory) Before(org.junit.Before)

Aggregations

DatawaveUser (datawave.security.authorization.DatawaveUser)51 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)41 Test (org.junit.Test)26 SubjectIssuerDNPair (datawave.security.authorization.SubjectIssuerDNPair)14 HashSet (java.util.HashSet)13 Before (org.junit.Before)13 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)11 BaseQueryLogic (datawave.webservice.query.logic.BaseQueryLogic)9 ArrayList (java.util.ArrayList)9 QueryMetric (datawave.microservice.querymetric.QueryMetric)7 DatawaveCredential (datawave.security.auth.DatawaveCredential)7 Date (java.util.Date)6 Set (java.util.Set)6 UUID (java.util.UUID)6 Connector (org.apache.accumulo.core.client.Connector)6 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)6 InMemoryInstance (datawave.accumulo.inmemory.InMemoryInstance)5 QueryLogic (datawave.webservice.query.logic.QueryLogic)5 DateIndexHelperFactory (datawave.query.util.DateIndexHelperFactory)4 MetadataHelperFactory (datawave.query.util.MetadataHelperFactory)4