View Javadoc

1   package org.apache.continuum.distributed.transport.slave;
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.continuum.buildagent.configuration.BuildAgentConfigurationService;
23  import org.apache.xmlrpc.XmlRpcException;
24  import org.apache.xmlrpc.XmlRpcRequest;
25  import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
26  import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  public class SlaveBuildAgentTransportAuthenticator
30      implements AuthenticationHandler
31  {
32      private BuildAgentConfigurationService buildAgentConfigurationService;
33  
34      public SlaveBuildAgentTransportAuthenticator( BuildAgentConfigurationService buildAgentConfigurationService )
35      {
36          this.buildAgentConfigurationService = buildAgentConfigurationService;
37      }
38  
39      public boolean isAuthorized( XmlRpcRequest pRequest )
40          throws XmlRpcException
41      {
42          if ( pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl )
43          {
44              XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl) pRequest.getConfig();
45  
46              if ( config.getBasicPassword() == null || StringUtils.isBlank( config.getBasicPassword() ) )
47              {
48                  throw new XmlRpcException( "Shared Secret Password is not present in the server request" );
49              }
50  
51              if ( buildAgentConfigurationService.getSharedSecretPassword() == null || StringUtils.isBlank(
52                  buildAgentConfigurationService.getSharedSecretPassword() ) )
53              {
54                  throw new XmlRpcException( "Shared Secret Password is not configured properly on the build agent" );
55              }
56  
57              return buildAgentConfigurationService.getSharedSecretPassword().equals( config.getBasicPassword() );
58          }
59  
60          throw new XmlRpcException( "Unsupported transport (must be http)" );
61      }
62  
63  
64  }