View Javadoc

1   /*
2    * Copyright 2000-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.jetspeed.services;
18  
19  // Turbine
20  import org.apache.turbine.services.TurbineServices;
21  
22  // Jetspeed
23  import org.apache.jetspeed.om.security.JetspeedUser;
24  import org.apache.jetspeed.services.security.PortalAuthentication;
25  import org.apache.jetspeed.services.security.LoginException;
26  
27  
28  /***
29   * Static accessor for the JetspeedAuthentication service
30   *
31   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
32   * @version $Id: JetspeedAuthentication.java,v 1.4 2004/02/23 04:00:57 jford Exp $
33   */
34  public abstract class JetspeedAuthentication
35  {
36      /***
37       * Given a public credential(username) and private credential(password), 
38       * perform authentication. If authentication succeeds, a <code>JetspeedUser</code> 
39       * is returned representing the authenticated subject.
40       *
41       * @param username a public credential of the subject to be authenticated.
42       * @param password a private credentialof the subject to be authenticated.
43       * @return a <code>JetspeedUser</code> object representing the authenticated subject.
44       * @exception LoginException when general security provider failure.
45       * @exception FailedLoginException when the authentication failed.
46       * @exception AccountExpiredException when the subject's account is expired.
47       * @exception CredentialExpiredException when the subject's credential is expired.
48       */
49      public static JetspeedUser login(String username, String password)
50          throws LoginException
51      {
52          return getService().login(username, password);
53      }
54  
55      /***
56       * Automatically authenticates and retrieves the portal anonymous user.
57       *
58       * @return a <code>JetspeedUser</code> object representing the authenticated subject.
59       * @exception LoginException if the authentication fails.
60       */
61      public static JetspeedUser getAnonymousUser()
62          throws LoginException
63      {
64          return getService().getAnonymousUser();
65      }
66  
67      /***
68       * Logout the <code>JetspeedUser</code>.
69       *
70       * The logout procedure my may include removing/destroying
71       * <code>Principal</code> and <code>Credential</code> information
72       * if relevant to the security provider.
73       *
74       * @exception LoginException if the logout fails.
75       */
76      public static void logout()
77          throws LoginException
78      {
79          getService().logout();
80      }
81          
82      /*
83       * Utility method for accessing the service
84       * implementation
85       *
86       * @return a UniqueIdService implementation instance
87       */
88      protected static PortalAuthentication getService()
89      {
90          return (PortalAuthentication)TurbineServices
91          .getInstance().getService(PortalAuthentication.SERVICE_NAME);
92      }
93      
94      
95  }
96  
97