Search in sources :

Example 21 with Collection

use of java.util.Collection in project storm by apache.

the class AuthUtilsTest method getNimbusAutoCredPluginTest.

@Test
public void getNimbusAutoCredPluginTest() {
    Map emptyMap = new HashMap<String, String>();
    Map<String, Collection<String>> map = new HashMap<String, Collection<String>>();
    map.put(Config.NIMBUS_AUTO_CRED_PLUGINS, Arrays.asList(new String[] { "org.apache.storm.security.auth.AuthUtilsTestMock" }));
    Assert.assertTrue(AuthUtils.getNimbusAutoCredPlugins(emptyMap).isEmpty());
    Assert.assertEquals(AuthUtils.getNimbusAutoCredPlugins(map).size(), 1);
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 22 with Collection

use of java.util.Collection in project storm by apache.

the class AuthUtilsTest method GetCredentialRenewersTest.

@Test
public void GetCredentialRenewersTest() {
    Map emptyMap = new HashMap<String, String>();
    Map<String, Collection<String>> map = new HashMap<String, Collection<String>>();
    map.put(Config.NIMBUS_CREDENTIAL_RENEWERS, Arrays.asList(new String[] { "org.apache.storm.security.auth.AuthUtilsTestMock" }));
    Assert.assertTrue(AuthUtils.GetCredentialRenewers(emptyMap).isEmpty());
    Assert.assertEquals(AuthUtils.GetCredentialRenewers(map).size(), 1);
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 23 with Collection

use of java.util.Collection in project storm by apache.

the class AuthUtils method getNimbusAutoCredPlugins.

/**
     * Get all the Nimbus Auto cred plugins.
     * @param conf nimbus configuration to use.
     * @return nimbus auto credential plugins.
     */
public static Collection<INimbusCredentialPlugin> getNimbusAutoCredPlugins(Map conf) {
    try {
        Set<INimbusCredentialPlugin> ret = new HashSet<>();
        Collection<String> clazzes = (Collection<String>) conf.get(Config.NIMBUS_AUTO_CRED_PLUGINS);
        if (clazzes != null) {
            for (String clazz : clazzes) {
                INimbusCredentialPlugin inst = Utils.newInstance(clazz);
                inst.prepare(conf);
                ret.add(inst);
            }
        }
        return ret;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : INimbusCredentialPlugin(org.apache.storm.security.INimbusCredentialPlugin) Collection(java.util.Collection) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 24 with Collection

use of java.util.Collection in project hbase by apache.

the class TestStore method testHandleErrorsInFlush.

@Test
public void testHandleErrorsInFlush() throws Exception {
    LOG.info("Setting up a faulty file system that cannot write");
    final Configuration conf = HBaseConfiguration.create();
    User user = User.createUserForTesting(conf, "testhandleerrorsinflush", new String[] { "foo" });
    // Inject our faulty LocalFileSystem
    conf.setClass("fs.file.impl", FaultyFileSystem.class, FileSystem.class);
    user.runAs(new PrivilegedExceptionAction<Object>() {

        @Override
        public Object run() throws Exception {
            // Make sure it worked (above is sensitive to caching details in hadoop core)
            FileSystem fs = FileSystem.get(conf);
            Assert.assertEquals(FaultyFileSystem.class, fs.getClass());
            // Initialize region
            init(name.getMethodName(), conf);
            LOG.info("Adding some data");
            store.add(new KeyValue(row, family, qf1, 1, (byte[]) null), null);
            store.add(new KeyValue(row, family, qf2, 1, (byte[]) null), null);
            store.add(new KeyValue(row, family, qf3, 1, (byte[]) null), null);
            LOG.info("Before flush, we should have no files");
            Collection<StoreFileInfo> files = store.getRegionFileSystem().getStoreFiles(store.getColumnFamilyName());
            Assert.assertEquals(0, files != null ? files.size() : 0);
            //flush
            try {
                LOG.info("Flushing");
                flush(1);
                Assert.fail("Didn't bubble up IOE!");
            } catch (IOException ioe) {
                Assert.assertTrue(ioe.getMessage().contains("Fault injected"));
            }
            LOG.info("After failed flush, we should still have no files!");
            files = store.getRegionFileSystem().getStoreFiles(store.getColumnFamilyName());
            Assert.assertEquals(0, files != null ? files.size() : 0);
            store.getHRegion().getWAL().close();
            return null;
        }
    });
    FileSystem.closeAllForUGI(user.getUGI());
}
Also used : User(org.apache.hadoop.hbase.security.User) KeyValue(org.apache.hadoop.hbase.KeyValue) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) CompactionConfiguration(org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) FilterFileSystem(org.apache.hadoop.fs.FilterFileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) Collection(java.util.Collection) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 25 with Collection

use of java.util.Collection in project zeppelin by apache.

the class SecurityUtils method getRoles.

/**
   * Return the roles associated with the authenticated user if any otherwise returns empty set
   * TODO(prasadwagle) Find correct way to get user roles (see SHIRO-492)
   *
   * @return shiro roles
   */
public static HashSet<String> getRoles() {
    if (!isEnabled) {
        return EMPTY_HASHSET;
    }
    Subject subject = org.apache.shiro.SecurityUtils.getSubject();
    HashSet<String> roles = new HashSet<>();
    Map allRoles = null;
    if (subject.isAuthenticated()) {
        Collection realmsList = SecurityUtils.getRealmsList();
        for (Iterator<Realm> iterator = realmsList.iterator(); iterator.hasNext(); ) {
            Realm realm = iterator.next();
            String name = realm.getClass().getName();
            if (name.equals("org.apache.shiro.realm.text.IniRealm")) {
                allRoles = ((IniRealm) realm).getIni().get("roles");
                break;
            } else if (name.equals("org.apache.zeppelin.realm.LdapRealm")) {
                allRoles = ((LdapRealm) realm).getListRoles();
                break;
            }
        }
        if (allRoles != null) {
            Iterator it = allRoles.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pair = (Map.Entry) it.next();
                if (subject.hasRole((String) pair.getKey())) {
                    roles.add((String) pair.getKey());
                }
            }
        }
    }
    return roles;
}
Also used : IniRealm(org.apache.shiro.realm.text.IniRealm) Subject(org.apache.shiro.subject.Subject) Iterator(java.util.Iterator) Collection(java.util.Collection) LdapRealm(org.apache.zeppelin.realm.LdapRealm) Map(java.util.Map) IniRealm(org.apache.shiro.realm.text.IniRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) Realm(org.apache.shiro.realm.Realm) HashSet(java.util.HashSet)

Aggregations

Collection (java.util.Collection)8532 ArrayList (java.util.ArrayList)2646 Map (java.util.Map)2119 List (java.util.List)1956 HashMap (java.util.HashMap)1657 Test (org.junit.Test)1476 Set (java.util.Set)1137 Iterator (java.util.Iterator)1090 HashSet (java.util.HashSet)1085 Collectors (java.util.stream.Collectors)951 IOException (java.io.IOException)823 Collections (java.util.Collections)660 Arrays (java.util.Arrays)446 Optional (java.util.Optional)423 File (java.io.File)386 Logger (org.slf4j.Logger)344 LoggerFactory (org.slf4j.LoggerFactory)330 PersistenceManager (javax.jdo.PersistenceManager)309 LinkedHashMap (java.util.LinkedHashMap)299 Query (javax.jdo.Query)294