Package juzu.impl.common

Examples of juzu.impl.common.JSON


 
  /** .*/
  private ServiceContext context;

  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));
View Full Code Here


  public Response invoke(Stage.Handler stage) {
    //
    String methodId = stage.getRequest().getHandler().getHandle().toString();
    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;

    if (controllerJSON.get("require") != null) {
      Response resp = authorizer.isAuthorized(stage, controllerJSON);
      if (resp != null) {
        return resp;
View Full Code Here

    return manager;
  }

  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);
View Full Code Here

  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 :
View Full Code Here

  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 :
View Full Code Here

    ThreadContext.bind(manager);
    ThreadContext.bind(currentUser);
  }

  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;
    }
  }
View Full Code Here

  @Override
  public JSON getDescriptor(ApplicationMetaModel application) {
    ElementHandle.Package handle = application.getHandle();
    Boolean enabled = enabledMap.get(handle);
    return enabled != null && enabled ? new JSON() : null;
  }
View Full Code Here

  @Override
  public void processAnnotationAdded(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState added) {
    ElementHandle.Package handle = metaModel.getHandle();
    if (key.getType().equals(Name.create(Shiro.class))) {
      JSON json = new JSON();
      json.set("rememberMe", added.get("rememberMe"));
      json.set("config", added.get("config"));
      List<AnnotationState> realms = (List<AnnotationState>)added.get("realms");
      JSON realmsJSON = new JSON();
      if (realms != null) {
        for (AnnotationState sel : realms) {
          ElementHandle.Type clazz = (juzu.impl.compiler.ElementHandle.Type)sel.get("value");
          String name = (String)sel.get("name");
          realmsJSON.set(clazz.getName().toString(), new JSON().set("name", name));
        }
      }
      json.set("realms", realmsJSON);
      enableMap.put(handle, json);
    } else {
View Full Code Here

      if (json.get("require") != null) {
        throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement());
      }
      ArrayList<String> values = (ArrayList<String>)added.get("value");
      String logical = (String)added.get("logical");
      JSON foo = new JSON();
      foo.set("value", values);
      if (logical != null) {
        foo.set("logical", logical);
      } else {
        foo.set("logical", Logical.AND);
      }
      json.set("permissions", foo);
    } else if (key.getType().equals(Name.create(RequiresRoles.class))) {
      if (json.get("require") != null) {
        throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement());
      }
      ArrayList<String> values = (ArrayList<String>)added.get("value");
      String logical = (String)added.get("logical");
      JSON foo = new JSON();
      foo.set("value", values);
      if (logical != null) {
        foo.set("logical", logical);
      } else {
        foo.set("logical", Logical.AND);
      }
      json.set("roles", foo);
    }
  }
View Full Code Here

  }

  @Override
  public void postProcessEvents(ApplicationMetaModel metaModel) {
    ElementHandle.Package packageHandle = metaModel.getHandle();
    JSON config = enableMap.get(packageHandle);
    if (config != null) {
      ControllersMetaModel controllersModel = metaModel.getChild(ControllersMetaModel.KEY);

      for (ControllerMetaModel controller : controllersModel) {
        Map<AnnotationKey, AnnotationState> annotations = controllers.get(controller.getHandle());
        if (annotations != null) {
          JSON controllerJSON = new JSON();
          config.set(controller.getHandle().getName().toString(), controllerJSON);

          for (Map.Entry<AnnotationKey, AnnotationState> entry : annotations.entrySet()) {
            AnnotationKey key = entry.getKey();

            if (controllerJSON.get("require") != null) {
              throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement());
            }

            if (key.getType().equals(Name.create(RequiresGuest.class))) {
              controllerJSON.set("require", "guest");
            } else if (key.getType().equals(Name.create(RequiresAuthentication.class))) {
              controllerJSON.set("require", "authenticate");
            } else if (key.getType().equals(Name.create(RequiresUser.class))) {
              controllerJSON.set("require", "user");
            }
          }
        }

        for (HandlerMetaModel handler : controller) {
          annotations = methods.get(handler.getMethod());
          String methodId = handler.getMethod().getMethodHandle().toString();

          if (annotations != null) {
            JSON controllerJSON = config.getJSON(controller.getHandle().getName().toString());
            if (controllerJSON == null) {
              controllerJSON = new JSON();
              config.set(controller.getHandle().getName().toString(), controllerJSON);
            }

            JSON methodJSON = new JSON();;
            for (Map.Entry<AnnotationKey, AnnotationState> entry : annotations.entrySet()) {
              emitConfig(methodJSON, entry.getKey(), entry.getValue());
            }

            JSON methodsJSON = controllerJSON.getJSON("methods");
            if (methodsJSON == null) {
              methodsJSON = new JSON();
              controllerJSON.set("methods", methodsJSON);
            }
            methodsJSON.set(methodId.substring(methodId.lastIndexOf('#') + 1), methodJSON);
          }
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of juzu.impl.common.JSON

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.