Package org.jano.security

Source Code of org.jano.security.Security

package org.jano.security;

import org.jano.resources.ResourceRef;
import org.jano.resources.ResourceSystem;
import org.jano.resources.ResourceView;

import java.util.Set;

/**
* Jano Security point
*/
public final class Security {

  /**
   * Creates security context from the set of allowed rights
   */
  private static SecurityContext createContext(final Set<Right> rights) {
    return new SecurityContext() {
      @Override
      public boolean isAllowed(Right right) {
        return rights.contains(right);
      }
    };
  }

  /**
   * Secures the resource view with set of allowed rights
   * @param resourceView the view to secure
   * @param rights set of the rights allowed to execute under rights
   * @return
   */
  public static ResourceView secure(final ResourceView resourceView, final Set<Right> rights) {
    final SecurityContext context = createContext(rights);
    return new ResourceView() {
      @Override
      public ResourceRef viewOf(String viewUri, String childUri, ResourceSystem system) {
        ResourceRef ref = resourceView.viewOf(viewUri, childUri, system);
        return new SecuredRef(ref, context);
      }
    };
  }
}
TOP

Related Classes of org.jano.security.Security

TOP
Copyright © 2018 www.massapi.com. 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.