KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 /**
21  * This implementation of an AuthenticationComponent can be configured to accept or reject all attempts to login.
22  *
23  * This only affects attempts to login using a user name and password.
24  * Authentication filters etc. could still support authentication but not via user names and passwords.
25  * For example, where they set the current user using the authentication component.
26  * Then the current user is set in the security context and asserted to be authenticated.
27  *
28  * By default, the implementation rejects all authentication attempts.
29  *
30  * @author Andy Hind
31  */

32 public class SimpleAcceptOrRejectAllAuthenticationComponentImpl extends AbstractAuthenticationComponent
33 {
34     private boolean accept = false;
35
36     public SimpleAcceptOrRejectAllAuthenticationComponentImpl()
37     {
38         super();
39     }
40
41     public void setAccept(boolean accept)
42     {
43         this.accept = accept;
44     }
45     
46     public void authenticate(String JavaDoc userName, char[] password) throws AuthenticationException
47     {
48         if(accept)
49         {
50             setCurrentUser(userName);
51         }
52         else
53         {
54             throw new AuthenticationException("Access Denied");
55         }
56
57     }
58
59     @Override JavaDoc
60     protected boolean implementationAllowsGuestLogin()
61     {
62        return accept;
63     }
64     
65     
66 }
67
Popular Tags