Example #1
0
 public String insertResource(Resource rsce, String contUrl) {
   return "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
       + "PREFIX res:<"
       + this.getRes()
       + "s#>"
       + "INSERT  "
       + " { <"
       + rsce.getUrl()
       + "> res:submitter  \""
       + rsce.getSubmitter().getLogin()
       + "\" ; "
       + "                       res:state  \""
       + rsce.getState()
       + "\" ; "
       + "                       res:vocname  \""
       + rsce.getVoc().getName()
       + "\" ; "
       + "                       res:type  \""
       + rsce.getType()
       + "\" ; "
       + "                       res:language  \""
       + rsce.getLanguage()
       + "\" ; "
       + "                       res:format  \""
       + rsce.getFormat()
       + "\" ; "
       + "                       res:author  \""
       + rsce.getAuthor()
       + "\" ; "
       + "                       res:content  \""
       + contUrl
       + "\"  "
       + "               }";
 }
  private LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> buildRequestMap313() {
    LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap =
        new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>();

    ResourceMapping resourceMapping = new ResourceMapping(getDataSource(), resourceQuery);
    for (Resource resource : (List<Resource>) resourceMapping.execute()) {
      String url = resource.getUrl();
      String role = resource.getRole();

      RequestMatcher key =
          resource.getMatchType().equalsIgnoreCase("ant")
              ? new AntPathRequestMatcher(url)
              : new RegexRequestMatcher(url, null);

      if (requestMap.containsKey(key)) {
        requestMap.get(key).add(new SecurityConfig(role.trim()));
      } else {
        requestMap.put(key, SecurityConfig.createList(role));
      }
    }

    System.out.println("SecurityMetadataSource resourceQuery : " + resourceQuery);
    System.out.println("SecurityMetadataSource resourceMapping : " + resourceMapping);

    return requestMap;
  }
Example #3
0
 // Get all docs registed by a source in vocabulary named vocName
 public String existResource(Resource res) {
   return "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
       + "PREFIX dc:<http://purl.org/dc/elements/1.1/>"
       + "PREFIX res:<"
       + this.getRes()
       + "s#>"
       + "ASK  "
       + "WHERE { ?r ?p ?o ."
       + "       FILTER(STR(?r)=\""
       + res.getUrl()
       + "\")}";
 }
Example #4
0
  public Resource guardResource(Resource res, String negotiatingPeerName)
      throws IllegalAccessPolicyAssociation {

    // pt negotiation if external protected resource
    if (res instanceof ProtectedResource) {
      String policyName = ((ProtectedResource) res).getPolicyName();
      if (policyName == null) {
        throw new IllegalAccessPolicyAssociation(
            "Policy name associated with " + res.getUrl() + " is null");
      }
      if (policyName.trim().length() == 0) {
        throw new IllegalAccessPolicyAssociation(
            "Policy name associated with " + res.getUrl() + " is empty");
      }

      Vector associatePolicies = policySystem.getPolicies(policyName);
      if (associatePolicies.size() == 0) {
        throw new IllegalAccessPolicyAssociation("Policy with the name " + policyName + "is empty");
      }

      // evaluate
      int result = policyEvaluator.eval(associatePolicies, negotiatingPeerName);
      if (result == PolicyEvaluator.SUCCESS_FLAG) {
        ((ProtectedResource) res).setCanAccess(true);
      } else {
        ((ProtectedResource) res).setCanAccess(false);
        String message = ((SimplePolicyEvaluator) policyEvaluator).getMessage();
        if (message == null) {
          ((ProtectedResource) res)
              .setReason(
                  "Fail to evaluate "
                      + ((Policy) associatePolicies.elementAt(result)).getPolicyValue());
        } else {
          ((ProtectedResource) res).setReason(message);
        }
      }
    }

    return res;
  }
  @Deprecated
  protected Map<String, String> findResources() {
    ResourceMapping resourceMapping = new ResourceMapping(getDataSource(), resourceQuery);

    Map<String, String> resourceMap = new LinkedHashMap<String, String>();

    for (Resource resource : (List<Resource>) resourceMapping.execute()) {
      String url = resource.getUrl();
      String role = resource.getRole();

      if (resourceMap.containsKey(url)) {
        String value = resourceMap.get(url);
        resourceMap.put(url, value + "," + role);
      } else {
        resourceMap.put(url, role);
      }
    }

    return resourceMap;
  }
  @Deprecated
  private LinkedHashMap<RequestKey, Collection<ConfigAttribute>> buildRequestMap301() {
    LinkedHashMap<RequestKey, Collection<ConfigAttribute>> requestMap =
        new LinkedHashMap<RequestKey, Collection<ConfigAttribute>>();

    ResourceMapping resourceMapping = new ResourceMapping(getDataSource(), resourceQuery);
    for (Resource resource : (List<Resource>) resourceMapping.execute()) {
      String url = resource.getUrl();
      String role = resource.getRole();

      RequestKey key = new RequestKey(url, null);

      if (requestMap.containsKey(key)) {
        requestMap.get(key).add(new SecurityConfig(role.trim()));
      } else {
        requestMap.put(new RequestKey(url, null), SecurityConfig.createList(role));
      }
    }

    return requestMap;
  }
Example #7
0
 public String insert(Resource rsce) {
   String descr = "";
   for (String term : rsce.getContent()) {
     descr += "  ;  res:content  \"" + term + "\"  ";
   }
   return "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
       + "PREFIX res:<"
       + this.getRes()
       + "s#>"
       + "INSERT  "
       + " { <"
       + rsce.getUrl()
       + "> res:submitter  \""
       + rsce.getSubmitter().getLogin()
       + "\" ; "
       + "                       res:state  \""
       + rsce.getState()
       + "\" ; "
       + "                       res:vocname  \""
       + rsce.getVoc().getName()
       + "\" ; "
       + "                       res:type  \""
       + rsce.getType()
       + "\" ; "
       + "                       res:language  \""
       + rsce.getLanguage()
       + "\" ; "
       + "                       res:format  \""
       + rsce.getFormat()
       + "\" ; "
       + "                       res:author  \""
       + rsce.getAuthor()
       + "\"  "
       + descr
       + "               }";
 }