use of org.opensolaris.opengrok.authorization.AuthorizationStack in project OpenGrok by OpenGrok.
the class RuntimeEnvironmentTest method testAuthorizationStackDecode.
@Test
public void testAuthorizationStackDecode() throws IOException {
String confString = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<java class=\"java.beans.XMLDecoder\" version=\"1.8.0_121\">\n" + " <object class=\"org.opensolaris.opengrok.configuration.Configuration\">\n" + " <void property=\"pluginStack\">\n" + " <void method=\"add\">\n" + " <object id=\"first_plugin\" class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>sufficient</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>Plugin</string>\n" + " </void>\n" + " </object>\n" + " </void>\n" + " <void method=\"add\">\n" + " <object id=\"first_stack\" class=\"org.opensolaris.opengrok.authorization.AuthorizationStack\">\n" + " <void property=\"flag\">\n" + " <string>required</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>basic stack</string>\n" + " </void>\n" + " <void property=\"stack\">" + " <void method=\"add\">" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>required</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>NestedPlugin</string>\n" + " </void>\n" + " </object>\n" + " </void>" + " <void method=\"add\">" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>requisite</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>NestedPlugin</string>\n" + " </void>\n" + " <void property=\"setup\">" + " <void method=\"put\">" + " <string>key</string>" + " <string>value</string>" + " </void>" + " <void method=\"put\">" + " <string>plugin</string>" + " <object idref=\"first_plugin\" />" + " </void>" + " </void>" + " </object>\n" + " </void>" + " </void>" + " </object>\n" + " </void>\n" + " <void method=\"add\">\n" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>requisite</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>Requisite</string>\n" + " </void>\n" + " </object>\n" + " </void>\n" + " <void method=\"add\">\n" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationStack\">\n" + " <void property=\"flag\">\n" + " <string>required</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>advanced stack</string>\n" + " </void>\n" + " <void property=\"stack\">" + " <void method=\"add\">" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>required</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>NestedPlugin</string>\n" + " </void>\n" + " </object>\n" + " </void>" + " <void method=\"add\">" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>requisite</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>NestedPlugin</string>\n" + " </void>\n" + " <void property=\"setup\">" + " <void method=\"put\">" + " <string>key</string>" + " <string>other value</string>" + " </void>" + " <void method=\"put\">" + " <string>plugin</string>" + " <object idref=\"first_plugin\" />" + " </void>" + " </void>" + " </object>\n" + " </void>" + " </void>" + " </object>\n" + " </void>\n" + " <void method=\"add\">\n" + " <object idref=\"first_stack\" />" + " </void>\n" + " </void>\n" + " </object>\n" + "</java>";
Configuration conf = Configuration.makeXMLStringAsConfiguration(confString);
assertNotNull(conf.getPluginStack());
AuthorizationStack pluginConfiguration = conf.getPluginStack();
assertEquals(5, pluginConfiguration.getStack().size());
// single plugins
assertTrue(pluginConfiguration.getStack().get(0).getFlag().isSufficient());
assertEquals("Plugin", pluginConfiguration.getStack().get(0).getName());
assertTrue(pluginConfiguration.getStack().get(2).getFlag().isRequisite());
assertEquals("Requisite", pluginConfiguration.getStack().get(2).getName());
/**
* Third element is a stack which defines two nested plugins.
*/
assertTrue(pluginConfiguration.getStack().get(1) instanceof AuthorizationStack);
AuthorizationStack stack = (AuthorizationStack) pluginConfiguration.getStack().get(1);
assertTrue(stack.getFlag().isRequired());
assertEquals("basic stack", stack.getName());
assertEquals(2, stack.getStack().size());
assertTrue(stack.getStack().get(0) instanceof AuthorizationPlugin);
assertEquals("NestedPlugin", stack.getStack().get(0).getName());
assertTrue(stack.getStack().get(0).isRequired());
assertTrue(stack.getStack().get(1) instanceof AuthorizationPlugin);
assertEquals("NestedPlugin", stack.getStack().get(1).getName());
assertTrue(stack.getStack().get(1).isRequisite());
AuthorizationPlugin plugin = (AuthorizationPlugin) stack.getStack().get(1);
assertTrue(plugin.getSetup().containsKey("key"));
assertEquals("value", plugin.getSetup().get("key"));
assertTrue(plugin.getSetup().containsKey("plugin"));
assertTrue(plugin.getSetup().get("plugin") instanceof AuthorizationPlugin);
assertEquals(pluginConfiguration.getStack().get(0), plugin.getSetup().get("plugin"));
/**
* Fourth element is a stack slightly changed from the previous stack.
* Only the setup for the particular plugin is changed.
*/
assertTrue(pluginConfiguration.getStack().get(3) instanceof AuthorizationStack);
stack = (AuthorizationStack) pluginConfiguration.getStack().get(3);
assertTrue(stack.getFlag().isRequired());
assertEquals("advanced stack", stack.getName());
assertEquals(2, stack.getStack().size());
assertTrue(stack.getStack().get(0) instanceof AuthorizationPlugin);
assertEquals("NestedPlugin", stack.getStack().get(0).getName());
assertTrue(stack.getStack().get(0).isRequired());
assertTrue(stack.getStack().get(1) instanceof AuthorizationPlugin);
assertEquals("NestedPlugin", stack.getStack().get(1).getName());
assertTrue(stack.getStack().get(1).isRequisite());
plugin = (AuthorizationPlugin) stack.getStack().get(1);
assertTrue(plugin.getSetup().containsKey("key"));
assertEquals("other value", plugin.getSetup().get("key"));
assertTrue(plugin.getSetup().containsKey("plugin"));
assertTrue(plugin.getSetup().get("plugin") instanceof AuthorizationPlugin);
assertEquals(pluginConfiguration.getStack().get(0), plugin.getSetup().get("plugin"));
/**
* Fifth element is a direct copy of the first stack.
*/
assertTrue(pluginConfiguration.getStack().get(4) instanceof AuthorizationStack);
stack = (AuthorizationStack) pluginConfiguration.getStack().get(4);
assertTrue(stack.getFlag().isRequired());
assertEquals("basic stack", stack.getName());
assertEquals(2, stack.getStack().size());
assertTrue(stack.getStack().get(0) instanceof AuthorizationPlugin);
assertEquals("NestedPlugin", stack.getStack().get(0).getName());
assertTrue(stack.getStack().get(0).isRequired());
assertTrue(stack.getStack().get(1) instanceof AuthorizationPlugin);
assertEquals("NestedPlugin", stack.getStack().get(1).getName());
assertTrue(stack.getStack().get(1).isRequisite());
plugin = (AuthorizationPlugin) stack.getStack().get(1);
assertTrue(plugin.getSetup().containsKey("key"));
assertEquals("value", plugin.getSetup().get("key"));
assertTrue(plugin.getSetup().containsKey("plugin"));
assertTrue(plugin.getSetup().get("plugin") instanceof AuthorizationPlugin);
assertEquals(pluginConfiguration.getStack().get(0), plugin.getSetup().get("plugin"));
}
use of org.opensolaris.opengrok.authorization.AuthorizationStack in project OpenGrok by OpenGrok.
the class RuntimeEnvironmentTest method testAuthorizationFlagDecode.
@Test
public void testAuthorizationFlagDecode() throws IOException {
String confString = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<java class=\"java.beans.XMLDecoder\" version=\"1.8.0_121\">\n" + " <object class=\"org.opensolaris.opengrok.configuration.Configuration\">\n" + " <void property=\"pluginStack\">\n" + " <void method=\"add\">\n" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>sufficient</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>Plugin</string>\n" + " </void>\n" + " </object>\n" + " </void>\n" + " <void method=\"add\">\n" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>required</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>OtherPlugin</string>\n" + " </void>\n" + " </object>\n" + " </void>\n" + " <void method=\"add\">\n" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>REQUISITE</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>AnotherPlugin</string>\n" + " </void>\n" + " </object>\n" + " </void>\n" + " <void method=\"add\">\n" + " <object class=\"org.opensolaris.opengrok.authorization.AuthorizationPlugin\">\n" + " <void property=\"flag\">\n" + " <string>reQuIrEd</string>\n" + " </void>\n" + " <void property=\"name\">\n" + " <string>DifferentPlugin</string>\n" + " </void>\n" + " </object>\n" + " </void>\n" + " </void>\n" + " </object>\n" + "</java>";
Configuration conf = Configuration.makeXMLStringAsConfiguration(confString);
assertNotNull(conf.getPluginStack());
AuthorizationStack pluginConfiguration = conf.getPluginStack();
assertEquals(4, pluginConfiguration.getStack().size());
assertTrue(pluginConfiguration.getStack().get(0).getFlag().isSufficient());
assertEquals("Plugin", pluginConfiguration.getStack().get(0).getName());
assertTrue(pluginConfiguration.getStack().get(1).getFlag().isRequired());
assertEquals("OtherPlugin", pluginConfiguration.getStack().get(1).getName());
assertTrue(pluginConfiguration.getStack().get(2).getFlag().isRequisite());
assertEquals("AnotherPlugin", pluginConfiguration.getStack().get(2).getName());
assertTrue(pluginConfiguration.getStack().get(3).getFlag().isRequired());
assertEquals("DifferentPlugin", pluginConfiguration.getStack().get(3).getName());
}
use of org.opensolaris.opengrok.authorization.AuthorizationStack in project OpenGrok by OpenGrok.
the class ConfigurationHelp method getSampleValue.
private static Object getSampleValue(Method setter, Object defaultValue) {
Class paramType = setter.getParameterTypes()[0];
Type genType = setter.getGenericParameterTypes()[0];
if (setter.getName().equals("setBugPattern")) {
return "Sample Bug \\#(\\d+)";
} else if (setter.getName().equals("setReviewPattern")) {
return "Sample Issue \\#(\\d+)";
} else if (paramType == String.class) {
return "user-specified-value";
} else if (paramType == int.class) {
return 1 + (int) defaultValue;
} else if (paramType == short.class) {
return (short) (1 + (short) defaultValue);
} else if (paramType == boolean.class) {
if (defaultValue == null)
return null;
return !(boolean) defaultValue;
} else if (paramType == double.class) {
return 1 + (double) defaultValue;
} else if (paramType == List.class) {
return getSampleListValue(genType);
} else if (paramType == Map.class) {
return getSampleMapValue(genType);
} else if (paramType == Set.class) {
return getSampleSetValue(genType);
} else if (paramType == AuthorizationStack.class) {
AuthorizationStack astck = new AuthorizationStack(AuthControlFlag.REQUIRED, "user-specified-value");
astck.add(new AuthorizationPlugin(AuthControlFlag.REQUISITE, "user-specified-value"));
return astck;
} else if (paramType == Filter.class) {
Filter flt = new Filter();
flt.add("user-specified-(patterns)*");
flt.add("user-specified-filename");
flt.add("user/specified/path");
return flt;
} else if (paramType == IgnoredNames.class) {
IgnoredNames inm = new IgnoredNames();
inm.add("f:user-specified-value");
inm.add("d:user-specified-value");
return inm;
} else if (paramType.isEnum()) {
for (Object value : paramType.getEnumConstants()) {
if (!value.equals(defaultValue))
return value;
}
return null;
} else {
throw new UnsupportedOperationException("getSampleValue() for " + paramType + ", " + genType);
}
}
Aggregations