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

1   package org.apache.archiva.redback.rest.services.interceptors;
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.cxf.jaxrs.model.OperationResourceInfo;
23  import org.apache.cxf.message.Message;
24  import org.apache.archiva.redback.authorization.RedbackAuthorization;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  import javax.ws.rs.core.Context;
31  import java.lang.reflect.Method;
32  
33  /**
34   * @author Olivier Lamy
35   * @since 1.3
36   */
37  public class AbstractInterceptor
38  {
39  
40      private Logger log = LoggerFactory.getLogger( getClass() );
41  
42      @Context
43      private HttpServletRequest httpServletRequest;
44  
45      @Context
46      private HttpServletResponse httpServletResponse;
47  
48      public HttpServletRequest getHttpServletRequest( Message message )
49      {
50          return httpServletRequest;
51      }
52  
53      public HttpServletResponse getHttpServletResponse( Message message )
54      {
55          return httpServletResponse;
56      }
57  
58      public RedbackAuthorization getRedbackAuthorization( Message message )
59      {
60          OperationResourceInfo operationResourceInfo = message.getExchange().get( OperationResourceInfo.class );
61          if ( operationResourceInfo == null )
62          {
63              return null;
64          }
65  
66          Method method = operationResourceInfo.getAnnotatedMethod();
67  
68          log.debug( " method name {}", method == null ? "null" : method.getName() );
69          RedbackAuthorization redbackAuthorization = method.getAnnotation( RedbackAuthorization.class );
70          return redbackAuthorization;
71      }
72  }