Exemple #1
0
        /**
         * Removes the {@code Provider} with the specified name form the collection
         * of providers. If the the {@code Provider} with the specified name is
         * removed, all provider at a greater position are shifted down one
         * position.
         * <p/>
         * Returns silently if {@code name} is {@code null} or no provider with the
         * specified name is installed.
         * <p/>
         * If a {@code SecurityManager} is installed, code calling this method needs
         * the {@code SecurityPermission} {@code removeProvider.NAME} (where NAME is
         * the provider name) to be granted, otherwise a {@code SecurityException}
         * will be thrown.
         *
         * @param name
         *            the name of the provider to remove.
         * @throws SecurityException
         *             if a {@code SecurityManager} is installed and the caller does
         *             not have permission to invoke this method.
         */
        public static void removeProvider(String name)
        {
            lock (lockJ)
            {
                // It is not clear from spec.:
                // 1. if name is null, should we checkSecurityAccess or not?
                //    throw SecurityException or not?
                // 2. as 1 but provider is not installed
                // 3. behavior if name is empty string?

                Provider p;
                if ((name == null) || (name.length() == 0))
                {
                    return;
                }
                p = getProvider(name);
                if (p == null)
                {
                    return;
                }
                java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager();
                if (sm != null)
                {
                    sm.checkSecurityAccess("removeProvider." + name); //$NON-NLS-1$
                }
                Services.removeProvider(p.getProviderNumber());
                renumProviders();
                p.setProviderNumber(-1);
            }
        }
Exemple #2
0
 /**
  * Sets the value of the specified security property.
  * <p/>
  * If a {@code SecurityManager} is installed, code calling this method needs
  * the {@code SecurityPermission} {@code setProperty.KEY} (where KEY is the
  * specified {@code key}) to be granted, otherwise a {@code
  * SecurityException} will be thrown.
  *
  * @param key
  *            the name of the security property.
  * @param datnum
  *            the value of the security property.
  * @throws SecurityException
  *             if a {@code SecurityManager} is installed and the caller does
  *             not have permission to invoke this method.
  */
 public static void setProperty(String key, String datnum)
 {
     java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager();
     if (sm != null)
     {
         sm.checkSecurityAccess("setProperty." + key); //$NON-NLS-1$
     }
     secprops.put(key, datnum);
 }
Exemple #3
0
        /**
         * Returns the value of the security property named by the argument.
         * <p/>
         * If a {@code SecurityManager} is installed, code calling this method needs
         * the {@code SecurityPermission} {@code getProperty.KEY} (where KEY is the
         * specified {@code key}) to be granted, otherwise a {@code
         * SecurityException} will be thrown.
         *
         * @param key
         *            the name of the requested security property.
         * @return the value of the security property.
         * @throws SecurityException
         *             if a {@code SecurityManager} is installed and the caller does
         *             not have permission to invoke this method.
         */
        public static String getProperty(String key)
        {
            if (key == null)
            {
                throw new java.lang.NullPointerException("The key is null"); //$NON-NLS-1$
            }
            java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager();
            if (sm != null)
            {
                sm.checkSecurityAccess("getProperty." + key); //$NON-NLS-1$
            }
            String property = secprops.getProperty(key);

            if (property != null)
            {
                property = property.trim();
            }
            return(property);
        }
Exemple #4
0
 /**
  * Insert the given {@code Provider} at the specified {@code position}. The
  * positions define the preference order in which providers are searched for
  * requested algorithms.
  * <p/>
  * If a {@code SecurityManager} is installed, code calling this method needs
  * the {@code SecurityPermission} {@code insertProvider.NAME} (where NAME is
  * the provider name) to be granted, otherwise a {@code SecurityException}
  * will be thrown.
  *
  * @param provider
  *            the provider to insert.
  * @param position
  *            the position (starting from 1).
  * @return the actual position or {@code -1} if the given {@code provider}
  *         was already in the list. The actual position may be different
  *         from the desired position.
  * @throws SecurityException
  *             if a {@code SecurityManager} is installed and the caller does
  *             not have permission to invoke this method.
  */
 public static int insertProviderAt(Provider provider,
                                    int position)
 {
     lock (lockJ)
     {
         // check security access; check that provider is not already
         // installed, else return -1; if (position <1) or (position > max
         // position) position = max position + 1; insert provider, shift up
         // one position for next providers; Note: The position is 1-based
         java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager();
         if (sm != null)
         {
             sm.checkSecurityAccess("insertProvider." + provider.getName()); //$NON-NLS-1$
         }
         if (getProvider(provider.getName()) != null)
         {
             return(-1);
         }
         int result = Services.insertProviderAt(provider, position);
         renumProviders();
         return(result);
     }
 }