Package com.comcast.cmb.common.model

Examples of com.comcast.cmb.common.model.CMBPolicy


       
        if (actionList.size() == 0) {
            throw new CMBException(CMBErrorCodes.NotFound, "ActionName is required");
        }
       
        CMBPolicy policy = null;
    CNSTopicAttributes attributes = CNSCache.getTopicAttributes(topicArn);

        // validate policy string
       
        if (attributes.getPolicy() != null) {
          policy = new CMBPolicy(attributes.getPolicy());
        } else {
          policy = new CMBPolicy();
        }

        if (policy.addStatement(CMBPolicy.SERVICE.CNS, label, "Allow", userList, actionList, topicArn, null)) {
          attributes.setPolicy(policy.toString());
          PersistenceFactory.getCNSAttributePersistence().setTopicAttributes(attributes, topicArn);
        } else {
          throw new CMBException(CMBErrorCodes.InvalidParameterValue, "Value " + label + " for parameter Label is invalid. Reason: Already exists.");
        }
View Full Code Here


        if (!Util.isValidId(label)) {
            throw new CMBException(CQSErrorCodes.InvalidBatchEntryId, "Label " + label + " is invalid. Only alphanumeric, hyphen, and underscore are allowed. It can be at most " + CMBProperties.getInstance().getCQSMaxMessageSuppliedIdLength() + " letters long.");
        }
       
        CMBPolicy policy = null;

    CNSTopicAttributes attributes = CNSCache.getTopicAttributes(topicArn);

        // validate policy string
       
        if (attributes.getPolicy() != null) {

          policy = new CMBPolicy(attributes.getPolicy());
           
          if (policy.removeStatement(label)) {
              attributes.setPolicy(policy.toString());
            PersistenceFactory.getCNSAttributePersistence().setTopicAttributes(attributes, topicArn);
            }
        }
       
        String out = CNSAttributePopulator.getRemovePermissionResponse();
View Full Code Here

      } else if (attributeName.equals("Policy")) {     
       
      // validate policy before updating
     
      try {
        new CMBPolicy(attributeValue);
      } catch (Exception ex) {
                logger.warn("event=invalid_policy topic_arn=" + topicArn + " policy=" + attributeValue, ex);
          throw ex;
        }
View Full Code Here

    } catch (Exception ex) {
      logger.error("event=get_topic_attributes topic_arn=" + topicArn + " user_id=" + userId, ex);
      throw new ServletException(ex);
    }
   
    CMBPolicy policy = null;
   
    try {
      if (attributes.get("Policy") != null && !attributes.get("Policy").equals("") && !attributes.get("Policy").equals("null")) {
        policy = new CMBPolicy(attributes.get("Policy"));
      }
    } catch (Exception ex) {
      throw new ServletException(ex);
    }
   
    out.println("<html>");
   
    header(request, out, "Permissions for Topic "+ Util.getNameFromTopicArn(topicArn));
   
    out.println("<body>");

    out.println("<h2>Permissions for Topic "+ Util.getNameFromTopicArn(topicArn) + "</h2>");
   
    if (user != null) {
     
      out.println("<table><tr><td><b>User Name:</b></td><td>"+ user.getUserName()+"</td></tr>");
      out.println("<tr><td><b>User ID:</b></td><td>"+ user.getUserId()+"</td></tr>");
      out.println("<tr><td><b>Access Key:</b></td><td>"+user.getAccessKey()+"</td></tr>");
      out.println("<tr><td><b>Access Secret:</b></td><td>"+user.getAccessSecret()+"</td></tr>");
      out.println("<tr><td><b>Topic Name:</b></td><td>"+Util.getNameFromTopicArn(topicArn)+"</td></tr>");
      out.println("<tr><td><b>Topic Arn:</b></td><td>"+topicArn+"</td></tr></table><br>");
    }
   
    if (policy != null && !policy.getStatements().isEmpty()) {
     
      List<CMBStatement> stmts = policy.getStatements();
     
      if (stmts != null && stmts.size() > 0) {
        out.println("<span class='content'><table border='1' width='70%'><tr><th>Effect</th><th>Users</th><th>Actions</th><th>Label</th><th>&nbsp;</th></tr>");
      }
     
View Full Code Here

        String topicArn = request.getParameter("TopicArn");
           
        CNSTopicAttributes attributes = CNSCache.getTopicAttributes(topicArn);         
            if (attributes != null) {
                if (!actionMap.get(action).isActionAllowed(user, request, "CNS", new CMBPolicy(attributes.getPolicy()))) {
                    throw new CMBException(CMBErrorCodes.AccessDenied, "You don't have permission for " + actionMap.get(action).getName());
                }
            }
      }
