KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > security > level2 > SecAttributeManager


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2002 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.security.level2;
22
23 /**
24  * SecAttributeManager.java
25  *
26  *
27  * Created: Mon Sep 4 16:32:39 2000
28  *
29  * @author Nicolas Noffke
30  * @version $Id: SecAttributeManager.java,v 1.11 2003/12/19 12:24:13 nick.cross Exp $
31  */

32
33 import java.util.*;
34
35 import org.omg.Security.*;
36
37 public class SecAttributeManager
38 {
39     private Hashtable attributes = null;
40     private int id = Integer.MIN_VALUE + 1;
41
42     private static SecAttributeManager instance = null;
43
44     public SecAttributeManager()
45     {
46         attributes = new Hashtable();
47     }
48
49     public static SecAttributeManager getInstance()
50     {
51         if( instance == null )
52         {
53             instance = new SecAttributeManager();
54         }
55
56         return instance;
57     }
58
59     public KeyAndCert getAttributeCertValue( SecAttribute attribute )
60     {
61         return (KeyAndCert) getAttributeValue( attribute );
62     }
63
64     public synchronized SecAttribute createAttribute(
65         Object JavaDoc attrib_value,
66         AttributeType attribute_type )
67     {
68         //value is id in byte array
69
byte[] value = new byte[]{ (byte) (( id >> 24 ) & 0xff),
70                                    (byte) (( id >> 16 ) & 0xff),
71                                    (byte) (( id >> 8 ) & 0xff),
72                                    (byte) ( id & 0xff) };
73
74         attributes.put( new Integer JavaDoc( id++ ), attrib_value );
75
76         return new SecAttribute( attribute_type,
77                                  new byte[0], //no defining auth
78
value );
79     }
80
81     public Object JavaDoc getAttributeValue( SecAttribute attribute )
82     {
83         if( attribute.value.length != 4 )
84         {
85             throw new RuntimeException JavaDoc( "Value of SecAttribute unknown!" );
86         }
87
88         int the_id =
89             ((attribute.value[0] & 0xff) << 24 ) +
90             ((attribute.value[1] & 0xff) << 16 ) +
91             ((attribute.value[2] & 0xff) << 8 ) +
92             (attribute.value[3] & 0xff);
93
94         return attributes.get( new Integer JavaDoc( the_id ));
95     }
96
97     public void removeAttribute( SecAttribute attribute )
98     {
99         if( attribute.value.length != 4 )
100         {
101             throw new RuntimeException JavaDoc( "Value of SecAttribute unknown!" );
102         }
103
104         int the_id =
105             ((attribute.value[0] & 0xff) << 24 ) +
106             ((attribute.value[1] & 0xff) << 16 ) +
107             ((attribute.value[2] & 0xff) << 8 ) +
108             (attribute.value[3] & 0xff);
109
110         attributes.remove( new Integer JavaDoc( the_id ));
111     }
112 } // SecAttributeManager
113
Popular Tags