private boolean verify(Request request, JSON config) { if (config.get("require") != null) { return hasRequire(request, config); } if (config.get("roles") != null && config.get("permissions") != null) { return hasRoles(request, config) && hasPermissions(request, config); } if (config.get("permissions") != null && config.get("roles") == null) { return hasPermissions(request, config); } if (config.get("roles") != null && config.get("permissions") == null) { return hasRoles(request, config); } return true; } }
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; } } }
JSON methodJSON; if (controllerJSON.get("require") != null) { Response resp = authorizer.isAuthorized(stage, controllerJSON); if (resp != null) {
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; }
@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 boolean hasRequire(Request request, JSON config) { Object obj = config.get("require"); if ("guest".equals(obj)) { return SecurityUtils.getSubject().getPrincipal() == null; } else if ("authenticate".equals(obj)) { return SecurityUtils.getSubject().isAuthenticated(); } else if ("user".equals(obj)) { return SecurityUtils.getSubject().getPrincipal() != null; } 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; }
@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 Response doInvoke(Stage.Handler request, JSON json) { Response resp = authorizer.isAuthorized(request, json); if (resp != null) { return resp; } else { if ("login".equals(json.get("operator"))) { return authenticater.doLogin(request); } else if ("logout".equals(json.get("operator"))) { return authenticater.doLogout(request); } else { return request.invoke(); } } } }
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); } } } } }
AnnotationKey key = entry.getKey(); if (controllerJSON.get("require") != null) { throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement());
public SecurityManager get() { SecurityManager manager = null; try { manager = SecurityUtils.getSecurityManager(); } catch (UnavailableSecurityManagerException e1) { manager = new DefaultSecurityManager(); } boolean rememberMeSupported = config.get("rememberMe") != null ? true : false; if (rememberMeSupported && manager instanceof DefaultSecurityManager) { ((DefaultSecurityManager)manager).setRememberMeManager(new JuzuRememberMe()); } if (config.get("realms") != null) { try { injectRealms(config, manager, Request.getCurrent().getApplication().getInjectionContext()); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } return manager; }
ShiroDescriptor(ServiceContext context) { JSON config = context.getConfig(); this.authenticater = new ShiroAuthenticator(config.get("rememberMe") != null ? true : false); this.authorizer = new ShiroAuthorizor(); this.context = context; this.bean = BeanDescriptor .createFromProvider(SecurityManager.class, Scope.SESSION, null, new SecurityManagerProvider(config)); }
private void emitConfig(JSON json, AnnotationKey key, AnnotationState added) { if (key.getType().equals(Name.create(Login.class))) { if (json.get("operator") != null) { throw new UnsupportedOperationException("Unsupported multiple operators at " + key.getElement()); if (json.get("operator") != null) { throw new UnsupportedOperationException("Unsupported multiple operators at " + key.getElement()); if (json.get("require") != null || json.get("permissions") != null || json.get("roles") != null) { throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement()); if (json.get("require") != null || json.get("permissions") != null || json.get("roles") != null) { throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement()); if (json.get("require") != null || json.get("permissions") != null || json.get("roles") != null) { throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement()); if (json.get("require") != null) { throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement()); if (json.get("require") != null) { throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement());
@Test public void testReadMap() throws Exception { JSON o = (JSON)JSON.parse("{\"a\":\"b\"}"); assertEquals(Collections.singleton("a"), o.names()); assertEquals("b", o.get("a")); }
@Test public void testReadMap() throws Exception { JSON o = (JSON)JSON.parse("{\"a\":\"b\"}"); assertEquals(Collections.singleton("a"), o.names()); assertEquals("b", o.get("a")); }