Exemplo n.º 1
0
        public void testMoreElementHashtableKeyEnumerator()
        {
            java.util.Hashtable <String, String> nameWert = new java.util.Hashtable <String, String>();
            nameWert.put("1", "one");
            nameWert.put("2", "one");

            java.util.Enumeration <String> names = nameWert.keys();

            Assert.True(names.hasMoreElements());
            names.nextElement();
            Assert.True(names.hasMoreElements());
            names.nextElement();
            Assert.False(names.hasMoreElements());
        }
Exemplo n.º 2
0
        private bool defaultImplies(ProtectionDomain domain, Permission permission)
        {
            if (domain == null && permission == null)
            {
                throw new java.lang.NullPointerException();
            }
            bool implies = false;

            if (domain != null)
            {
                PermissionCollection total    = getPermissions(domain);
                PermissionCollection inherent = domain.getPermissions();
                if (inherent != null)
                {
                    java.util.Enumeration <Permission> en = inherent.elements();
                    while (en.hasMoreElements())
                    {
                        total.add(en.nextElement());
                    }
                }
                try {
                    implies = total.implies(permission);
                } catch (java.lang.NullPointerException) {
                    // return false instead of throwing the NullPointerException
                    implies = false;
                }
            }
            return(implies);
        }
Exemplo n.º 3
0
        /**
         * Returns a {@code PermissionCollection} describing what permissions are
         * allowed for the specified {@code ProtectionDomain} (more specifically,
         * its {@code CodeSource}) based on the current security policy.
         * <p />
         * Note that this method is not called for classes which are in the
         * system domain (i.e. system classes). System classes are always
         * given full permissions (i.e. AllPermission). This can not be changed by
         * installing a new policy.
         *
         * @param domain
         *            the {@code ProtectionDomain} to compute the permissions for.
         * @return the permissions that are granted to the specified {@code
         *         CodeSource}.
         */
        public PermissionCollection getPermissions(ProtectionDomain domain)
        {
            Permissions permissions = new Permissions();

            if (domain != null)
            {
                try {
                    PermissionCollection cds = getPermissions(domain
                                                              .getCodeSource());
                    if (cds != Policy.UNSUPPORTED_EMPTY_COLLECTION)
                    {
                        java.util.Enumeration <Permission> elements = cds.elements();
                        while (elements.hasMoreElements())
                        {
                            permissions.add(elements.nextElement());
                        }
                    }
                } catch (java.lang.NullPointerException) {
                    // ignore the exception, just add nothing to the result set
                }

                PermissionCollection pds = domain.getPermissions();
                if (pds != null)
                {
                    java.util.Enumeration <Permission> pdElements = pds.elements();
                    while (pdElements.hasMoreElements())
                    {
                        permissions.add(pdElements.nextElement());
                    }
                }
            }
            return(permissions);
        }
Exemplo n.º 4
0
        private static void Initialize()
        {
            VfsDirectory root = new VfsDirectory();

            root.AddDirectory("lib").AddDirectory("security").Add("cacerts", new VfsCacertsEntry());
            VfsDirectory bin = new VfsDirectory();

            root.Add("bin", bin);
            root.Add("assembly", new VfsAssembliesDirectory());
            AddDummyLibrary(bin, "zip");
            AddDummyLibrary(bin, "awt");
            AddDummyLibrary(bin, "rmi");
            AddDummyLibrary(bin, "w2k_lsa_auth");
            AddDummyLibrary(bin, "jaas_nt");
            AddDummyLibrary(bin, "jaas_unix");
            AddDummyLibrary(bin, "net");
            AddDummyLibrary(bin, "splashscreen");
            AddDummyLibrary(bin, "osx");
            AddDummyLibrary(bin, "management");
            bin.Add("java", new VfsJavaExe());
            bin.Add("javaw", new VfsJavaExe());
            bin.Add("java.exe", new VfsJavaExe());
            bin.Add("javaw.exe", new VfsJavaExe());

            // this is a weird loop back, the vfs.zip resource is loaded from vfs,
            // because that's the easiest way to construct a ZipFile from a Stream.
            java.util.zip.ZipFile zf = new java.util.zip.ZipFile(RootPath + "vfs.zip");
            java.util.Enumeration e  = zf.entries();
            while (e.hasMoreElements())
            {
                AddZipEntry(zf, root, (java.util.zip.ZipEntry)e.nextElement());
            }

            Interlocked.CompareExchange(ref VirtualFileSystem.root, root, null);
        }
Exemplo n.º 5
0
        /*
         * Returns a string containing a concise, human-readable description of this
         * {@code PermissionCollection}.
         *
         * @return a printable representation for this {@code PermissionCollection}.
         */
        public override String ToString()
        {
            java.util.ArrayList <String>       elist  = new java.util.ArrayList <String>(100);
            java.util.Enumeration <Permission> elenum = elements();
            String superStr    = base.ToString();
            int    totalLength = superStr.length() + 5;

            if (elenum != null)
            {
                while (elenum.hasMoreElements())
                {
                    String el = elenum.nextElement().toString();
                    totalLength += el.length();
                    elist.add(el);
                }
            }
            int esize = elist.size();

            totalLength += esize * 4;
            java.lang.StringBuilder result = new java.lang.StringBuilder(totalLength).append(superStr)
                                             .append(" ("); //$NON-NLS-1$
            for (int i = 0; i < esize; i++)
            {
                result.append("\n ").append(elist.get(i).toString()); //$NON-NLS-1$
            }
            return(result.append("\n)\n").toString());                //$NON-NLS-1$
        }
