OSDN Git Service

* java/security/AlgorithmParameterGeneratorSpi.java: New file.
[pf3gnuchains/gcc-fork.git] / libjava / java / security / Security.java
1 /* Copyright (C) 2000  Free Software Foundation
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8
9 package java.security;
10
11 import java.util.Enumeration;
12 import java.util.Properties;
13 import java.util.Vector;
14
15 /**
16  * @author Tom Tromey <tromey@cygnus.com>
17  * @date February 8, 2000.
18  */
19
20 /**
21  * Written using on-line Java Platform 1.2 API Specification.
22  * Status:  Still missing the deprecated getAlgorithmProperty method.
23  */
24
25 public final class Security
26 {
27   public static int insertProviderAt (Provider provider, int position)
28   {
29     SecurityManager sm = System.getSecurityManager ();
30     if (sm != null)
31       {
32         // FIXME: need SecurityPermission.
33         // sm.checkSecurityAccess ("insertProvider." + provider.getName ());
34       }
35     if (providers.indexOf (provider) != -1)
36       return -1;
37     if (position > providers.size ())
38       position = providers.size ();
39     providers.insertElementAt (provider, position);
40     return providers.indexOf (provider);
41   }
42
43   public static int addProvider (Provider provider)
44   {
45     return insertProviderAt (provider, providers.size ());
46   }
47
48   public static void removeProvider (String name)
49   {
50     SecurityManager sm = System.getSecurityManager ();
51     if (sm != null)
52       {
53         // FIXME: need SecurityPermission.
54         // sm.checkSecurityAccess ("removeProvider." + name);
55       }
56     Provider p = getProvider (name);
57     if (p != null)
58       providers.removeElement (p);
59   }
60
61   public static Provider[] getProviders ()
62   {
63     Provider[] r = new Provider[providers.size ()];
64     providers.copyInto (r);
65     return r;
66   }
67
68   public static Provider getProvider (String name)
69   {
70     Enumeration e = providers.elements ();
71     while (e.hasMoreElements ())
72       {
73         Provider p = (Provider) e.nextElement ();
74         if (name.equals (p.getName ()))
75           return p;
76       }
77     return null;
78   }
79
80   public static String getProperty (String key)
81   {
82     SecurityManager sm = System.getSecurityManager ();
83     if (sm != null)
84       {
85         // FIXME: need SecurityPermission.
86         // sm.checkSecurityAccess ("getProperty." + key);
87       }
88     return props.getProperty (key);
89   }
90
91   public static void setProperty (String key, String value)
92   {
93     SecurityManager sm = System.getSecurityManager ();
94     if (sm != null)
95       {
96         // FIXME: need SecurityPermission.
97         // sm.checkSecurityAccess ("setProperty." + key);
98       }
99     props.setProperty (key, value);
100   }
101
102   // The providers we list.
103   private static Vector providers = new Vector ();
104
105   // Security propertiesl
106   private static Properties props = new Properties ();
107 }