KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > authentication > ntlm > NTLMChallenge


1 /*
2  * Copyright (C) 2006 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.security.authentication.ntlm;
18
19 import org.alfresco.filesys.util.HexDump;
20
21 /**
22  * Contains the NTLM challenge bytes.
23  *
24  * @author GKSpencer
25  */

26 public class NTLMChallenge
27 {
28     // Challenge bytes
29

30     private byte[] m_challenge;
31     
32     /**
33      * Class constructor
34      *
35      * @param chbyts byte[]
36      */

37     protected NTLMChallenge(byte[] chbyts)
38     {
39         m_challenge = chbyts;
40     }
41     
42     /**
43      * Return the challenge bytes
44      *
45      * @return byte[]
46      */

47     public final byte[] getBytes()
48     {
49         return m_challenge;
50     }
51     
52     /**
53      * Check for object equality
54      *
55      * @param obj Object
56      * @return boolean
57      */

58     public boolean equals(Object JavaDoc obj)
59     {
60         if ( obj instanceof NTLMChallenge)
61         {
62             NTLMChallenge ntlmCh = (NTLMChallenge) obj;
63             
64             // Check if both challenges are null
65

66             if ( getBytes() == null && ntlmCh.getBytes() == null)
67                 return true;
68             
69             // Check if both challenges are the same length
70

71             if ( getBytes() != null && ntlmCh.getBytes() != null &&
72                     getBytes().length == ntlmCh.getBytes().length)
73             {
74                 // Check if challenages are the same value
75

76                 byte[] ntlmBytes = ntlmCh.getBytes();
77                 
78                 for ( int i = 0; i < m_challenge.length; i++)
79                     if ( m_challenge[i] != ntlmBytes[i])
80                         return false;
81             }
82             else
83                 return false;
84         }
85         
86         // Not the same type
87

88         return false;
89     }
90     
91     /**
92      * Return the challenge as a string
93      *
94      * @return String
95      */

96     public String JavaDoc toString()
97     {
98         StringBuilder JavaDoc str = new StringBuilder JavaDoc();
99         
100         str.append("[");
101         str.append(HexDump.hexString(getBytes(), " "));
102         str.append("]");
103         
104         return str.toString();
105     }
106 }
107
Popular Tags