티스토리 뷰
Web Development/Spring OAuth2
Spring OAuth2 CORS(cross origin requests are only supported for HTTP) 관련 필터 설정.
dev ms 2016. 8. 12. 15:24반응형
OncePerRequestFilter로는 안됐다 -_-;;
그래서 찾던중 알아낸게 그냥 Filter를 Implements 해서 하는 방법을 알아냈다.
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CorsFilter implements Filter {
private static Logger LOG = LoggerFactory.getLogger(CorsFilter.class);
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest request = (HttpServletRequest) req;
LOG.info("CorsFilter filter");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE, HEAD");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "X-Requested-With, X-Auth-Token, Content-Type, Authorization");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.addHeader("Cache-Control", "no-cache");
if (!"OPTIONS".equalsIgnoreCase(request.getMethod())) {
chain.doFilter(req, res);
}
}
@Override
public void init(FilterConfig config) throws ServletException {
}
}
Order 애노테이션에 선언된 Ordered는 아래와 같다.
Filter 순서를 최대한 빨리 실행되도록 설정을 해주는 것 같다.
/**
* {@code Ordered} is an interface that can be implemented by objects that
* should be <em>orderable</em>, for example in a {@code Collection}.
*
* <p>The actual {@link #getOrder() order} can be interpreted as prioritization,
* with the first object (with the lowest order value) having the highest
* priority.
*
* <p>Note that there is also a <em>priority</em> marker for this interface:
* {@link PriorityOrdered}. Order values expressed by {@code PriorityOrdered}
* objects always apply before same order values expressed by <em>plain</em>
* {@link Ordered} objects.
*
* <p>Consult the Javadoc for {@link OrderComparator} for details on the
* sort semantics for non-ordered objects.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 07.04.2003
* @see PriorityOrdered
* @see OrderComparator
* @see org.springframework.core.annotation.Order
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
*/
public interface Ordered {
/**
* Useful constant for the highest precedence value.
* @see java.lang.Integer#MIN_VALUE
*/
int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;
/**
* Useful constant for the lowest precedence value.
* @see java.lang.Integer#MAX_VALUE
*/
int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
/**
* Get the order value of this object.
* <p>Higher values are interpreted as lower priority. As a consequence,
* the object with the lowest value has the highest priority (somewhat
* analogous to Servlet {@code load-on-startup} values).
* <p>Same order values will result in arbitrary sort positions for the
* affected objects.
* @return the order value
* @see #HIGHEST_PRECEDENCE
* @see #LOWEST_PRECEDENCE
*/
int getOrder();
}
반응형
'Web Development > Spring OAuth2' 카테고리의 다른 글
Spring oauth2 refresh token 발급시 예외 적용. (0) | 2016.08.12 |
---|---|
Spring oauth2 설정 부분. (0) | 2016.08.12 |
Spring OAuth2 인증 토큰 발급 관련 Test Html (jquery, angularjs) (0) | 2016.08.12 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Kotlin
- jstl 커스텀 태그
- java 설치
- 코루틴
- POI EXCEL
- java calendar
- github image 첨부시 주의할점
- Database#transaction
- jstl foreach
- JSTL
- coroutine
- MyBatis 팁
- jstl split
- JSP 세션
- POE Excel 만들기
- spring property
- mybatis Merge
- spring ExcelView
- java 폴더구조 구하기
- 전자정부프레임워크 tiles
- java 특정문자 갯수구하기
- java 설정
- java 압축 풀기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함