Package net.jini.core.constraint

Examples of net.jini.core.constraint.InvocationConstraint


     *            object to check
     * @return true if the returned result is equal to the expected one or
     *         false otherwise
     */
    public boolean checker(TestCase tc) {
        InvocationConstraint ic_init = tc.getInvocationConstraint1();
        InvocationConstraint ic_toCompare = tc.getInvocationConstraint2();
        InvocationConstraint ic_after = null;
        logger.log(Level.FINE,
                "Invocation Constraint before serialization:: " + ic_init);
        logger.log(Level.FINE, "serialization ...");
        logger.log(Level.FINE, "deserialization ...");

View Full Code Here


         * of the original object, as deserialized from the contained byte
         * stream.
         */
        try {
            MarshalledObject mObj = new MarshalledObject(ic);
            InvocationConstraint dic = (InvocationConstraint) mObj.get();
            logger.log(Level.FINE,
                    "Invocation Constraint after deserialization:: " + dic);
            return (dic == ic);
        } catch (Exception e) {
            logger.log(Level.FINE, e + "has been thrown while serialization or"
View Full Code Here

                || tc == CL_MAX_PR_TYPE__ARRAY
                || tc == CL_MIN_PR_TYPE__ARRAY) {
            cl_copy = new Class[cl.length];
            System.arraycopy(cl, 0, cl_copy, 0, cl.length);
        }
        InvocationConstraint ic = null;

        try {
            if (       tc == CL_MAX_PR_TYPE__CLASS
                    || tc == CL_MAX_PR_TYPE__CLASS__NULL) {
                // Invoking ClientMaxPrincipalType(Class clazz) constructor
                ic = new ClientMaxPrincipalType((Class) cl[0]);
            } else if (tc == CL_MIN_PR_TYPE__CLASS
                    || tc == CL_MIN_PR_TYPE__CLASS__NULL) {
                // Invoking ClientMinPrincipalType(Class clazz) constructor
                ic = new ClientMinPrincipalType((Class) cl[0]);
            } else if (tc == CL_MAX_PR_TYPE__ARRAY
                    || tc == CL_MAX_PR_TYPE__ARRAY__NULL
                    || tc == CL_MAX_PR_TYPE__ARRAY__NULL_EL
                    || tc == CL_MAX_PR_TYPE__ARRAY__EMPTY
                    || tc == CL_MAX_PR_TYPE__ARRAY__PRIM_TYPE
                    || tc == CL_MAX_PR_TYPE__ARRAY__ARRAY_TYPE
                    || tc == CL_MAX_PR_TYPE__ARRAY__NOT_PRINCIPAL) {
                // Invoking ClientMaxPrincipalType(Class[] classes) constructor
                ic = new ClientMaxPrincipalType((Class[]) cl);
            } else if (tc == CL_MIN_PR_TYPE__ARRAY
                    || tc == CL_MIN_PR_TYPE__ARRAY__NULL
                    || tc == CL_MIN_PR_TYPE__ARRAY__NULL_EL
                    || tc == CL_MIN_PR_TYPE__ARRAY__EMPTY
                    || tc == CL_MIN_PR_TYPE__ARRAY__PRIM_TYPE
                    || tc == CL_MIN_PR_TYPE__ARRAY__ARRAY_TYPE
                    || tc == CL_MIN_PR_TYPE__ARRAY__NOT_PRINCIPAL) {
                // Invoking ClientMinPrincipalType(Class[] classes) constructor
                ic = new ClientMinPrincipalType((Class[]) cl);
            }

            // If some Exception is expected
            if (       tc == CL_MAX_PR_TYPE__CLASS__NULL
                    || tc == CL_MIN_PR_TYPE__CLASS__NULL
                    || tc == CL_MAX_PR_TYPE__ARRAY__NULL
                    || tc == CL_MAX_PR_TYPE__ARRAY__NULL_EL
                    || tc == CL_MAX_PR_TYPE__ARRAY__EMPTY
                    || tc == CL_MAX_PR_TYPE__ARRAY__PRIM_TYPE
                    || tc == CL_MAX_PR_TYPE__ARRAY__ARRAY_TYPE
                    || tc == CL_MAX_PR_TYPE__ARRAY__NOT_PRINCIPAL
                    || tc == CL_MIN_PR_TYPE__ARRAY__NULL
                    || tc == CL_MIN_PR_TYPE__ARRAY__NULL_EL
                    || tc == CL_MIN_PR_TYPE__ARRAY__EMPTY
                    || tc == CL_MIN_PR_TYPE__ARRAY__PRIM_TYPE
                    || tc == CL_MIN_PR_TYPE__ARRAY__ARRAY_TYPE
                    || tc == CL_MIN_PR_TYPE__ARRAY__NOT_PRINCIPAL) {
                logger.log(Level.FINE, "Expected Exception type:: " + ex);
                throw new TestException("Instead of " + ex + " no Exception"
                        + " has been thrown while invoking constructor");
            }
        } catch (Exception e) {
            logger.log(Level.FINE, "Exception while invoking constructor " + e);
            // If no Exception is expected
            if (       tc == CL_MAX_PR_TYPE__CLASS
                    || tc == CL_MIN_PR_TYPE__CLASS
                    || tc == CL_MAX_PR_TYPE__ARRAY
                    || tc == CL_MIN_PR_TYPE__ARRAY) {
                throw new TestException("Exception while invoking constructor ",
                        e);
            }

            // If some Exception is expected
            if (!ex.equals(e.getClass())) {
                logger.log(Level.FINE, "Expected Exception:: " + ex);
                logger.log(Level.FINE, "Thrown   Exception:: " + e.getClass());
                throw new TestException("Instead of " + ex + " "
                        + e.getClass() + " has been thrown while"
                        + " invoking constructor");
            } else {
                return;
            }
        }

        // logger.log(Level.INFO, "Returned object: " + ic.toString());

        /*
         * Verify that the corresponding constraint object is created.
         */
        if (ic == null) {
            logger.log(Level.FINE, "Constraint object hasn't been created");
            throw new TestException("Constraint object hasn't been created");
        }

        if (       (tc == CL_MAX_PR_TYPE__CLASS
                 || tc == CL_MAX_PR_TYPE__ARRAY)
                && !(ic instanceof ClientMaxPrincipalType)) {
            logger.log(Level.FINE,
                    "Instead of ClientMaxPrincipalType " + ic.getClass()
                    + " object is returned");
            throw new TestException("Instead of ClientMaxPrincipalType "
                    + ic.getClass() + " object is returned");
        } else if ((tc == CL_MIN_PR_TYPE__CLASS
                 || tc == CL_MIN_PR_TYPE__ARRAY)
                && !(ic instanceof ClientMinPrincipalType)) {
            logger.log(Level.FINE,
                    "Instead of ClientMinPrincipalType " + ic.getClass()
                    + " object is returned");
            throw new TestException("Instead of ClientMinPrincipalType "
                    + ic.getClass() + " object is returned");
        }

        /*
         * Verify that the argument passed to the constructor isn't modified.
         * Compare argument for the constructor before and after invoking the
         * constructor.
         */

        // logger.log(Level.INFO, "Argument before invoking the constructor:");
        // for (int i = 0; i < cl_copy.length; i++) {
        // logger.log(Level.INFO, "cl_copy[" + i + "]:: " + cl_copy[i]);
        // }
        // logger.log(Level.INFO, "Argument after invoking the constructor :");
        // for (int i = 0; i < cl.length; i++) {
        // logger.log(Level.INFO, "cl[" + i + "]:: " + cl[i]);
        // }
        if (!Arrays.equals(cl, cl_copy)) {
            logger.log(Level.FINE,
                    "The argument passed to the constructor is modified");
            throw new TestException("The argument passed to the constructor"
                    + " is modified");
        }
        logger.log(Level.FINE,
                "The argument passed to the constructor isn't modified");

        /*
         * Verify that the argument passed to the constructor isn't retained;
         * subsequent changes to that argument have no effect on the instance
         * created. Compare set of all of the classes from the created
         * object before and after changing the argument.
         */
        Set icSet_before = null;

        try {
            Class icClass = ic.getClass();
            Method elementsMethod = icClass.getMethod("elements", null);
            // Get set of classes from the created constraint
            icSet_before = (Set) elementsMethod.invoke(ic, null);

            /*
 
View Full Code Here

        ArrayList cl_copy = null;
        if (       tc == CL_MAX_PR_TYPE__COLL
                || tc == CL_MIN_PR_TYPE__COLL) {
            cl_copy = new ArrayList(cl);
        }
        InvocationConstraint ic = null;

        try {
            if (       tc == CL_MAX_PR_TYPE__COLL
                    || tc == CL_MAX_PR_TYPE__COLL__NULL
                    || tc == CL_MAX_PR_TYPE__COLL__NULL_EL
                    || tc == CL_MAX_PR_TYPE__COLL__EMPTY
                    || tc == CL_MAX_PR_TYPE__COLL__ILL_EL
                    || tc == CL_MAX_PR_TYPE__COLL__PRIM_TYPE
                    || tc == CL_MAX_PR_TYPE__COLL__ARRAY_TYPE
                    || tc == CL_MAX_PR_TYPE__COLL__NOT_PRINCIPAL) {
                // Invoking ClientMaxPrincipalType(Collection classes) constructor
                ic = new ClientMaxPrincipalType((Collection) cl);
            } else if (tc == CL_MIN_PR_TYPE__COLL
                    || tc == CL_MIN_PR_TYPE__COLL__NULL
                    || tc == CL_MIN_PR_TYPE__COLL__NULL_EL
                    || tc == CL_MIN_PR_TYPE__COLL__EMPTY
                    || tc == CL_MIN_PR_TYPE__COLL__ILL_EL
                    || tc == CL_MIN_PR_TYPE__COLL__PRIM_TYPE
                    || tc == CL_MIN_PR_TYPE__COLL__ARRAY_TYPE
                    || tc == CL_MIN_PR_TYPE__COLL__NOT_PRINCIPAL) {
                // Invoking ClientMinPrincipalType(Collection classes) constructor
                ic = new ClientMinPrincipalType((Collection) cl);
            }

            // If some Exception is expected
            if (       tc == CL_MAX_PR_TYPE__COLL__NULL
                    || tc == CL_MAX_PR_TYPE__COLL__NULL_EL
                    || tc == CL_MAX_PR_TYPE__COLL__EMPTY
                    || tc == CL_MAX_PR_TYPE__COLL__ILL_EL
                    || tc == CL_MAX_PR_TYPE__COLL__PRIM_TYPE
                    || tc == CL_MAX_PR_TYPE__COLL__ARRAY_TYPE
                    || tc == CL_MAX_PR_TYPE__COLL__NOT_PRINCIPAL
                    || tc == CL_MIN_PR_TYPE__COLL__NULL
                    || tc == CL_MIN_PR_TYPE__COLL__NULL_EL
                    || tc == CL_MIN_PR_TYPE__COLL__EMPTY
                    || tc == CL_MIN_PR_TYPE__COLL__ILL_EL
                    || tc == CL_MIN_PR_TYPE__COLL__PRIM_TYPE
                    || tc == CL_MIN_PR_TYPE__COLL__ARRAY_TYPE
                    || tc == CL_MIN_PR_TYPE__COLL__NOT_PRINCIPAL) {
                logger.log(Level.FINE, "Expected Exception type:: " + ex);
                throw new TestException("Instead of " + ex + " no Exception"
                        + " has been thrown while invoking constructor");
            }
        } catch (Exception e) {
            logger.log(Level.FINE, "Exception while invoking constructor: " + e);
            // If no Exception is expected
            if (       tc == CL_MAX_PR_TYPE__COLL
                    || tc == CL_MIN_PR_TYPE__COLL) {
                throw new TestException(
                        "Exception while invoking constructor", e);
            }

            // If some Exception is expected
            if (!ex.equals(e.getClass())) {
                logger.log(Level.FINE, "Expected Exception:: " + ex);
                logger.log(Level.FINE, "Thrown   Exception:: " + e.getClass());
                throw new TestException("Instead of " + ex + " "
                        + e.getClass() + " has been thrown while"
                        + " invoking constructor");
            } else {
                return;
            }
        }

        // logger.log(Level.INFO, "Returned object: " + ic.toString());

        /*
         * Verify that the corresponding constraint object is created.
         */
        if (ic == null) {
            logger.log(Level.FINE, "Constraint object hasn't been created");
            throw new TestException("Constraint object hasn't been created");
        }

        if (       tc == CL_MAX_PR_TYPE__COLL
                && !(ic instanceof ClientMaxPrincipalType)) {
            logger.log(Level.FINE,
                    "Instead of ClientMaxPrincipalType " + ic.getClass()
                    + " object is returned");
            throw new TestException("Instead of ClientMaxPrincipalType "
                    + ic.getClass() + " object is returned");
        } else if (tc == CL_MIN_PR_TYPE__COLL
                && !(ic instanceof ClientMinPrincipalType)) {
            logger.log(Level.FINE,
                    "Instead of ClientMinPrincipalType " + ic.getClass()
                    + " object is returned");
            throw new TestException("Instead of ClientMinPrincipalType "
                    + ic.getClass() + " object is returned");
        }

        /*
         * Verify that the argument passed to the constructor isn't modified.
         * Compare argument for the constructor before and after invoking the
         * constructor.
         */

        // logger.log(Level.INFO, "Argument before invoking the constructor: "
        // + cl_copy);
        // logger.log(Level.INFO, "Argument after invoking the constructor : "
        // + cl);
        if (!cl.equals(cl_copy)) {
            logger.log(Level.FINE,
                    "The argument passed to the constructor is modified");
            throw new TestException("The argument passed to the constructor"
                    + " is modified");
        }
        logger.log(Level.FINE,
                "The argument passed to the constructor isn't modified");

        /*
         * Verify that the argument passed to the constructor isn't retained;
         * subsequent changes to that argument have no effect on the instance
         * created. Compare set of all of the classes from the created
         * object before and after changing the argument.
         */
        Set icSet_before = null;

        try {
            Class icClass = ic.getClass();
            Method elementsMethod = icClass.getMethod("elements", null);
            // Get set of classes from the created constraint
            icSet_before = (Set) elementsMethod.invoke(ic, null);

            /*
 
View Full Code Here

            /*
             * Try to call the constructor
             */
            long retTime = (long) -1;
            InvocationConstraint constraint = null;

            try {
               
                if (       constructorType == CONNECTION_ABSOLUTE_TIME) {
                    constraint = new ConnectionAbsoluteTime(argument);
View Full Code Here

                    "Expected type of exception:: " + expExceptionClass);

            /*
             * Try to call the constructor
             */
            InvocationConstraint constraint = null;

            try {
               
                if (       constructorType == DELEGATION_ABSOLUTE_TIME__DATE) {
                    Date minStartDate = (minStart == Long.MIN_VALUE) ?
                                        null : new Date(minStart);
                    Date maxStartDate = (maxStart == Long.MIN_VALUE) ?
                                        null : new Date(maxStart);
                    Date minStopDate = (minStop == Long.MIN_VALUE) ?
                                        null : new Date(minStop);
                    Date maxStopDate  = (maxStop == Long.MIN_VALUE) ?
                                        null : new Date(maxStop);
                    logger.log(Level.FINE,"\tminStart:: " + minStartDate);
                    logger.log(Level.FINE,"\tmaxStart:: " + maxStartDate);
                    logger.log(Level.FINE,"\tminStop :: " + minStopDate);
                    logger.log(Level.FINE,"\tmaxStop :: " + maxStopDate);
                    constraint = new DelegationAbsoluteTime(minStartDate,
                                                            maxStartDate,
                                                            minStopDate,
                                                            maxStopDate);
                } else if (constructorType == DELEGATION_ABSOLUTE_TIME__LONG) {
                    constraint = new DelegationAbsoluteTime(minStart, maxStart,
                                                            minStop, maxStop);
                } else if (constructorType == DELEGATION_RELATIVE_TIME__LONG) {
                    constraint = new DelegationRelativeTime(minStart, maxStart,
                                                            minStop, maxStop);
                }
                logger.log(Level.INFO, "Created constraint: " + constraint);
            } catch (Exception e) {
                logger.log(Level.FINE,
                        "Exception while invoking the constructor: " + e);
                // If no exception is expected
                if (expExceptionClass == null) {
                    throw new TestException("No exception is expected, but"
                            + " really " + e + " exception has been thrown"
                            + " while invoking the constructor");
                }

                // An exception is expected
                if (!(e.getClass()).equals(expExceptionClass)) {
                    throw new TestException("Instead of exception of "
                            + expExceptionClass + " exception of " + e.getClass()
                            + " has been thrown");
                }
                return;
            }

            // If an exception is expected
            if (expExceptionClass != null) {
                throw new TestException("Exception of type "
                        + expExceptionClass + " is expected, but really no"
                        + " exception has been thrown while invoking the"
                        + " constructor");
            }

            // No exception is expected
            try {
                Class cl = constraint.getClass();
                Method getMinStartMethod = cl.getMethod("getMinStart", null);
                Method getMaxStartMethod = cl.getMethod("getMaxStart", null);
                Method getMinStopMethod = cl.getMethod("getMinStop", null);
                Method getMaxStopMethod = cl.getMethod("getMaxStop", null);
                // Get the values from the created constraint and verify them
View Full Code Here

            logger.log(Level.INFO, "--> " + testCase);
           
            // 1
            String name = "someMethod";
            Class[] types = new Class[] {int.class, Object.class};
            InvocationConstraint ic = Delegation.YES;
            InvocationConstraints constraints = new InvocationConstraints(
                    ic, null);
            callConstructor(testCase, name, types, constraints);
           
            // 2
View Full Code Here

         regardless whether the caller has the getSubject
         permission */
      for (Iterator iter = constraints.requirements().iterator();
     iter.hasNext(); )
      {
    InvocationConstraint c = (InvocationConstraint) iter.next();
    if (!KerberosUtil.isSupportableConstraint(c)) {
        errorCode = UNSUPPORTABLE_CONSTRAINT_REQUIRED;
        detailedExceptionMsg = "A constraint unsupportable by " +
      "this endpoint has been required: " + c;
        return;
    }
      }

      /* All Kerberos principals allowed by the constraints.  If
         the resulting set is empty, it means no client min/max
         principal constraints found in the constraints, instead
         of no principals allowed. */
      clientPrincipals = new HashSet();
      for (Iterator iter = constraints.requirements().iterator();
     iter.hasNext(); )
      {
    if (!KerberosUtil.collectCpCandidates(
        (InvocationConstraint) iter.next(),
        clientPrincipals))
    {
        errorCode = UNSUPPORTABLE_CONSTRAINT_REQUIRED;
        detailedExceptionMsg = "Client principal constraint " +
      "related conflicts found in the given set of " +
      "constraints: " + constraints;
        return;
    }
      }

      if (clientSubject == null) {
    errorCode = NULL_SUBJECT;
    detailedExceptionMsg = "JAAS login has not been done " +
        "properly, the subject associated with the current " +
        "AccessControlContext is null.";
    return;
      }

      this.clientSubject = clientSubject;
      this.constraints = constraints;

      subjectReadOnly = clientSubject.isReadOnly();
      subjectClientPrincipals = getClientPrincipals(clientSubject);

      if (subjectClientPrincipals.size() == 0) {
    errorCode = NO_CLIENT_PRINCIPAL;
    detailedExceptionMsg = "JAAS login has not been done " +
        "properly, the subject associated with the current " +
        "AccessControlContext contains no KerberosPrincipal.";
    return;
      }

      if (clientPrincipals.size() > 0) {
    clientPrincipals.retainAll(subjectClientPrincipals);
      } else {
    clientPrincipals = subjectClientPrincipals;
      }

      boolean canDeleg = false;
      if (KerberosUtil.containsConstraint(
    constraints.requirements(), Delegation.YES) ||
    KerberosUtil.containsConstraint(
        constraints.preferences(), Delegation.YES))
      {
    canDeleg = true;
      }

      // enumerate all possible configs and filter them by constraints
      ArrayList configArr = new ArrayList();
    outer:
      for (ConfigIter citer = new ConfigIter(
         clientPrincipals, serverPrincipal, canDeleg);
     citer.hasNext(); )
      {
    Config config = citer.next();
    for (Iterator jter = constraints.requirements().iterator();
         jter.hasNext(); )
    {
        InvocationConstraint c =
      (InvocationConstraint) jter.next();
        if (!KerberosUtil.isSatisfiable(config, c))
      continue outer;
    }
    configArr.add(config);
      }

      if (configArr.size() == 0) {
    errorCode = UNSATISFIABLE_CONSTRAINT_REQUIRED;
    detailedExceptionMsg = "Constraints unsatisfiable by this " +
        "endpoint with the current subject have been required: " +
        constraints + ", while the KerberosPrincipal set of " +
        "the subject is: " + subjectClientPrincipals;
    return;
      }

      configs = (Config[]) configArr.toArray(
    new Config[configArr.size()]);

      // reorder configs by the num of preferences a config can satisfy
      for (int i = 0; i < configs.length; i++) {
    for (Iterator iter = constraints.preferences().iterator();
         iter.hasNext(); )
          {
        InvocationConstraint c =
      (InvocationConstraint) iter.next();
        if (KerberosUtil.isSatisfiable(configs[i], c))
      configs[i].prefCount++;
    }
      }
View Full Code Here

  try {
      // check for unsupportable constraints
      for (Iterator iter = constraints.requirements().iterator();
     iter.hasNext(); )
      {
    InvocationConstraint c = (InvocationConstraint)iter.next();
    if (!KerberosUtil.isSupportableConstraint(c)) {
        throw new UnsupportedConstraintException(
      "A constraint unsupportable by this endpoint " +
      "has been required: " + c);
    }
      }

      if (getKey(serverSubject, serverPrincipal) == null) {
    throw new UnsupportedConstraintException(
        "Failed to find a valid Kerberos key " +
        "corresponding to serverPrincipal (" + serverPrincipal +
        ") in serverSubject.");
      }

      // now check whether the constraints are satisfiable
     
      // first find all client principal candidates in constraints
      HashSet cpCandidates = new HashSet();
      for (Iterator iter = constraints.requirements().iterator();
     iter.hasNext(); )
      {
    if (!KerberosUtil.collectCpCandidates(
        (InvocationConstraint) iter.next(), cpCandidates))
    {
        throw new UnsupportedConstraintException(
      "Client principal constraint related conflicts " +
      "found in the given set of constraints: " +
      constraints);
    }
      }

      if (cpCandidates.size() == 0) {
    /* no client principal constraints is required, anyone
       will pass */
    cpCandidates.add(new KerberosPrincipal("anyone"));
      }

      // look for a satisfiable config
      boolean doable = false;
      ConfigIter citer =
    new ConfigIter(cpCandidates, serverPrincipal, true);
    outer:
      while (citer.hasNext()) {
    Config config = citer.next();
    for (Iterator iter = constraints.requirements().iterator();
         iter.hasNext(); )
    {
        InvocationConstraint c =
      (InvocationConstraint) iter.next();
        if (!KerberosUtil.isSatisfiable(config, c))
      continue outer;
    }
    doable = true;
View Full Code Here

      // no cached result, has to do the whole analysis     
      for (Iterator iter = constraints.requirements().iterator();
     iter.hasNext(); )
      {
    try {
        InvocationConstraint c =
      (InvocationConstraint) iter.next();
        if (!KerberosUtil.isSupportableConstraint(c)) {
      UnsupportedConstraintException e =
          new UnsupportedConstraintException(
        "A constraint unsupportable by this " +
View Full Code Here

TOP

Related Classes of net.jini.core.constraint.InvocationConstraint

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.