Line data Source code
1 : // Copyright (C) 2010 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.httpd.auth.openid; 16 : 17 : import com.google.gerrit.server.config.CanonicalWebUrl; 18 : import com.google.inject.Inject; 19 : import com.google.inject.Provider; 20 : import com.google.inject.Singleton; 21 : import java.io.IOException; 22 : import javax.servlet.Filter; 23 : import javax.servlet.FilterChain; 24 : import javax.servlet.FilterConfig; 25 : import javax.servlet.ServletException; 26 : import javax.servlet.ServletRequest; 27 : import javax.servlet.ServletResponse; 28 : import javax.servlet.http.HttpServletResponse; 29 : 30 : @Singleton 31 : class XrdsFilter implements Filter { 32 : private final Provider<String> url; 33 : 34 : @Inject 35 99 : XrdsFilter(@CanonicalWebUrl final Provider<String> url) { 36 99 : this.url = url; 37 99 : } 38 : 39 : @Override 40 : public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 41 : throws IOException, ServletException { 42 0 : HttpServletResponse rsp = (HttpServletResponse) response; 43 0 : rsp.setHeader("X-XRDS-Location", url.get() + XrdsServlet.LOCATION); 44 0 : chain.doFilter(request, response); 45 0 : } 46 : 47 : @Override 48 99 : public void init(FilterConfig config) {} 49 : 50 : @Override 51 99 : public void destroy() {} 52 : }