KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > webservice > authentication > AuthenticationWebService


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.webservice.authentication;
18
19 import java.rmi.RemoteException JavaDoc;
20
21 import org.alfresco.repo.security.authentication.AuthenticationException;
22 import org.alfresco.service.cmr.security.AuthenticationService;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27  * Web service implementation of the AuthenticationService. The WSDL for this
28  * service can be accessed from
29  * http://localhost:8080/alfresco/wsdl/authentication-service.wsdl
30  *
31  * @author gavinc
32  */

33 public class AuthenticationWebService implements AuthenticationServiceSoapPort
34 {
35     private static Log logger = LogFactory.getLog(AuthenticationWebService.class);
36
37     private AuthenticationService authenticationService;
38
39     /**
40      * Sets the AuthenticationService instance to use
41      *
42      * @param authenticationSvc
43      * The AuthenticationService
44      */

45     public void setAuthenticationService(AuthenticationService authenticationSvc)
46     {
47         this.authenticationService = authenticationSvc;
48     }
49
50     /**
51      * @see org.alfresco.repo.webservice.authentication.AuthenticationServiceSoapPort#startSession(java.lang.String,
52      * java.lang.String)
53      */

54     public AuthenticationResult startSession(String JavaDoc username, String JavaDoc password)
55             throws RemoteException JavaDoc, AuthenticationFault
56     {
57         try
58         {
59             this.authenticationService.authenticate(username, password.toCharArray());
60             String JavaDoc ticket = this.authenticationService.getCurrentTicket();
61
62             if (logger.isDebugEnabled())
63             {
64                 logger.debug("Issued ticket '" + ticket + "' for '" + username + "'");
65             }
66
67             return new AuthenticationResult(username, ticket);
68         }
69         catch (AuthenticationException ae)
70         {
71             throw new AuthenticationFault(100, ae.getMessage());
72         }
73         catch (Throwable JavaDoc e)
74         {
75             throw new AuthenticationFault(0, e.getMessage());
76         }
77     }
78
79     /**
80      * @see org.alfresco.repo.webservice.authentication.AuthenticationServiceSoapPort#endSession()
81      */

82     public void endSession(String JavaDoc ticket) throws RemoteException JavaDoc, AuthenticationFault
83     {
84         try
85         {
86             if (ticket != null)
87             {
88                 this.authenticationService.validate(ticket);
89                 this.authenticationService.invalidateTicket(ticket);
90                 this.authenticationService.clearCurrentSecurityContext();
91     
92                 if (logger.isDebugEnabled())
93                 {
94                     logger.debug("Session ended for ticket '" + ticket + "'");
95                 }
96             }
97         }
98         catch (Throwable JavaDoc e)
99         {
100             throw new AuthenticationFault(0, e.getMessage());
101         }
102     }
103 }
104
Popular Tags