public ControllersDescriptor(ApplicationDescriptor desc) throws Exception { this(desc.getApplicationLoader(), desc.getConfig().getJSON("controller")); }
public ControllersDescriptor(ApplicationDescriptor desc) throws Exception { this(desc.getApplicationLoader(), desc.getConfig().getJSON("controller")); }
public RouteDescriptor(JSON config) { HashMap<String, ParamDescriptor> parameters = null; JSON foo = config.getJSON("parameters"); if (foo != null) { parameters = new HashMap<String, ParamDescriptor>(); for (String name : foo.names()) { String pattern = foo.getJSON(name).getString("pattern"); Boolean preservePath = foo.getJSON(name).getBoolean("preserve-path"); Boolean captureGroup = foo.getJSON(name).getBoolean("capture-group"); parameters.put(name, new ParamDescriptor(pattern, preservePath, captureGroup)); } } // this.path = config.getString("path"); this.handle = MethodHandle.parse(config.getString("handle")); this.parameters = parameters; }
public RouteDescriptor(JSON config) { HashMap<String, ParamDescriptor> parameters = null; JSON foo = config.getJSON("parameters"); if (foo != null) { parameters = new HashMap<String, ParamDescriptor>(); for (String name : foo.names()) { String pattern = foo.getJSON(name).getString("pattern"); Boolean preservePath = foo.getJSON(name).getBoolean("preserve-path"); Boolean captureGroup = foo.getJSON(name).getBoolean("capture-group"); parameters.put(name, new ParamDescriptor(pattern, preservePath, captureGroup)); } } // this.path = config.getString("path"); this.handle = MethodHandle.parse(config.getString("handle")); this.parameters = parameters; }
private boolean hasPermissions(Request request, JSON config) { if (!SecurityUtils.getSubject().isAuthenticated()) { return false; } JSON foo = config.getJSON("permissions"); Logical logical = Logical.valueOf(foo.getString("logical")); List<String> permissions = (List<String>)foo.get("value"); if (permissions.size() == 1) { return ShiroTools.isPermitted(permissions.get(0)); } else if (permissions.size() > 1) { switch (logical) { case AND : return SecurityUtils.getSubject().isPermittedAll(permissions.toArray(new String[permissions.size()])); case OR : return ShiroTools.isPermitted(permissions.toArray(new String[permissions.size()])); } } return false; }
private boolean hasRoles(Request request, JSON config) { if (!SecurityUtils.getSubject().isAuthenticated()) { return false; } JSON foo = config.getJSON("roles"); Logical logical = Logical.valueOf(foo.getString("logical")); List<String> roles = (List<String>)foo.get("value"); if (roles.size() == 1) { return ShiroTools.hasRole(roles.get(0)); } else if (roles.size() > 1) { switch (logical) { case AND : return SecurityUtils.getSubject().hasAllRoles(roles); case OR : return ShiroTools.hasRole(roles.toArray(new String[roles.size()])); } } return false; }
private void injectRealms(JSON config, SecurityManager currentManager, InjectionContext manager) throws InvocationTargetException { JSON realmsJSON = config.getJSON("realms"); Iterable beans = manager.resolveBeans(AuthorizingRealm.class); for (Object bean : beans) { Object instance = manager.createContext(bean); AuthorizingRealm realm = AuthorizingRealm.class.cast(manager.getInstance(bean, instance)); JSON realmJSON = realmsJSON.getJSON(realm.getClass().getName()); if (realmJSON != null) { if (realmJSON.get("name") != null) { realm.setName(realmJSON.getString("name")); } Collection<Realm> realms = ((RealmSecurityManager)currentManager).getRealms(); if (realms == null) { ((RealmSecurityManager)currentManager).setRealm(realm); } else { ((RealmSecurityManager)currentManager).getRealms().add(realm); } } } } }
@Override public ServiceDescriptor init(ServiceContext context) throws Exception { JSON config = context.getConfig(); String assetsPath; List<AssetMetaData> assets; if (config != null) { String packageName = config.getString("package"); assets = load(packageName, config.getJSON("assets")); assetsPath = "/" + Name.parse(application.getPackageName()).append(packageName).toString().replace('.', '/') + "/"; } else { assets = Collections.emptyList(); assetsPath = null; } this.descriptor = new AssetDescriptor(assets); this.context = context; this.assetsPath = assetsPath; return descriptor; }
@Override public ServiceDescriptor init(ServiceContext context) throws Exception { JSON config = context.getConfig(); String assetsPath; List<AssetMetaData> assets; if (config != null) { String packageName = config.getString("package"); assets = load(packageName, config.getJSON("assets")); assetsPath = "/" + Name.parse(application.getPackageName()).append(packageName).toString().replace('.', '/') + "/"; } else { assets = Collections.emptyList(); assetsPath = null; } this.descriptor = new AssetDescriptor(assets); this.context = context; this.assetsPath = assetsPath; return descriptor; }
String controllerId = methodId.substring(0, methodId.indexOf('#')); methodId = methodId.substring(controllerId.length() + 1); JSON controllerJSON = getConfig().getJSON(controllerId); if (controllerJSON == null) { return stage.invoke(); JSON methodsJSON = controllerJSON.getJSON("methods"); JSON methodJSON; methodJSON = methodsJSON.getJSON(methodId); if (methodJSON == null) { return stage.invoke(); methodJSON = methodsJSON.getJSON(methodId); if (methodJSON == null) { return stage.invoke();
@Test public void testSimple() throws Exception { MockApplication<?> app = application("plugin.controller.url.simple"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertFalse(url.getJSON("properties").contains(PropertyType.ESCAPE_XML.getClass().getName())); }
@Test public void testEscapeXML() throws Exception { MockApplication<?> app = application("plugin.controller.url.escapexml"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertEquals(Boolean.TRUE, url.getJSON("properties").get(PropertyType.ESCAPE_XML.getClass().getName())); }
@Test public void testSimple() throws Exception { MockApplication<?> app = application("plugin.controller.url.simple"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertFalse(url.getJSON("properties").contains(PropertyType.ESCAPE_XML.getClass().getName())); }
@Test public void testEscapeXML() throws Exception { MockApplication<?> app = application("plugin.controller.url.escapexml"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertEquals(Boolean.TRUE, url.getJSON("properties").get(PropertyType.ESCAPE_XML.getClass().getName())); }
private URL getShiroIniURL() throws MalformedURLException { JSON json = descriptor.getConfig().getJSON("config"); if (json == null) return null; AssetLocation location = AssetLocation.APPLICATION; if (json.get("location") != null) { location = AssetLocation.valueOf(json.getString("location")); } switch (location) { case APPLICATION : return descriptor.getContext().getApplicationResolver().resolve(json.getString("value")); case SERVER : return descriptor.getContext().getServerResolver().resolve(json.getString("value")); case URL : return new URL(json.getString("value")); default : return null; } } }
@Test public void testToJSON() throws Exception { class Foo { final String value; Foo(String value) { this.value = value; } public JSON toJSON() { return new JSON().set("value", value); } } JSON json = new JSON().set("foo", new Foo("bar")); assertEquals(new JSON().set("value", "bar"), json.getJSON("foo")); }
@Test public void testToJSON() throws Exception { class Foo { final String value; Foo(String value) { this.value = value; } public JSON toJSON() { return new JSON().set("value", value); } } JSON json = new JSON().set("foo", new Foo("bar")); assertEquals(new JSON().set("value", "bar"), json.getJSON("foo")); }
JSON jsonParams = json.getJSON("parameters"); Map<String, String[]> parameters = new HashMap<String, String[]>(); for (String name : jsonParams.names()) {