View Javadoc

1   package org.apache.maven.archiva.webdav;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
23  import org.codehaus.plexus.redback.authentication.AuthenticationException;
24  import org.codehaus.plexus.redback.authentication.AuthenticationResult;
25  import org.codehaus.plexus.redback.authorization.AuthorizationException;
26  import org.codehaus.plexus.redback.authorization.AuthorizationResult;
27  import org.codehaus.plexus.redback.keys.KeyManager;
28  import org.codehaus.plexus.redback.keys.memory.MemoryKeyManager;
29  import org.codehaus.plexus.redback.policy.AccountLockedException;
30  import org.codehaus.plexus.redback.policy.DefaultUserSecurityPolicy;
31  import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
32  import org.codehaus.plexus.redback.system.DefaultSecuritySession;
33  import org.codehaus.plexus.redback.system.DefaultSecuritySystem;
34  import org.codehaus.plexus.redback.system.SecuritySession;
35  import org.codehaus.plexus.redback.system.SecuritySystem;
36  import org.codehaus.plexus.redback.users.UserManager;
37  import org.codehaus.plexus.redback.users.UserNotFoundException;
38  import org.codehaus.plexus.redback.users.memory.MemoryUserManager;
39  
40  /**
41   * BypassSecuritySystem - used to bypass the security system for testing reasons and allow
42   * for every request to respond as success / true. 
43   *
44   * @version $Id: BypassSecuritySystem.java 718864 2008-11-19 06:33:35Z brett $
45   * 
46   * @plexus.component 
47   *      role="org.codehaus.plexus.redback.system.SecuritySystem"
48   */
49  public class BypassSecuritySystem
50      extends DefaultSecuritySystem
51      implements SecuritySystem
52  {
53      private KeyManager bypassKeyManager;
54      private UserSecurityPolicy bypassPolicy;
55      private UserManager bypassUserManager;
56      
57      public BypassSecuritySystem()
58      {
59          bypassKeyManager = new MemoryKeyManager();
60          bypassPolicy = new DefaultUserSecurityPolicy();
61          bypassUserManager = new MemoryUserManager();
62      }
63      
64      public SecuritySession authenticate( AuthenticationDataSource source )
65          throws AuthenticationException, UserNotFoundException, AccountLockedException
66      {
67          AuthenticationResult result = new AuthenticationResult( true, source.getPrincipal(), null );
68          return new DefaultSecuritySession( result );
69      }
70  
71      public AuthorizationResult authorize( SecuritySession session, Object permission )
72          throws AuthorizationException
73      {
74          return new AuthorizationResult( true, session.getUser(), null );
75      }
76  
77      public AuthorizationResult authorize( SecuritySession session, Object permission, Object resource )
78          throws AuthorizationException
79      {
80          return new AuthorizationResult( true, session.getUser(), null );
81      }
82  
83      public String getAuthenticatorId()
84      {
85          return "bypass-authenticator";
86      }
87  
88      public String getAuthorizerId()
89      {
90          return "bypass-authorizer";
91      }
92  
93      public KeyManager getKeyManager()
94      {
95          return bypassKeyManager;
96      }
97  
98      public UserSecurityPolicy getPolicy()
99      {
100         return bypassPolicy;
101     }
102 
103     public String getUserManagementId()
104     {
105         return "bypass-managementid";
106     }
107 
108     public UserManager getUserManager()
109     {
110         return bypassUserManager;
111     }
112 
113     public boolean isAuthenticated( AuthenticationDataSource source )
114         throws AuthenticationException, UserNotFoundException, AccountLockedException
115     {
116         // Always true
117         return true;
118     }
119 
120     public boolean isAuthorized( SecuritySession session, Object permission )
121         throws AuthorizationException
122     {
123         // Always true
124         return true;
125     }
126 
127     public boolean isAuthorized( SecuritySession session, Object permission, Object resource )
128         throws AuthorizationException
129     {
130         // Always true
131         return true;
132     }
133 }