1 package org.apache.archiva.web.security;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
23 import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin;
24 import org.apache.archiva.redback.authorization.AuthorizationDataSource;
25 import org.apache.archiva.redback.authorization.AuthorizationException;
26 import org.apache.archiva.redback.authorization.AuthorizationResult;
27 import org.apache.archiva.redback.authorization.Authorizer;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.stereotype.Service;
33 import javax.inject.Inject;
34 import javax.inject.Named;
37 * @author Olivier Lamy
40 @Service( "authorizer#archiva" )
41 public class ArchivaAuthorizer
44 private Logger log = LoggerFactory.getLogger( getClass() );
47 private ApplicationContext applicationContext;
50 private RedbackRuntimeConfigurationAdmin redbackRuntimeConfigurationAdmin;
57 public AuthorizationResult isAuthorized( AuthorizationDataSource source )
58 throws AuthorizationException
60 log.debug( "isAuthorized source: {}", source );
64 RedbackRuntimeConfiguration redbackRuntimeConfiguration =
65 redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
67 AuthorizationException authorizationException = null;
69 AuthorizationResult lastResult = null;
71 for ( String id : redbackRuntimeConfiguration.getAuthorizerImpls() )
73 Authorizer authorizer = getAuthorizer( id );
75 AuthorizationResult result = null;
78 result = authorizer.isAuthorized( source );
79 log.debug( "AuthorizationResult {} with id '{}", result, id );
81 catch ( AuthorizationException e )
83 log.debug( "AuthorizationException {} with id '{}", e.getMessage(), id );
84 authorizationException = e;
87 if ( result != null && result.isAuthorized() )
94 if ( authorizationException != null )
96 throw authorizationException;
100 catch ( RepositoryAdminException e )
102 throw new AuthorizationException( e.getMessage(), e );
107 private Authorizer getAuthorizer( String id )
109 return applicationContext.getBean( "authorizer#" + id, Authorizer.class );
112 public boolean isFinalImplementation()
117 public String getDescriptionKey()
119 return "archiva.redback.authorizer.archiva";