1 package org.apache.maven.archiva.web.check;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.maven.archiva.database.ArchivaDAO;
23 import org.apache.maven.archiva.database.ArchivaDatabaseException;
24 import org.apache.maven.archiva.database.ObjectNotFoundException;
25 import org.apache.maven.archiva.model.ArchivaRepository;
26 import org.codehaus.plexus.logging.AbstractLogEnabled;
27 import org.codehaus.plexus.redback.role.RoleManager;
28 import org.codehaus.plexus.redback.role.RoleManagerException;
29 import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
31 import java.util.Iterator;
32 import java.util.List;
35 * RoleExistanceEnvironmentCheck:
37 * Under certain circumstances it is possible that the user store and/or role store
38 * have been wiped or reset and its important to see if there are repositories already
39 * configured in archiva that need to reinitialized in terms of having their roles created.
41 * @author: Jesse McConnell <jmcconnell@apache.org>
43 * @plexus.component role="org.codehaus.plexus.security.system.check.EnvironmentCheck"
44 * role-hint="repository-role-check"
46 public class RoleExistanceEnvironmentCheck
47 extends AbstractLogEnabled
48 implements EnvironmentCheck
51 * @plexus.requirement role-hint="jdo"
53 private ArchivaDAO dao;
56 * @plexus.requirement role-hint="default"
58 private RoleManager roleManager;
60 private boolean checked;
62 public void validateEnvironment( List list )
68 List repos = dao.getRepositoryDAO().getRepositories();
70 // TODO! this be skipping non-managed repos
71 Iterator it = repos.iterator();
72 while ( it.hasNext() )
74 ArchivaRepository repository = (ArchivaRepository) it.next();
76 if ( !roleManager.templatedRoleExists( "archiva-repository-manager", repository.getId() ) )
78 roleManager.createTemplatedRole( "archiva-repository-manager", repository.getId() );
81 if ( !roleManager.templatedRoleExists( "archiva-repository-observer", repository.getId() ) )
83 roleManager.createTemplatedRole( "archiva-repository-observer", repository.getId() );
87 catch ( RoleManagerException rpe )
89 list.add( this.getClass().getName() + "error initializing roles: " + rpe.getMessage() );
90 getLogger().info( "error initializing roles", rpe );
92 catch ( ObjectNotFoundException e )
95 this.getClass().getName() + "error initializing roles (repository not found): " + e.getMessage() );
96 getLogger().info( "error initializing roles", e );
98 catch ( ArchivaDatabaseException e )
100 list.add( this.getClass().getName() + "error initializing roles (database error): " + e.getMessage() );
101 getLogger().info( "error initializing roles", e );