Example #1
0
 /**
  * Finds method that accessible from specified class.
  *
  * @param method object that represents found method
  * @param generic generic type that is used to find accessible method
  * @return object that represents accessible method
  * @throws NoSuchMethodException if method is not accessible or is not found in specified
  *     superclass or interface
  */
 private static Method findAccessibleMethod(Method method, Type generic)
     throws NoSuchMethodException {
   String name = method.getName();
   Class<?>[] params = method.getParameterTypes();
   if (generic instanceof Class) {
     Class<?> type = (Class<?>) generic;
     return findAccessibleMethod(type.getMethod(name, params));
   }
   if (generic instanceof ParameterizedType) {
     ParameterizedType pt = (ParameterizedType) generic;
     Class<?> type = (Class<?>) pt.getRawType();
     for (Method m : type.getMethods()) {
       if (m.getName().equals(name)) {
         Class<?>[] pts = m.getParameterTypes();
         if (pts.length == params.length) {
           if (Arrays.equals(params, pts)) {
             return findAccessibleMethod(m);
           }
           Type[] gpts = m.getGenericParameterTypes();
           if (params.length == gpts.length) {
             if (Arrays.equals(params, TypeResolver.erase(TypeResolver.resolve(pt, gpts)))) {
               return findAccessibleMethod(m);
             }
           }
         }
       }
     }
   }
   throw new NoSuchMethodException("Method '" + name + "' is not accessible");
 }
Example #2
0
 /**
  * Compares this finite field for equality with the specified object.
  *
  * @param obj the object to be compared.
  * @return true if {@code obj} is an instance of ECFieldF2m and both {@code m} and the reduction
  *     polynomial match, false otherwise.
  */
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj instanceof ECFieldF2m) {
     // no need to compare rp here since ks and rp
     // should be equivalent
     return ((m == ((ECFieldF2m) obj).m) && (Arrays.equals(ks, ((ECFieldF2m) obj).ks)));
   }
   return false;
 }
Example #3
0
  /**
   * This method may return false negatives. But if it says two names are equals, then there is some
   * mechanism that authenticates them as the same principal.
   */
  public boolean equals(GSSName other) throws GSSException {

    if (this.isAnonymous() || other.isAnonymous()) return false;

    if (other == this) return true;

    if (!(other instanceof GSSNameImpl))
      return equals(gssManager.createName(other.toString(), other.getStringNameType()));

    /*
     * XXX Do a comparison of the appNameStr/appNameBytes if
     * available. If that fails, then proceed with this test.
     */

    GSSNameImpl that = (GSSNameImpl) other;

    GSSNameSpi myElement = this.mechElement;
    GSSNameSpi element = that.mechElement;

    /*
     * XXX If they are not of the same mechanism type, convert both to
     * Kerberos since it is guaranteed to be present.
     */
    if ((myElement == null) && (element != null)) {
      myElement = this.getElement(element.getMechanism());
    } else if ((myElement != null) && (element == null)) {
      element = that.getElement(myElement.getMechanism());
    }

    if (myElement != null && element != null) {
      return myElement.equals(element);
    }

    if ((this.appNameType != null) && (that.appNameType != null)) {
      if (!this.appNameType.equals(that.appNameType)) {
        return false;
      }
      byte[] myBytes = null;
      byte[] bytes = null;
      try {
        myBytes = (this.appNameStr != null ? this.appNameStr.getBytes("UTF-8") : this.appNameBytes);
        bytes = (that.appNameStr != null ? that.appNameStr.getBytes("UTF-8") : that.appNameBytes);
      } catch (UnsupportedEncodingException e) {
        // Won't happen
      }

      return Arrays.equals(myBytes, bytes);
    }

    return false;
  }