aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/security/Security.java
blob: 87a0088281baebe8be0c2c185c08b43bb5cca311 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright (C) 2000  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

package java.security;

import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;

/**
 * @author Tom Tromey <tromey@cygnus.com>
 * @date February 8, 2000.
 */

/**
 * Written using on-line Java Platform 1.2 API Specification.
 * Status:  Still missing the deprecated getAlgorithmProperty method.
 */

public final class Security
{
  public static int insertProviderAt (Provider provider, int position)
  {
    SecurityManager sm = System.getSecurityManager ();
    if (sm != null)
      {
	// FIXME: need SecurityPermission.
	// sm.checkSecurityAccess ("insertProvider." + provider.getName ());
      }
    if (providers.indexOf (provider) != -1)
      return -1;
    if (position > providers.size ())
      position = providers.size ();
    providers.insertElementAt (provider, position);
    return providers.indexOf (provider);
  }

  public static int addProvider (Provider provider)
  {
    return insertProviderAt (provider, providers.size ());
  }

  public static void removeProvider (String name)
  {
    SecurityManager sm = System.getSecurityManager ();
    if (sm != null)
      {
	// FIXME: need SecurityPermission.
	// sm.checkSecurityAccess ("removeProvider." + name);
      }
    Provider p = getProvider (name);
    if (p != null)
      providers.removeElement (p);
  }

  public static Provider[] getProviders ()
  {
    Provider[] r = new Provider[providers.size ()];
    providers.copyInto (r);
    return r;
  }

  public static Provider getProvider (String name)
  {
    Enumeration e = providers.elements ();
    while (e.hasMoreElements ())
      {
	Provider p = (Provider) e.nextElement ();
	if (name.equals (p.getName ()))
	  return p;
      }
    return null;
  }

  public static String getProperty (String key)
  {
    SecurityManager sm = System.getSecurityManager ();
    if (sm != null)
      {
	// FIXME: need SecurityPermission.
	// sm.checkSecurityAccess ("getProperty." + key);
      }
    return props.getProperty (key);
  }

  public static void setProperty (String key, String value)
  {
    SecurityManager sm = System.getSecurityManager ();
    if (sm != null)
      {
	// FIXME: need SecurityPermission.
	// sm.checkSecurityAccess ("setProperty." + key);
      }
    props.setProperty (key, value);
  }

  // The providers we list.
  private static Vector providers = new Vector ();

  // Security propertiesl
  private static Properties props = new Properties ();
}