KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sf.acegisecurity.GrantedAuthority;
20 import net.sf.acegisecurity.providers.*;
21
22 /**
23  * <p>Used to provide authentication with a remote Windows server when the username and password are
24  * provided locally.
25  *
26  * @author GKSpencer
27  */

28 public class NTLMLocalToken extends UsernamePasswordAuthenticationToken
29 {
30     private static final long serialVersionUID = -7946514578455279387L;
31
32     /**
33      * Class constructor
34      */

35     protected NTLMLocalToken()
36     {
37         super(null, null);
38     }
39     
40     /**
41      * Class constructor
42      *
43      * @param username String
44      * @param plainPwd String
45      */

46     public NTLMLocalToken(String JavaDoc username, String JavaDoc plainPwd) {
47         super(username.toLowerCase(), plainPwd);
48     }
49     
50     /**
51      * Check if the user logged on as a guest
52      *
53      * @return boolean
54      */

55     public final boolean isGuestLogon()
56     {
57         return hasAuthority(NTLMAuthenticationProvider.NTLMAuthorityGuest);
58     }
59
60     /**
61      * Check if the user is an administrator
62      *
63      * @return boolean
64      */

65     public final boolean isAdministrator()
66     {
67         return hasAuthority(NTLMAuthenticationProvider.NTLMAuthorityAdministrator);
68     }
69     
70     /**
71      * Search for the specified authority
72      *
73      * @param authority String
74      * @return boolean
75      */

76     public final boolean hasAuthority(String JavaDoc authority)
77     {
78         boolean found = false;
79         GrantedAuthority[] authorities = getAuthorities();
80         
81         if ( authorities != null && authorities.length > 0)
82         {
83             // Search for the specified authority
84

85             int i = 0;
86             
87             while ( found == false && i < authorities.length)
88             {
89                 if ( authorities[i++].getAuthority().equals(authority))
90                     found = true;
91             }
92         }
93
94         // Return the status
95

96         return found;
97     }
98 }
99
Popular Tags