1package org.apache.archiva.redback.rest.services.interceptors;
2/*3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 */202122import org.apache.cxf.interceptor.Fault;
23import org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor;
24import org.apache.cxf.jaxrs.model.OperationResourceInfo;
25import org.apache.cxf.message.Message;
26import org.apache.cxf.phase.AbstractPhaseInterceptor;
27import org.apache.cxf.phase.Phase;
28import org.apache.cxf.phase.PhaseInterceptor;
29import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32import org.springframework.stereotype.Service;
3334import javax.ws.rs.core.Response;
3536/**37 * @author Olivier Lamy38 * @since 1.439 */40 @Service( "threadLocalUserCleaner#rest" )
41publicclassThreadLocalUserCleaner42extends AbstractPhaseInterceptor<Message>
43implements PhaseInterceptor<Message>
44 {
45private Logger log = LoggerFactory.getLogger( getClass() );
4647publicThreadLocalUserCleaner( String phase )
48 {
49super( phase );
50 addAfter( JAXRSInInterceptor.class.getName() );
51 }
525354publicThreadLocalUserCleaner()
55 {
56super( Phase.PRE_STREAM );
57 addAfter( JAXRSInInterceptor.class.getName() );
58 }
596061public Response handleResponse( Message message, OperationResourceInfo operationResourceInfo, Response response )
62 {
63 log.debug( "handleResponse" );
64 cleanup();
65returnnull;
66 }
6768privatevoid cleanup()
69 {
70 RedbackAuthenticationThreadLocal.set( null );
71 }
7273publicvoid handleMessage( Message message )
74throws Fault
75 {
76 log.debug( "handleMessage" );
77 cleanup();
78 }
79 }