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);
}
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);
}
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);
}
}
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());
}
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;
}
Aggregations