本文整理汇总了Java中javax.servlet.FilterChain类的典型用法代码示例。如果您正苦于以下问题:Java FilterChain类的具体用法?Java FilterChain怎么用?Java FilterChain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FilterChain类属于javax.servlet包,在下文中一共展示了FilterChain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain)
throws IOException, ServletException {
final HttpServletRequest request = (HttpServletRequest) req;
final String authHeader = request.getHeader("Authorization");
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
ExceptionUtils.createUnauthorizedException("Missing or invalid Authorization header.", res);
return;
}
try {
final String token = authHeader.substring(7); // The part after "Bearer "
final Claims claims =
Jwts.parser().setSigningKey("secretkey").parseClaimsJws(token).getBody();
request.setAttribute("claims", claims);
} catch (final Exception e) {
ExceptionUtils.createUnauthorizedException("Invalid token", res);
return;
}
chain.doFilter(req, res);
}
示例2: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// 包装请求和响应
if (LOGGER.isDebugEnabled()) {
request = new RequestWrapper((HttpServletRequest) request);
response = new ResponseWrapper((HttpServletResponse) response);
}
try {
chain.doFilter(request, response);
} finally {
if (LOGGER.isDebugEnabled()) {
// 进行打印
logRequest((RequestWrapper) request);
logResponse((ResponseWrapper) response);
}
}
}
示例3: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String servletPath = req.getServletPath() + req.getPathInfo();
xLogger.fine("Servlet path: ", servletPath);
if (req.getCharacterEncoding() == null) {
request.setCharacterEncoding(Constants.UTF8);
}
if (!(StringUtils.isNotBlank(servletPath) && servletPath.startsWith(MEDIA_ENDPOINT_URL))) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (filterChain != null) {
filterChain.doFilter(request, response);
}
}
示例4: doFilterInternal
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
String requestUri = request.getRequestURI();
String spaceId = getSpaceIdFromUri(requestUri);
try {
// The spaceId will be null when the requestURI does not match the expected one /api/v1/spaces/*.
// This could happen when the filter is used for processing requests from the SLP API.
// In such cases the filter will be skipped.
if (spaceId != null) {
UserInfo userInfo = SecurityContextUtil.getUserInfo();
AuthorizationChecker.ensureUserIsAuthorized(request, clientProvider, userInfo, spaceId, null);
}
} catch (WebApplicationException e) {
response.sendError(401, MessageFormat.format(Messages.NOT_AUTHORIZED_TO_PERFORM_OPERATIONS_IN_SPACE, spaceId));
return;
}
filterChain.doFilter(request, response);
}
示例5: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain
) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
// if the user is already authenticated, don't override it
if (httpRequest.getRemoteUser() != null) {
chain.doFilter(request, response);
} else {
HttpServletRequestWrapper wrapper =
new HttpServletRequestWrapper(httpRequest) {
@Override
public Principal getUserPrincipal() {
return user;
}
@Override
public String getRemoteUser() {
return username;
}
};
chain.doFilter(wrapper, response);
}
}
示例6: setup
import javax.servlet.FilterChain; //导入依赖的package包/类
@Before
public void setup() throws Exception {
filter = new AuthorizationFilter();
filter.authService = mock(APPAuthenticationServiceBean.class);
VOUserDetails user = new VOUserDetails();
user.setLocale("de");
doReturn(user).when(filter.authService).authenticateAdministrator(
any(PasswordAuthentication.class));
chain = mock(FilterChain.class);
config = mock(FilterConfig.class);
req = mock(HttpServletRequest.class);
resp = mock(HttpServletResponse.class);
session = mock(HttpSession.class);
when(req.getSession()).thenReturn(session);
when(req.getLocale()).thenReturn(new Locale("en"));
when(req.getServletPath()).thenReturn("/xxx");
when(config.getInitParameter(any(String.class))).thenReturn("css");
}
示例7: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest request = (HttpServletRequest) req;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with, authorization, content-type, correlation-id");
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
}
else {
chain.doFilter(req, res);
}
}
示例8: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
String relativeURI = request.getRequestURI().trim();// 相对地址
if(request.getContextPath().length() > 0)
{
relativeURI = relativeURI.replaceFirst(request.getContextPath(), "");
}
if(isIgnoreURI(relativeURI))// 是否不用判断
{
chain.doFilter(request, response);
return;
}
// 取得当前用户账号
String userAccount = WebFilter.getAccount(request.getSession());
if(isAccess(request, userAccount, relativeURI))// 判断是否能访问该页面
{
chain.doFilter(request, response);// 有权限访问
return;
}
// 没权限
response.sendRedirect(request.getContextPath() + PAGE_NOACCESS); // 无权限访问,跳转页面
return;
}
示例9: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException {
try {
chain.doFilter(request, response);
} catch (final Exception exception) {
// Error before security/jax-rs management
log.error("High level error", exception);
// Catch this stack
final HttpServletResponse response3 = (HttpServletResponse) response;
response3.setStatus(Status.INTERNAL_SERVER_ERROR.getStatusCode());
response3.setContentType(MediaType.APPLICATION_JSON_TYPE.toString());
response3.setCharacterEncoding(StandardCharsets.UTF_8.name());
response3.getOutputStream().write("{\"code\":\"internal\"}".getBytes(StandardCharsets.UTF_8));
response3.flushBuffer();
}
}
示例10: doFilterInternal
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilterInternal(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain chain)
throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest)servletRequest;
String str = request.getRequestURI().toLowerCase();
boolean flag = true;
int idx = 0;
if ((idx = str.indexOf(".")) > 0){
str = str.substring(idx);
if (ignoreExt.contains(str.toLowerCase())){
flag = false;
}
}
if (flag){
super.doFilterInternal(servletRequest, servletResponse, chain);
} else {
chain.doFilter(servletRequest, servletResponse);
}
}
示例11: doFilterInternal
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
if (!registry.isEnabled()) {
filterChain.doFilter(request, response);
return;
}
final long startTime = registry.getNanos();
filterChain.doFilter(request, response);
final long duration = registry.getNanos() - startTime;
final String username = getUsername();
registry.increment("spring.Username.Invocations", username);
registry.add("spring.Username.Durations", username, duration);
}
示例12: doFilterInternal
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
String allowedRequestHeaders = request.getHeader("Access-Control-Request-Headers");
String responseHeader = XApiConstants.XAPI_VERSION_HEADER;
if (StringUtils.isNotBlank(allowedRequestHeaders)) {
if (StringUtils.contains(allowedRequestHeaders, XApiConstants.XAPI_VERSION_HEADER.toLowerCase())) {
responseHeader = responseHeader.toLowerCase();
}
}
response.addHeader(responseHeader, version);
filterChain.doFilter(request, response);
}
示例13: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest hsrq = (HttpServletRequest) request;
HttpServletResponse hsrp = (HttpServletResponse) response;
String clientType = hsrq.getParameter("clientType");
if ("WORD".equals(clientType)) {
chain.doFilter(request, response);
} else {
SessionUser person = null;
String reqPage = hsrq.getServletPath();
if (!reqPage.trim().equals("/login.do") && !reqPage.trim().equals("/logout.do")
) {
person = (SessionUser) hsrq.getSession().getAttribute(SysConstants.SESSION_USER_KEY);
if (person == null) {
hsrp.sendRedirect("login.do");
return;
}
}
chain.doFilter(request, response);
}
}
示例14: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
arg0.setAttribute("siteName", Config.SITE_NAME);
arg0.setAttribute("pageTitle", Config.TITLE_SITE);
arg0.setAttribute("metaDescription", Config.META_DESCRIPTION);
arg0.setAttribute("metaKeywords", Config.META_KEYWORDS);
arg0.setAttribute("year", Config.getYear());
arg0.setAttribute("url", Config.SITE_URL);
arg0.setAttribute("tplUrl", Config.TPL_URL);
arg0.setAttribute("staticUrl", Config.STATIC_URL);
arg0.setAttribute("analyticsId", Config.ANALYTICS_ID);
arg0.setAttribute("emailAddress", Config.CONTACT_EMAIL);
arg2.doFilter(arg0, arg1);
}
示例15: doFilter
import javax.servlet.FilterChain; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
MDC.put("url", httpRequest.getRequestURI());
MDC.put("referer", httpRequest.getHeader("referer"));
MDC.put("request-id", UUID.randomUUID().toString());
MDC.put("accept-encoding", httpRequest.getHeader("accept-encoding"));
MDC.put("accept-language", httpRequest.getHeader("accept-language"));
MDC.put("accept", httpRequest.getHeader("accept"));
MDC.put("user-agent", httpRequest.getHeader("user-agent"));
MDC.put("client-ip", httpRequest.getRemoteAddr());
MDC.put("forwarded-for", httpRequest.getHeader("x-forwarded-for"));
MDC.put("client", RequestHelper.getIpAdress(httpRequest));
chain.doFilter(request, response);
MDC.put("http-status", Integer.toString(httpResponse.getStatus()));
LOGGER.info("outgoing response");
}