KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.alfresco.service.cmr.security.AuthenticationService;
20
21 public class AuthenticationServiceImpl implements AuthenticationService
22 {
23     MutableAuthenticationDao authenticationDao;
24
25     AuthenticationComponent authenticationComponent;
26     
27     TicketComponent ticketComponent;
28     
29     public AuthenticationServiceImpl()
30     {
31         super();
32     }
33
34     public void setAuthenticationDao(MutableAuthenticationDao authenticationDao)
35     {
36         this.authenticationDao = authenticationDao;
37     }
38
39     public void setTicketComponent(TicketComponent ticketComponent)
40     {
41         this.ticketComponent = ticketComponent;
42     }
43
44     public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
45     {
46         this.authenticationComponent = authenticationComponent;
47     }
48
49     public void createAuthentication(String JavaDoc userName, char[] password) throws AuthenticationException
50     {
51         authenticationDao.createUser(userName, password);
52     }
53
54     public void updateAuthentication(String JavaDoc userName, char[] oldPassword, char[] newPassword)
55             throws AuthenticationException
56     {
57         authenticationDao.updateUser(userName, newPassword);
58     }
59
60     public void setAuthentication(String JavaDoc userName, char[] newPassword) throws AuthenticationException
61     {
62         authenticationDao.updateUser(userName, newPassword);
63     }
64
65     public void deleteAuthentication(String JavaDoc userName) throws AuthenticationException
66     {
67         authenticationDao.deleteUser(userName);
68     }
69
70     public boolean getAuthenticationEnabled(String JavaDoc userName) throws AuthenticationException
71     {
72         return authenticationDao.getEnabled(userName);
73     }
74
75     public void setAuthenticationEnabled(String JavaDoc userName, boolean enabled) throws AuthenticationException
76     {
77         authenticationDao.setEnabled(userName, enabled);
78     }
79
80     public void authenticate(String JavaDoc userName, char[] password) throws AuthenticationException
81     {
82         try
83         {
84            authenticationComponent.authenticate(userName, password);
85         }
86         catch(AuthenticationException ae)
87         {
88             clearCurrentSecurityContext();
89             throw ae;
90         }
91     }
92
93     public String JavaDoc getCurrentUserName() throws AuthenticationException
94     {
95         return authenticationComponent.getCurrentUserName();
96     }
97
98     public void invalidateUserSession(String JavaDoc userName) throws AuthenticationException
99     {
100         ticketComponent.invalidateTicketByUser(userName);
101     }
102
103     public void invalidateTicket(String JavaDoc ticket) throws AuthenticationException
104     {
105         ticketComponent.invalidateTicketById(ticket);
106     }
107
108     public void validate(String JavaDoc ticket) throws AuthenticationException
109     {
110         try
111         {
112            authenticationComponent.setCurrentUser(ticketComponent.validateTicket(ticket));
113         }
114            catch(AuthenticationException ae)
115            {
116                clearCurrentSecurityContext();
117                throw ae;
118            }
119     }
120
121     public String JavaDoc getCurrentTicket()
122     {
123         return ticketComponent.getTicket(getCurrentUserName());
124     }
125
126     public void clearCurrentSecurityContext()
127     {
128         authenticationComponent.clearCurrentSecurityContext();
129     }
130
131     public boolean isCurrentUserTheSystemUser()
132     {
133         String JavaDoc userName = getCurrentUserName();
134         if ((userName != null) && userName.equals(authenticationComponent.getSystemUserName()))
135         {
136             return true;
137         }
138         return false;
139     }
140
141     public void authenticateAsGuest() throws AuthenticationException
142     {
143         authenticationComponent.setGuestUserAsCurrentUser();
144     }
145
146     
147 }
148
Popular Tags