Exemplo n.º 6
0
        void LoadWwwForm()
        {
            HttpServletRequest servletReq = context.ServletRequest;

            if (servletReq == null)
            {
                NameValueCollection requestParameters = context.RequestParameters;
                if (requestParameters != null)
                {
                    form.Add(requestParameters);
                }
                else
                {
                    RawLoadWwwForm();
                }
                return;
            }

            servletReq.setCharacterEncoding(ContentEncoding.WebName);

            for (java.util.Enumeration e = servletReq.getParameterNames(); e.hasMoreElements();)
            {
                string    key     = (string)e.nextElement();
                string [] qvalue  = QueryString.GetValues(key);
                string [] qfvalue = servletReq.getParameterValues(key);

                for (int i = (qvalue != null) ? qvalue.Length : 0; i < qfvalue.Length; i++)
                {
                    form.Add(key, qfvalue [i]);
                }
            }
        }
Exemplo n.º 7
0
        public override string [][] GetUnknownRequestHeaders()
        {
            if (unknownHeaders == null)
            {
                ArrayList pairs = new ArrayList();
                for (java.util.Enumeration he = getHeaderNames(); he.hasMoreElements();)
                {
                    string key   = (string)he.nextElement();
                    int    index = HttpWorkerRequest.GetKnownRequestHeaderIndex(key);
                    if (index != -1)
                    {
                        continue;
                    }
                    pairs.Add(new string [] { key, getHeader(key) });
                }

                if (pairs.Count != 0)
                {
                    unknownHeaders = new string [pairs.Count][];
                    for (int i = 0; i < pairs.Count; i++)
                    {
                        unknownHeaders [i] = (string [])pairs [i];
                    }
                }
            }
            if (unknownHeaders == null)
            {
                unknownHeaders = new string [0][];
            }

            return(unknownHeaders);
        }
Exemplo n.º 8
0
        /*
         * Adapter implementation method; do not call.
         * Adapt a SAX1 end element event.
         *
         * @param qName The qualified (prefixed) name.
         * @exception SAXException The client may raise a
         *            processing exception.
         * @see org.xml.sax.DocumentHandler#endElement
         */
        public void endElement(String qName)
        //throws SAXException
        {
            // If we're not doing Namespace
            // processing, dispatch this quickly.
            if (!namespaces)
            {
                if (contentHandler != null)
                {
                    contentHandler.endElement("", "", qName.intern());
                }
                return;
            }

            // Split the name.
            String[] names = processName(qName, false, false);
            if (contentHandler != null)
            {
                contentHandler.endElement(names[0], names[1], names[2]);
                java.util.Enumeration <Object> prefixes = nsSupport.getDeclaredPrefixes(); //FIXME use Enumeration<String>
                while (prefixes.hasMoreElements())
                {
                    String prefix = (String)prefixes.nextElement();
                    contentHandler.endPrefixMapping(prefix);
                }
            }
            nsSupport.popContext();
        }
Exemplo n.º 9
0
        private static IEnumerable ToEnumer(java.util.Enumeration enumeration)
        {
            List <object> list = new List <object>();

            while (enumeration.hasMoreElements())
            {
                list.Add(enumeration.nextElement());
            }
            return(list);
        }
Exemplo n.º 10
0
 /**
  * Constructs a new SequenceInputStream using the elements returned from
  * Enumeration {@code e} as the stream sequence. The instances returned by
  * {@code e.nextElement()} must be of type {@link InputStream}.
  *
  * @param e
  *            the enumeration of {@code InputStreams} to get bytes from.
  * @throws NullPointerException
  *             if any of the elements in {@code e} is {@code null}.
  */
 public SequenceInputStream(java.util.Enumeration<InputStream> e)
 {
     this.e = e;
     if (e.hasMoreElements ()) {
         inJ = e.nextElement ();
         if (inJ == null) {
             throw new java.lang.NullPointerException ();
         }
     }
 }
Exemplo n.º 11
0
        /*
         * Update rows which match a WHERE clause
         */
        private void UpdateStatement(String tableName, java.util.Vector <Object> c, java.util.Vector <Object> v, TinySQLWhere wc)
        //throws TinySQLException
        {
            /*
             *    Create a table object and put it in the Hashtable.
             */
            TinySQLTable jtbl = getTable(tableName);

            java.util.Hashtable <Object, Object> tables = new java.util.Hashtable <Object, Object>();
            tables.put(tableName, jtbl);
            String columnName, columnString, whereStatus;

            /*
             *    Process each row in the table ignoring deleted rows.
             */
            jtbl.GoTop();
            while (jtbl.NextRecord())
            {
                if (!jtbl.isDeleted())
                {
                    java.util.Enumeration <Object> cols = jtbl.column_info.keys();
                    whereStatus = "TRUE";
                    while (cols.hasMoreElements())
                    {
                        /*
                         *             Use the table name for the table alias for updates.
                         */
                        columnName = jtbl.table + "->" + jtbl.table
                                     + "." + (String)cols.nextElement();
                        columnString = jtbl.GetCol(columnName);

                        /*
                         *             Check the status of the where clause for each column value.
                         */
                        if (wc != (TinySQLWhere)null)
                        {
                            whereStatus = wc.evaluate(columnName, columnString);
                        }
                        if (whereStatus.equals("FALSE"))
                        {
                            break;
                        }
                    }
                    if (whereStatus.equals("TRUE"))
                    {
                        jtbl.UpdateCurrentRow(c, v);
                    }
                    if (wc != (TinySQLWhere)null)
                    {
                        wc.clearValues(jtbl.table + "->" + jtbl.tableAlias);
                    }
                }
            }
            jtbl.close();
        }
