KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > authentication > AuthenticationComponentImpl


1 /*
2  * Copyright (C) 2005 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;
18
19 import net.sf.acegisecurity.AuthenticationManager;
20 import net.sf.acegisecurity.UserDetails;
21 import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken;
22
23 public class AuthenticationComponentImpl extends AbstractAuthenticationComponent
24 {
25     private MutableAuthenticationDao authenticationDao;
26
27     AuthenticationManager authenticationManager;
28
29     public AuthenticationComponentImpl()
30     {
31         super();
32     }
33
34     /**
35      * IOC
36      *
37      * @param authenticationManager
38      */

39     public void setAuthenticationManager(AuthenticationManager authenticationManager)
40     {
41         this.authenticationManager = authenticationManager;
42     }
43
44     /**
45      * IOC
46      *
47      * @param authenticationDao
48      */

49     public void setAuthenticationDao(MutableAuthenticationDao authenticationDao)
50     {
51         this.authenticationDao = authenticationDao;
52     }
53     
54     /**
55      * Authenticate
56      */

57     public void authenticate(String JavaDoc userName, char[] password) throws AuthenticationException
58     {
59         try
60         {
61             UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userName,
62                     new String JavaDoc(password));
63             authenticationManager.authenticate(authentication);
64             setCurrentUser(userName);
65
66         }
67         catch (net.sf.acegisecurity.AuthenticationException ae)
68         {
69             throw new AuthenticationException(ae.getMessage(), ae);
70         }
71     }
72
73  
74     /**
75      * We actually have an acegi object so override the default method.
76      */

77     protected UserDetails getUserDetails(String JavaDoc userName)
78     {
79         return (UserDetails) authenticationDao.loadUserByUsername(userName);
80     }
81
82     
83     /**
84      * Get the password hash from the DAO
85      */

86     public String JavaDoc getMD4HashedPassword(String JavaDoc userName)
87     {
88         return authenticationDao.getMD4HashedPassword(userName);
89     }
90
91     
92     /**
93      * This implementation supported MD4 password hashes.
94      */

95     public NTLMMode getNTLMMode()
96     {
97         return NTLMMode.MD4_PROVIDER;
98     }
99
100     @Override JavaDoc
101     protected boolean implementationAllowsGuestLogin()
102     {
103         return true;
104     }
105    
106     
107 }
108
Popular Tags