This project has retired. For details please refer to its Attic page.
RbacManagerEventTracker xref
View Javadoc

1   package org.apache.archiva.redback.tests;
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.apache.archiva.redback.rbac.RBACManagerListener;
23  import org.apache.archiva.redback.rbac.Permission;
24  import org.apache.archiva.redback.rbac.Role;
25  import org.apache.archiva.redback.rbac.UserAssignment;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  /**
33   * RbacManagerEventTracker
34   *
35   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
36   *
37   */
38  public class RbacManagerEventTracker
39      implements RBACManagerListener
40  {
41      public long initCount = 0;
42  
43      public Boolean lastDbFreshness;
44  
45      public List<String> addedRoleNames = new ArrayList<String>();
46  
47      public List<String> removedRoleNames = new ArrayList<String>();
48  
49      public List<String> addedPermissionNames = new ArrayList<String>();
50  
51      public List<String> removedPermissionNames = new ArrayList<String>();
52  
53      protected Logger logger = LoggerFactory.getLogger( getClass() );
54  
55      public void rbacInit( boolean freshdb )
56      {
57          log( "Init - freshdb: " + freshdb );
58          initCount++;
59          lastDbFreshness = Boolean.valueOf( freshdb );
60      }
61  
62      public void rbacPermissionRemoved( Permission permission )
63      {
64          log( "Permission Removed: " + permission.getName() );
65          String obj = permission.getName();
66          if ( !removedPermissionNames.contains( obj ) )
67          {
68              removedPermissionNames.add( obj );
69          }
70      }
71  
72      public void rbacPermissionSaved( Permission permission )
73      {
74          log( "Permission Saved: " + permission.getName() );
75          String obj = permission.getName();
76          if ( !addedPermissionNames.contains( obj ) )
77          {
78              addedPermissionNames.add( obj );
79          }
80      }
81  
82      public void rbacRoleRemoved( Role role )
83      {
84          log( "Role Removed: " + role.getName() );
85          String obj = role.getName();
86          if ( !removedRoleNames.contains( obj ) )
87          {
88              removedRoleNames.add( obj );
89          }
90      }
91  
92      public void rbacRoleSaved( Role role )
93      {
94          log( "Role Saved: " + role.getName() );
95          String obj = role.getName();
96          if ( !addedRoleNames.contains( obj ) )
97          {
98              addedRoleNames.add( obj );
99          }
100     }
101 
102     public void rbacUserAssignmentRemoved( UserAssignment userAssignment )
103     {
104 
105     }
106 
107     public void rbacUserAssignmentSaved( UserAssignment userAssignment )
108     {
109 
110     }
111 
112     private void log( String msg )
113     {
114         logger.info( "[RBAC Event Tracker] : {}", msg );
115     }
116 }