Exemplo n.º 12
0
        public static void Main(string[] args)
        {
            Properties pps = new Properties();

            if (System.IO.File.Exists(DEFAULT_FILE))
            {
                LoadLeapPropertiesFile();
            }
            else
            {
                p = new ProfileImpl();
            }

            if (args.Length > 0)
            {
                pps = jade.Boot.parseCmdLineArgs(args);

                if (pps != null)
                {
                    java.util.Enumeration en = pps.keys();
                    while (en.hasMoreElements())
                    {
                        string key  = (string)en.nextElement();
                        string prop = pps.getProperty(key);
                        p.setParameter(key, prop);
                    }    //End WHILE block
                }        //End IF block
            }            //End IF block

            /* VERSIONE 3.2 */
            jade.wrapper.AgentContainer mc = null;
            /* VERSIONE 3.1 */
            //jade.wrapper.MainContainer mc = null;

            try
            {
                if (p.getParameter("main", "true").Equals("false"))
                {
                    mc = Runtime.instance().createAgentContainer(p);
                }
                else
                {
                    mc = Runtime.instance().createMainContainer(p);
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("\n----------- INIZIO ECCEZIONE ------------------");
                Console.WriteLine(exc.Message);
                Console.WriteLine(exc.InnerException);
                Console.WriteLine("\n----------- FINE ECCEZIONE ------------------");
            }
            Console.ReadLine();
        }
Exemplo n.º 13
0
 /*
  * Indicates whether the argument permission is implied by the permissions
  * contained in the receiver.
  *
  * @return boolean <code>true</code> if the argument permission is implied
  *         by the permissions in the receiver, and <code>false</code> if
  *         it is not.
  * @param permission
  *            java.security.Permission the permission to check
  */
 public override bool implies(Permission permission)
 {
     for (java.util.Enumeration <Permission> elementsJ = elements(); elementsJ.hasMoreElements();)
     {
         if (((Permission)elementsJ.nextElement()).implies(permission))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 14
0
 /**
  * Constructs a new SequenceInputStream using the elements returned from
  * Enumeration {@code e} as the stream sequence. The instances returned by
  * {@code e.nextElement()} must be of type {@link InputStream}.
  *
  * @param e
  *            the enumeration of {@code InputStreams} to get bytes from.
  * @throws NullPointerException
  *             if any of the elements in {@code e} is {@code null}.
  */
 public SequenceInputStream(java.util.Enumeration <InputStream> e)
 {
     this.e = e;
     if (e.hasMoreElements())
     {
         inJ = e.nextElement();
         if (inJ == null)
         {
             throw new java.lang.NullPointerException();
         }
     }
 }
Exemplo n.º 15
0
 private java.util.Enumeration <Permission> getNextEnumeration()
 {
     while (pcIter.hasNext())
     {
         java.util.Enumeration <Permission> en = ((PermissionCollection)pcIter.next()).elements();
         if (en.hasMoreElements())
         {
             return(en);
         }
     }
     return(null);
 }
Exemplo n.º 16
0
        /// <summary inherit="yes"/>

        public override JProperties GetOutputProperties()
        {
            JProperties properties = (defaultOutputProperties == null ? new JProperties() : new JProperties(defaultOutputProperties));

            java.util.Enumeration propsEnum = props.keys();
            while (propsEnum.hasMoreElements())
            {
                object obj   = propsEnum.nextElement();
                String value = (String)(props.get((String)obj));
                properties.setProperty((String)obj, value);
            }
            return(properties);
        }
Exemplo n.º 17
0
        /**
         * Walks through all recorded entries and adds the data available
         * from the local file header.
         *
         * <p>Also records the offsets for the data to read from the
         * entries.</p>
         */
        private void resolveLocalFileHeaderData(java.util.Map <ZipArchiveEntry, IAC_NameAndComment> entriesWithoutUTF8Flag)
        //throws IOException
        {
            java.util.Enumeration <ZipArchiveEntry> e = getEntries();
            while (e.hasMoreElements())
            {
                ZipArchiveEntry ze          = e.nextElement();
                IAC_OffsetEntry offsetEntry = entries.get(ze);
                long            offset      = offsetEntry.headerOffset;
                archive.seek(offset + LFH_OFFSET_FOR_FILENAME_LENGTH);
                byte[] b = new byte[SHORT];
                archive.readFully(b);
                int fileNameLen = ZipShort.getValue(b);
                archive.readFully(b);
                int extraFieldLen = ZipShort.getValue(b);
                int lenToSkip     = fileNameLen;
                while (lenToSkip > 0)
                {
                    int skipped = archive.skipBytes(lenToSkip);
                    if (skipped <= 0)
                    {
                        throw new java.lang.RuntimeException("failed to skip file name in"
                                                             + " local file header");
                    }
                    lenToSkip -= skipped;
                }
                byte[] localExtraData = new byte[extraFieldLen];
                archive.readFully(localExtraData);
                ze.setExtra(localExtraData);

                /*dataOffsets.put(ze,
                 *              new Long(offset + LFH_OFFSET_FOR_FILENAME_LENGTH
                 + SHORT + SHORT + fileNameLen + extraFieldLen));
                 */
                offsetEntry.dataOffset = offset + LFH_OFFSET_FOR_FILENAME_LENGTH
                                         + SHORT + SHORT + fileNameLen + extraFieldLen;

                if (entriesWithoutUTF8Flag.containsKey(ze))
                {
                    String             orig = ze.getName();
                    IAC_NameAndComment nc   = (IAC_NameAndComment)entriesWithoutUTF8Flag.get(ze);
                    ZipUtil.setNameAndCommentFromExtraFields(ze, nc.name, nc.comment);
                    if (!orig.equals(ze.getName()))
                    {
                        nameMap.remove(orig);
                        nameMap.put(ze.getName(), ze);
                    }
                }
            }
        }
Exemplo n.º 18
0
 /*
  * Return anjava.util.Enumeration&lt;Object&gt; of all prefixes for a given URI whose
  * declarations are active in the current context.
  * This includes declarations from parent contexts that have
  * not been overridden.
  *
  * <p/>This method returns prefixes mapped to a specific Namespace
  * URI.  The xml: prefix will be included.  If you want only one
  * prefix that's mapped to the Namespace URI, and you don't care
  * which one you get, use the {@link #getPrefix getPrefix}
  *  method instead.
  *
  * <p/><strong>Note:</strong> the empty (default) prefix is <em>never</em> included
  * in thisjava.util.Enumeration&lt;Object&gt;; to check for the presence of a default
  * Namespace, use the {@link #getURI getURI} method with an
  * argument of "".
  *
  * @param uri The Namespace URI.
  * @return Anjava.util.Enumeration&lt;Object&gt; of prefixes (never empty).
  * @see #getPrefix
  * @see #getDeclaredPrefixes
  * @see #getURI
  */
 public java.util.Enumeration <Object> getPrefixes(String uri)
 {
     java.util.Vector <Object>      prefixes    = new java.util.Vector <Object>();
     java.util.Enumeration <Object> allPrefixes = getPrefixes();
     while (allPrefixes.hasMoreElements())
     {
         String prefix = (String)allPrefixes.nextElement();
         if (uri.equals(getURI(prefix)))
         {
             prefixes.addElement(prefix);
         }
     }
     return(prefixes.elements());
 }
Exemplo n.º 19
0
            /**
             * Returns next element.
             */
            public Permission nextElement()
            {
                if (current != null)
                {
                    //assert current.hasMoreElements();
                    Permission next = current.nextElement();
                    if (!current.hasMoreElements())
                    {
                        current = getNextEnumeration();
                    }

                    return(next);
                }
                throw new java.util.NoSuchElementException("no more elements"); //$NON-NLS-1$
            }
Exemplo n.º 20
0
        public string[] ListClassifications()
        {
            List <string> attrs = new List <string>();

            for (int i = 0; i < structure.numAttributes(); ++i)
            {
                if (!structure.attribute(i).isNominal())
                {
                    continue;
                }
                java.util.Enumeration en = structure.attribute(i).enumerateValues();
                while (en.hasMoreElements())
                {
                    attrs.Add(en.nextElement().ToString());
                }
            }
            return(attrs.ToArray());
        }
Exemplo n.º 21
0
        // Searches for the property with the specified key in the provider
        // properties. Key is not case-sensitive.
        //
        // @param prop
        // @return the property value with the specified key value.
        private String getPropertyIgnoreCase(String key)
        {
            String res = getProperty(key);

            if (res != null)
            {
                return(res);
            }
            for (java.util.Enumeration <Object> e = propertyNames(); e.hasMoreElements();)
            {
                String pname = (String)e.nextElement();
                if (key.equalsIgnoreCase(pname))
                {
                    return(getProperty(pname));
                }
            }
            return(null);
        }
Exemplo n.º 22
0
    public static object getByInetAddress0(object addr)
    {
#if FIRST_PASS
        return(null);
#else
        foreach (java.net.NetworkInterface iface in GetInterfaces().javaInterfaces)
        {
            java.util.Enumeration addresses = iface.getInetAddresses();
            while (addresses.hasMoreElements())
            {
                if (addresses.nextElement().Equals(addr))
                {
                    return(iface);
                }
            }
        }
        return(null);
#endif
    }
Exemplo n.º 23
0
 /**
  * Sets up the next InputStream or leaves it alone if there are none left.
  *
  * @throws IOException
  */
 private void nextStream()
 {        // throws IOException {
     if (inJ != null)
     {
         inJ.close();
     }
     if (e.hasMoreElements())
     {
         inJ = e.nextElement();
         if (inJ == null)
         {
             throw new java.lang.NullPointerException();
         }
     }
     else
     {
         inJ = null;
     }
 }
Exemplo n.º 24
0
Arquivo: vfs.cs Projeto: sreejukg/ikvm
        private static void Initialize()
        {
            VfsDirectory root = new VfsDirectory();

            root.AddDirectory("lib").AddDirectory("security").Add("cacerts", new VfsCacertsEntry());
            VfsDirectory bin = new VfsDirectory();

            root.Add("bin", bin);
            root.Add("assembly", new VfsAssembliesDirectory());
            AddDummyLibrary(bin, "zip");
            AddDummyLibrary(bin, "awt");
            AddDummyLibrary(bin, "rmi");
            AddDummyLibrary(bin, "w2k_lsa_auth");
            AddDummyLibrary(bin, "jaas_nt");
            AddDummyLibrary(bin, "jaas_unix");
            AddDummyLibrary(bin, "net");
            AddDummyLibrary(bin, "splashscreen");
            AddDummyLibrary(bin, "osx");
            AddDummyLibrary(bin, "management");
            bin.Add("java", new VfsJavaExe());
            bin.Add("javaw", new VfsJavaExe());
            bin.Add("java.exe", new VfsJavaExe());
            bin.Add("javaw.exe", new VfsJavaExe());

            // this is a weird loop back, the vfs.zip resource is loaded from vfs,
            // because that's the easiest way to construct a ZipFile from a Stream.
            //Console.Error.WriteLine($"Opening virtual Zip file: {RootPath + "vfs.zip"}");
            java.util.zip.ZipFile zf = new java.util.zip.ZipFile(RootPath + "vfs.zip");
            java.util.Enumeration e  = zf.entries();
            while (e.hasMoreElements())
            {
                AddZipEntry(zf, root, (java.util.zip.ZipEntry)e.nextElement());
            }

            // make "lib/security/local_policy.jar" point to "lib/security/US_export_policy.jar"
            // to get the unrestricted crypto policy
            VfsDirectory security = (VfsDirectory)((VfsDirectory)root.GetEntry("lib")).GetEntry("security");

            security.Add("local_policy.jar", security.GetEntry("US_export_policy.jar"));

            Interlocked.CompareExchange(ref VirtualFileSystem.root, root, null);
        }
Exemplo n.º 25
0
            public LookupProvidersIterator(java.lang.Class providerClass, java.lang.ClassLoader loader)
            {
                this.loader = loader;

                java.util.Enumeration <java.net.URL> e = null;
                try
                {
                    e = loader.getResources("META-INF/services/" + providerClass.getName()); //$NON-NLS-1$
                    while (e.hasMoreElements())
                    {
                        java.util.Set <String> names = parse((java.net.URL)e.nextElement());
                        providerNames.addAll(names);
                    }
                }
                catch (java.io.IOException e1)
                {
                    // Ignored
                }

                it = providerNames.iterator();
            }
Exemplo n.º 26
0
        public void setClientInfo(java.util.Properties props)
        {
            java.util.HashMap <String, java.sql.ClientInfoStatus> errors = new java.util.HashMap <String, java.sql.ClientInfoStatus>();
            java.util.Enumeration <String> names = props.keys();
            String name = null;

            while (names.hasMoreElements())
            {
                try
                {
                    name = names.nextElement();
                    this.setClientInfo(name, props.get(name));
                }
                catch (java.sql.SQLClientInfoException) {
                    errors.put(name, java.sql.ClientInfoStatus.REASON_UNKNOWN);
                }
            }
            if (0 != errors.size())
            {
                throw new java.sql.SQLClientInfoException(errors);
            }
        }
Exemplo n.º 27
0
    public static string[] getMetaInfEntryNames(object thisJarFile)
    {
#if FIRST_PASS
        return(null);
#else
        java.util.zip.ZipFile zf      = (java.util.zip.ZipFile)thisJarFile;
        java.util.Enumeration entries = zf.entries();
        List <string>         list    = null;
        while (entries.hasMoreElements())
        {
            java.util.zip.ZipEntry entry = (java.util.zip.ZipEntry)entries.nextElement();
            if (entry.getName().StartsWith("META-INF/", StringComparison.OrdinalIgnoreCase))
            {
                if (list == null)
                {
                    list = new List <string>();
                }
                list.Add(entry.getName());
            }
        }
        return(list == null ? null : list.ToArray());
#endif
    }
Exemplo n.º 28
0
        public KeyValueMergedCollection(HttpContext hc, NameValueCollection wrapped)
            : base(wrapped)
        {
            _wrapped = wrapped;

            ServletConfig config = (ServletConfig)AppDomain.CurrentDomain.GetData(vmw.common.IAppDomainConfig.SERVLET_CONFIG);

            if (config != null)
            {
                ServletContext context = config.getServletContext();

                for (java.util.Enumeration e = context.getInitParameterNames(); e.hasMoreElements();)
                {
                    string key = (string)e.nextElement();
                    Set(key, context.getInitParameter(key));
                }

                for (java.util.Enumeration e = config.getInitParameterNames(); e.hasMoreElements();)
                {
                    string key = (string)e.nextElement();
                    Set(key, config.getInitParameter(key));
                }
            }
        }
Exemplo n.º 29
0
        private IEnumerable <java.net.URL> GetResourcesImpl(string unmangledName, bool getFromDelegates)
        {
            if (ReflectUtil.IsDynamicAssembly(assemblyLoader.Assembly))
            {
                yield break;
            }
#if !FIRST_PASS
            java.util.Enumeration urls = assemblyLoader.FindResources(unmangledName);
            while (urls.hasMoreElements())
            {
                yield return((java.net.URL)urls.nextElement());
            }
#endif
            string name = JVM.MangleResourceName(unmangledName);
            if (assemblyLoader.Assembly.GetManifestResourceInfo(name) != null)
            {
                yield return(MakeResourceURL(assemblyLoader.Assembly, name));
            }
            LazyInitExports();
            if (exports != null)
            {
                List <int> assemblies;
                if (exports.TryGetValue(JVM.PersistableHash(unmangledName), out assemblies))
                {
                    foreach (int index in assemblies)
                    {
                        AssemblyLoader loader = exportedAssemblies[index];
                        if (loader == null)
                        {
                            Assembly asm = LoadAssemblyOrClearName(ref exportedAssemblyNames[index], true);
                            if (asm == null)
                            {
                                continue;
                            }
                            loader = exportedAssemblies[index] = GetLoaderForExportedAssembly(asm);
                        }
#if !FIRST_PASS
                        urls = loader.FindResources(unmangledName);
                        while (urls.hasMoreElements())
                        {
                            yield return((java.net.URL)urls.nextElement());
                        }
#endif
                        if (loader.Assembly.GetManifestResourceInfo(name) != null)
                        {
                            yield return(MakeResourceURL(loader.Assembly, name));
                        }
                    }
                }
            }
            if (!getFromDelegates)
            {
                yield break;
            }
            for (int i = 0; i < delegates.Length; i++)
            {
                if (delegates[i] == null)
                {
                    Assembly asm = LoadAssemblyOrClearName(ref references[i], false);
                    if (asm != null)
                    {
                        delegates[i] = AssemblyClassLoader.FromAssembly(asm);
                    }
                }
                if (delegates[i] != null)
                {
                    foreach (java.net.URL url in delegates[i].FindResources(unmangledName))
                    {
                        yield return(url);
                    }
                }
            }
            if (!assemblyLoader.HasJavaModule)
            {
                foreach (java.net.URL url in GetBootstrapClassLoader().FindResources(unmangledName))
                {
                    yield return(url);
                }
            }
        }
Exemplo n.º 30
0
        public static void Main(string[] args)
        {
            // http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication
            // http://www.berthou.com/us/2007/12/05/ms-capi-and-java-jce-sunmscapi/


            try
            {
                java.lang.System.setProperty("javax.net.debug", "all");



                #region Certificates
                Func <string, IEnumerable <X509Certificate2> > Certificates = keyStoreType =>
                {
                    var a = new List <X509Certificate2> {
                    };

                    try
                    {
                        // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/security/mscapi/SunMSCAPI.java

                        // https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html

                        // https://social.msdn.microsoft.com/Forums/expression/en-US/52dca221-1e05-44c1-8c45-9e0d4a807853/java-keystoreload-for-windowsmy-pops-up-insert-smart-card-window?forum=windowssecurity
                        // I removed some personal certificaties at key manager (certmgr.msc) and wala!

                        //Client Authentication (1.3.6.1.5.5.7.3.2)
                        //Secure Email (1.3.6.1.5.5.7.3.4)


                        // https://www.chilkatsoft.com/p/p_280.asp
                        // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider

                        // http://stackoverflow.com/questions/27692904/how-to-avoid-smart-card-selection-popup-when-accessing-windows-my-using-java

                        // http://stackoverflow.com/questions/4552100/how-to-prevent-popups-when-loading-a-keystore
                        // http://stackoverflow.com/questions/15220976/how-to-obtain-a-users-identity-from-a-smartcard-on-windows-mscapi-with-java

                        KeyStore xKeyStore = KeyStore.getInstance(keyStoreType);
                        //Console.WriteLine(new { xKeyStore });
                        //Console.WriteLine("load... " + new { keyStoreType });
                        xKeyStore.load(null, null);
                        //Console.WriteLine("load... done");
                        //Console.WriteLine("aliases...");
                        java.util.Enumeration en = xKeyStore.aliases();
                        //Console.WriteLine("aliases... done");

                        while (en.hasMoreElements())
                        {
                            var aliasKey = (string)en.nextElement();

                            //Console.WriteLine(new { aliasKey });

                            // PCSC?
                            var c509 = xKeyStore.getCertificate(aliasKey) as java.security.cert.X509Certificate;
                            if (c509 != null)
                            {
                                X509Certificate2 crt = new __X509Certificate2 {
                                    InternalElement = c509
                                };

                                //Console.WriteLine(new { crt.Subject, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false) });
                                //Console.WriteLine(new { aliasKey, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false), crt.Issuer });

                                a.Add(crt);
                            }
                            //if (aliasKey.equals("myKey") ) {
                            //      PrivateKey key = (PrivateKey)ks.getKey(aliasKey, "monPassword".toCharArray());
                            //      Certificate[] chain = ks.getCertificateChain(aliasKey);
                            //}
                        }
                    }
                    catch //(Exception closure)
                    {
                        throw;
                    }

                    return(a);
                };
                #endregion



                Action <string> f = keyStoreType =>
                {
                    // jsc should do implicit try catch for closures? while asking for explicit catch for non closures?

                    //{ ks = java.security.KeyStore@d3ade7 }
                    //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306A9, SerialNumber = 03729f49acf3e79d4cc40da08149433d, SimpleName = peer integrity authority for cpu BFEBFBFF000306A9 }
                    //{ aliasKey = peer integrity authority for cpu BFEBFBFF000306C3, SerialNumber = c4761e1ea779bc9546151afce47c7c26, SimpleName = peer integrity authority for cpu BFEBFBFF000306C3 }

                    try
                    {
                        // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/security/mscapi/SunMSCAPI.java

                        // https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html

                        // https://social.msdn.microsoft.com/Forums/expression/en-US/52dca221-1e05-44c1-8c45-9e0d4a807853/java-keystoreload-for-windowsmy-pops-up-insert-smart-card-window?forum=windowssecurity
                        // I removed some personal certificaties at key manager (certmgr.msc) and wala!

                        //Client Authentication (1.3.6.1.5.5.7.3.2)
                        //Secure Email (1.3.6.1.5.5.7.3.4)


                        // https://www.chilkatsoft.com/p/p_280.asp
                        // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider

                        // http://stackoverflow.com/questions/27692904/how-to-avoid-smart-card-selection-popup-when-accessing-windows-my-using-java

                        // http://stackoverflow.com/questions/4552100/how-to-prevent-popups-when-loading-a-keystore
                        // http://stackoverflow.com/questions/15220976/how-to-obtain-a-users-identity-from-a-smartcard-on-windows-mscapi-with-java

                        KeyStore xKeyStore = KeyStore.getInstance(keyStoreType);
                        Console.WriteLine(new { xKeyStore });
                        Console.WriteLine("load... " + new { keyStoreType });
                        xKeyStore.load(null, null);
                        //Console.WriteLine("load... done");
                        Console.WriteLine("aliases...");
                        java.util.Enumeration en = xKeyStore.aliases();
                        //Console.WriteLine("aliases... done");

                        while (en.hasMoreElements())
                        {
                            var aliasKey = (string)en.nextElement();

                            //Console.WriteLine(new { aliasKey });

                            // PCSC?
                            var c509 = xKeyStore.getCertificate(aliasKey) as java.security.cert.X509Certificate;
                            if (c509 != null)
                            {
                                X509Certificate2 crt = new __X509Certificate2 {
                                    InternalElement = c509
                                };

                                //Console.WriteLine(new { crt.Subject, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false) });
                                Console.WriteLine(new { aliasKey, crt.SerialNumber, SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false), crt.Issuer });
                            }
                            //if (aliasKey.equals("myKey") ) {
                            //      PrivateKey key = (PrivateKey)ks.getKey(aliasKey, "monPassword".toCharArray());
                            //      Certificate[] chain = ks.getCertificateChain(aliasKey);
                            //}
                        }
                    }
                    catch //(Exception closure)
                    {
                        throw;
                    }
                };

                Certificates("Windows-ROOT").WithEach(
                    crt =>
                {
                    // aliasKey = peer integrity authority for cpu BFEBFBFF000306A9

                    // SimpleName = peer integrity authority for cpu BFEBFBFF000306A9
                    var SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false);


                    //{ SerialNumber = 01 }
                    //{ SerialNumber = 4a19d2388c82591ca55d735f155ddca3 }
                    //{ SerialNumber = 35def4cf }
                    //{ SerialNumber = 00 }
                    //{ SerialNumber = 7dd9fe07cfa81eb7107967fba78934c6 }
                    //{ SerialNumber = 70bae41d10d92934b638ca7b03ccbabf }
                    //{ SerialNumber = 7dd9fe07cfa81eb7107967fba78934c6 }
                    //{ SerialNumber = 35def4cf }
                    //{ SerialNumber = 00 }
                    //{ SerialNumber = 7dd9fe07cfa81eb7107967fba78934c6 }

                    //                        if (SimpleName == null)
                    //                            Console.WriteLine(new { crt.SerialNumber });
                    //                        else
                    if (SimpleName.StartsWith("peer integrity authority for cpu"))
                    {
                        Console.WriteLine(new { SimpleName, crt.SerialNumber, crt.Issuer });
                    }
                }
                    );

                //f("Windows-MY");
                Console.WriteLine("-");

                //Caused by: java.lang.NullPointerException
                //        at TestKeyStoreWindowsROOT.Program._Main_b__4(Program.java:214)

                // https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.friendlyname(v=vs.110).aspx


                f("Windows-MY");

                //Certificates("Windows-MY").WithEach(
                //    crt =>
                //    {
                //        // aliasKey = peer integrity authority for cpu BFEBFBFF000306A9

                //        // SimpleName = peer integrity authority for cpu BFEBFBFF000306A9
                //        var SimpleName = crt.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, false);

                //        //if (SimpleName.StartsWith("peer integrity authority for cpu"))
                //        Console.WriteLine(new { SimpleName, crt.SerialNumber, crt.Issuer });
                //    }
                //);
            }
            catch (Exception err)
            {
                Console.WriteLine(new { err.Message, err.StackTrace });
            }


            CLRProgram.CLRMain();
        }
Exemplo n.º 31
0
        /*
         * Support function for restartable queries. Continue to
         * read the query result. The current state is taken from
         * tsResultSet. Proceed until maxFetchSize has reached.
         */
        protected internal virtual void contSelectStatement(TsResultSet jrs)
        //throws TinySQLException
        {
            /*
             *    The table scan here is an iterative tree expansion, similar to
             *    the algorithm shown in the outline example in Chapter 5.
             */
            String       columnName, columnString, whereStatus, tableAndAlias;
            bool         addOK;
            int          i;
            int          level = jrs.getLevel();
            TinySQLTable jtbl;
            TsColumn     updateColumn;

            java.util.Hashtable <Object, Object> tables = jrs.getTableState();
            TinySQLWhere wc = jrs.getWhereClause();

            /*
             *    Create a hashtable to enumerate the tables to be scanned and initialize
             *    with the first table name.
             */
            java.util.Hashtable <Object, Object> tbl_list = new java.util.Hashtable <Object, Object>();
            java.util.Vector <Object>            t        = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER");
            String current = (String)t.elementAt(0);

            tbl_list.put(current, new java.lang.Integer(1));

            /*
             *    Create a row object; this is added to the ResultSet.
             */
            TsRow record = new TsRow();

            java.util.Vector <Object> resultSet = new java.util.Vector <Object>();

            /*
             *    Keep retrieving rows until we run out of rows to process.
             */
            while (level > 0)
            {
                bool levelFound = false;

                /*
                 *       Find an item within the tbl_list which has the same level as the
                 *       one we're on.
                 */
                java.util.Enumeration <Object> keys = tbl_list.keys();
                while (keys.hasMoreElements())
                {
                    /*
                     *          Get the next element in the "to be processed"
                     *          Hashtable, and find out its level, storing this
                     *          value in currLevel.
                     */
                    String hashkey   = (String)keys.nextElement();
                    int    currLevel = ((java.lang.Integer)tbl_list.get(hashkey)).intValue();

                    /*
                     *          As soon as an element is found whose level is equal to the
                     *          one currently being processed, grab it's primary key (the hashkey),
                     *          flag levelfound, and break!
                     */
                    if (currLevel == level)
                    {
                        current = hashkey; levelFound = true; break;
                    }
                }
                bool haveRecord = false; // did we get a record or not?

                /*
                 *       If a table was found at the current level, then we should
                 *       try to get another row from it.
                 */
                if (levelFound)
                {
                    /*
                     *          Get the current table
                     */
                    jtbl          = (TinySQLTable)tables.get(current);
                    tableAndAlias = jtbl.table + "->" + jtbl.tableAlias;
                    if (TinySQLGlobals.WHERE_DEBUG)
                    {
                        java.lang.SystemJ.outJ.println("Processing level " + level
                                                       + " table " + tableAndAlias + "\n");
                    }

                    /*
                     *          The following code is the start of setting up simple indexes
                     *          for tinySQL.  The concept involves creating a new tinySQLCondition
                     *          class, instances of which will be created by tinySQLWhere.  At least
                     *          initially only conditions that are equal to a constant will be
                     *          considered.  One of these conditions will be stored inside the
                     *          dbfFileTable object. Calls to NextRecord would then have to add
                     *          logic to check to see if an index exists.  The presence of a
                     *          complete index would be indicated by a counter that was equal
                     *          to the number of rows in the table.  In that case a single get
                     *          would deliver the record numbers required for the where condition.
                     *          The NextRecord function would return these record numbers in
                     *          sequence.  If the index did not exist then new values in the
                     *          index Hashtable would be created.  None of this code has been
                     *          developed or implemented, let alone tested.
                     *
                     *
                     *          if ( wc != (tinySQLWhere)null )
                     *             jtbl.setIndexCondition(wc.getIndexCondition(tableAndAlias));
                     */
                    if (performDebug)
                    {
                        java.lang.SystemJ.outJ.println("Selecting records from "
                                                       + jtbl.table);
                    }

                    /*
                     *          Skip to the next undeleted record; at some point,
                     *          this will run out of records, and found will be false.
                     */
                    bool found = false;
                    while (jtbl.NextRecord())
                    {
                        /*
                         *             Clear the column values for this table before starting
                         *             to process the next row.
                         */
                        for (i = 0; i < jrs.numcols(); i++)
                        {
                            updateColumn = jrs.columnAtIndex(i, true);
                            updateColumn.clear(tableAndAlias);
                        }
                        if (wc != (TinySQLWhere)null)
                        {
                            wc.clearValues(tableAndAlias);
                        }
                        if (!jtbl.isDeleted())
                        {
                            /*
                             *                Evaluate the where clause for each column in the table.  If
                             *                it is false, skip to the next row.  Otherwise, add the
                             *                column value to the output record.
                             */
                            java.util.Enumeration <Object> cols = jtbl.column_info.keys();
                            found       = true;
                            whereStatus = "TRUE";
                            while (cols.hasMoreElements())
                            {
                                columnName = tableAndAlias + "."
                                             + (String)cols.nextElement();
                                columnString = jtbl.GetCol(columnName);
                                if (wc != (TinySQLWhere)null)
                                {
                                    whereStatus = wc.evaluate(columnName, columnString);
                                    if (whereStatus.equals("FALSE"))
                                    {
                                        /*
                                         *                         This column value caused the where clause to
                                         *                         be FALSE.  Go to the next row in the table.
                                         */
                                        found = false;
                                        break;
                                    }
                                }

                                /*
                                 *                   Update the ResultSet tsColumn values
                                 */
                                jrs.updateColumns(columnName, columnString);
                            }

                            /*
                             *                If no where condition has evaluated to false then this
                             *                record is a candidate for output.  Break to the next table
                             *                in this case for further WHERE processing.
                             */
                            if (found)
                            {
                                break;
                            }
                        }
                    }
                    if (found)
                    {
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Build candidate record.");
                        }
                        for (i = 0; i < jrs.numcols(); i++)
                        {
                            updateColumn = jrs.columnAtIndex(i, true);

                            /*
                             *                Evaluate all functions before adding the
                             *                column to the output record.
                             */
                            updateColumn.updateFunctions();
                            columnString = updateColumn.getString();
                            if (updateColumn.isNotNull())
                            {
                                record.put(updateColumn.name, columnString);
                            }
                            else
                            {
                                record.remove(updateColumn.name);
                            }
                        }
                        if (performDebug)
                        {
                            java.lang.SystemJ.outJ.println("Record is " + record.toString());
                        }

                        /*
                         *             If the table we are processing is not the last in
                         *             the list, then we should increment level and loop to the top.
                         */
                        if (level < t.size())
                        {
                            /*
                             *                Increment level
                             */
                            level++;

                            /*
                             *                Add the next table in the list of tables to
                             *                the tbl_list, the Hashtable of "to be processed" tables.
                             */
                            String next_tbl = (String)t.elementAt(level - 1);
                            tbl_list.put(next_tbl, new java.lang.Integer(level));
                        }
                        else
                        {
                            /*
                             *                If the table that was just processed is the last in
                             *                the list, then we have drilled down to the bottom;
                             *                all columns have values, and we can add it to the
                             *                result set. The next time through, the program
                             *                will try to read another row at this level; if it's
                             *                found, only columns for the table being read will
                             *                be overwritten in the tsRow.
                             *
                             *                Columns for the other table will be left alone, and
                             *                another row will be added to the result set. Here
                             *                is the essence of the Cartesian Product which is
                             *                being built here.
                             */
                            haveRecord = true;
                        }
                    }
                    else
                    {
                        /*
                         *             We didn't find any more records at this level.
                         *             Reset the record pointer to the top of the table,
                         *             and decrement level. We have hit end of file here.
                         */
                        if (wc != (TinySQLWhere)null)
                        {
                            wc.clearValues(tableAndAlias);
                        }
                        level--;
                        jtbl.GoTop();
                    }
                }
                else
                {
                    /*
                     *          No tables were found at this level; back up a level
                     *          and see if there's any up there.
                     */
                    level--;
                }

                /*
                 *       If we got a record, then add it to the result set.
                 */
                if (haveRecord)
                {
                    /*
                     *          If group functions are involved, add records only after a break,
                     *          which is defined as a change in all of the group columns.
                     *          Otherwise, update the current record.
                     */
                    if (jrs.isGrouped())
                    {
                        if (groupBreak)
                        {
                            addOK = jrs.addRow((TsRow)record.clone());
                            if (addOK == false)
                            {
                                jrs.setLevel(level);
                                return;
                            }
                            groupBreak = false;
                        }
                        else
                        {
                            jrs.updateRow((TsRow)record.clone());
                        }
                    }
                    else
                    {
                        /*
                         *             No group functions are involved.  Just add the record.
                         */
                        addOK = jrs.addRow((TsRow)record.clone());
                        if (addOK == false)
                        {
                            jrs.setLevel(level);
                            return;
                        }
                    }
                }
            }

            /*
             *    Close all the tables
             */
            for (i = 0; i < t.size(); i++)
            {
                jtbl = (TinySQLTable)tables.get((String)t.elementAt(i));
                jtbl.close();
            }

            /*
             *    return a result set
             */
            jrs.setLevel(0);
        }