KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > rmi > iiop > ObjectKey


1 /**
2  *
3  * Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.interop.rmi.iiop;
19
20 import org.apache.geronimo.interop.security.*;
21 import org.apache.geronimo.interop.util.*;
22 import java.util.*;
23
24 public class ObjectKey
25 {
26     public static final int TYPE_MANAGER = 'M';
27
28     public static final int TYPE_SESSION = 'S';
29
30     public int type;
31     public String JavaDoc username = "";
32     public String JavaDoc password = "";
33     public String JavaDoc component = "";
34     public String JavaDoc sessionID = "";
35
36     public byte[] encode()
37     {
38         int un = username.length();
39         int pn = password.length();
40         int cn = component.length();
41         int sn = sessionID.length();
42         StringBuffer JavaDoc keyBuffer = new StringBuffer JavaDoc(12 + un + pn + cn + sn);
43         keyBuffer.append("U=");
44         keyBuffer.append(username);
45         keyBuffer.append("\tP=");
46         keyBuffer.append(password);
47         keyBuffer.append("\tC=");
48         keyBuffer.append(component);
49         if (sn > 0)
50         {
51             keyBuffer.append("\tS=");
52             keyBuffer.append(sessionID);
53         }
54         byte[] bytes = SecurityInfo.encode(keyBuffer.toString());
55         bytes[0] = (byte)type;
56         return bytes;
57     }
58
59     public void decode(byte[] bytes)
60     {
61         type = bytes.length == 0 ? 0 : bytes[0];
62         String JavaDoc key = SecurityInfo.decode(bytes);
63         List items = ListUtil.getListWithSeparator(key, "\t");
64         for (Iterator i = items.iterator(); i.hasNext();)
65         {
66             String JavaDoc item = (String JavaDoc)i.next();
67             if (item.startsWith("U="))
68             {
69                 username = item.substring(2);
70             }
71             else if (item.startsWith("P="))
72             {
73                 password = item.substring(2);
74             }
75             else if (item.startsWith("C="))
76             {
77                 component = item.substring(2);
78             }
79             else if (item.startsWith("S="))
80             {
81                 sessionID = item.substring(2);
82             }
83         }
84     }
85
86     public void checkPassword()
87     {
88         User.getInstance(username).login(password);
89     }
90 }
91
Popular Tags