View Full Code Here

    } catch (Exception ex) {
      logger.error("event_failed_to_get_attributes queue_url=" + queueUrl, ex);
      throw new ServletException(ex);
    }
   
    CMBPolicy policy;
   
    try {
      policy = new CMBPolicy(attributes.get("Policy"));
    } catch (Exception ex) {
      throw new ServletException(ex);
    }
   
    if (policy != null && !policy.getStatements().isEmpty()) {
     
      List<CMBStatement> stmts = policy.getStatements();
     
      if (stmts != null && stmts.size() > 0) {
        out.println("<span class='content'><table border='1' width='70%'><tr><th>Effect</th><th>Principals</th><th>Actions</th><th>Label</th><th>&nbsp;</th></tr>");
      }
     
View Full Code Here

            if (value != null && !value.equals("")) {
               
              // validate policy before updating
             
              try {
                new CMBPolicy(value);
              } catch (Exception ex) {
                      logger.warn("event=invalid_policy queue_url=" + queue.getRelativeUrl() + " policy=" + value, ex);
                throw ex;
              }
            }
View Full Code Here

        if (!Util.isValidId(label)) {
            throw new CMBException(CQSErrorCodes.InvalidBatchEntryId, "Label " + label + " is invalid. Only alphanumeric, hyphen, and underscore are allowed. It can be at most " + CMBProperties.getInstance().getCQSMaxMessageSuppliedIdLength() + " letters long.");
        }
       
        CMBPolicy policy = new CMBPolicy(queue.getPolicy());
       
        if (policy.removeStatement(label)) {
            String policyStr = policy.toString();
            PersistenceFactory.getQueuePersistence().updatePolicy(queue.getRelativeUrl(), policyStr);
            queue.setPolicy(policyStr);
        }
       
        String out = CQSQueuePopulator.getRemovePermissionResponse();
View Full Code Here

            queue = CQSCache.getCachedQueue(user, request);
      }

        if (isAuthenticationRequired(action)) {
       
            CMBPolicy policy = new CMBPolicy();
           
            if (queue != null) {
              policy.fromString(queue.getPolicy());
            }
           
            if (!actionMap.get(action).isActionAllowed(user, request, "CQS", policy)) {
                throw new CMBException(CMBErrorCodes.AccessDenied, "You don't have permission for " + actionMap.get(action).getName());
            }
View Full Code Here

       
        if (actionList.size() == 0) {
            throw new CMBException(CMBErrorCodes.NotFound, "ActionName is required");
        }
       
        CMBPolicy policy = new CMBPolicy(queue.getPolicy());
       
        if (policy.addStatement(CMBPolicy.SERVICE.CQS, label, "Allow", userList, actionList, queue.getArn(), null)) {
            PersistenceFactory.getQueuePersistence().updatePolicy(queue.getRelativeUrl(), policy.toString());
            queue.setPolicy(policy.toString());
        } else {
          throw new CMBException(CMBErrorCodes.InvalidParameterValue, "Value " + label + " for parameter Label is invalid. Reason: Already exists.");
        }
       
        String out = CQSQueuePopulator.getAddPermissionResponse();
View Full Code Here

TOP

Related Classes of com.comcast.cmb.common.model.CMBPolicy

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.