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; }
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 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; }
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 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; } } }
String defaultControllerName = config.getString("default"); if (defaultControllerName != null) { defaultController = loader.loadClass(defaultControllerName); String errorControllerName = config.getString("error"); if (errorControllerName != null) { errorController = (Class<? extends juzu.Handler<Response.Error,Response>>)loader.loadClass(errorControllerName);
public final ReadFileSystem<?> getSourcePath() { if (sourcePath == null) { String sourcePathParam = getInitParameter(SOURCE_PATH); if (sourcePathParam != null) { sourcePath = new DiskFileSystem(new File(sourcePathParam)); } else { try { URL configURL = getClassLoader().getResource("juzu/config.json"); if (configURL != null) { String configValue = Tools.read(configURL); JSON config = (JSON)JSON.parse(configValue); String sourcePathValue = config.getString("sourcepath"); if (sourcePathValue != null) { File sourcePathRoot = new File(sourcePathValue); if (sourcePathRoot.isDirectory() && sourcePathRoot.exists()) { sourcePath = new DiskFileSystem(sourcePathRoot); } } } } catch (IOException e) { e.printStackTrace(); } } } return sourcePath; }
for (String id : assets.names()) { JSON asset = assets.getJSON(id); AssetLocation location = AssetLocation.safeValueOf(asset.getString("location")); String type = asset.getString("type"); String value = asset.getString("value"); if (location == AssetLocation.APPLICATION && !value.startsWith("/")) { value = "/" + application.getPackageName().replace('.', '/') + "/" + packageName.replace('.', '/') + "/" + value; String minified = asset.getString("minified"); if (location == AssetLocation.APPLICATION && minified != null && !minified.startsWith("/")) { minified = "/" + application.getPackageName().replace('.', '/') + "/" + packageName.replace('.', '/') + "/" + minified;
public final ReadFileSystem<?> getSourcePath() { if (sourcePath == null) { String sourcePathParam = getInitParameter(SOURCE_PATH); if (sourcePathParam != null) { sourcePath = new DiskFileSystem(new File(sourcePathParam)); } else { try { URL configURL = getClassLoader().getResource("juzu/config.json"); if (configURL != null) { String configValue = Tools.read(configURL); JSON config = (JSON)JSON.parse(configValue); String sourcePathValue = config.getString("sourcepath"); if (sourcePathValue != null) { File sourcePathRoot = new File(sourcePathValue); if (sourcePathRoot.isDirectory() && sourcePathRoot.exists()) { sourcePath = new DiskFileSystem(sourcePathRoot); } } } } catch (IOException e) { e.printStackTrace(); } } } return sourcePath; }
for (String id : assets.names()) { JSON asset = assets.getJSON(id); AssetLocation location = AssetLocation.safeValueOf(asset.getString("location")); String type = asset.getString("type"); String value = asset.getString("value"); if (location == AssetLocation.APPLICATION && !value.startsWith("/")) { value = "/" + application.getPackageName().replace('.', '/') + "/" + packageName.replace('.', '/') + "/" + value; String minified = asset.getString("minified"); if (location == AssetLocation.APPLICATION && minified != null && !minified.startsWith("/")) { minified = "/" + application.getPackageName().replace('.', '/') + "/" + packageName.replace('.', '/') + "/" + minified;
String defaultControllerName = config.getString("default"); if (defaultControllerName != null) { defaultController = loader.loadClass(defaultControllerName); String errorControllerName = config.getString("error"); if (errorControllerName != null) { errorController = (Class<? extends juzu.Handler<Response.Error,Response>>)loader.loadClass(errorControllerName);
@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; }
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); } } } } }
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }