// Path: summer-core/src/main/java/org/smartx/summer/config/register/FormatterRegister.java
// public interface FormatterRegister {
//     /**
//      *
//      * 注册器
//      *
//      * @param registry formatter注册器
//      */
//     void registry(FormatterRegistry registry);
// }
// 
// Path: summer-core/src/main/java/org/smartx/summer/config/register/MessageConvertersRegister.java
// public interface MessageConvertersRegister {
// 
//     /**
//      * 注册器
//      *
//      * @param converters
//      */
//     void registry(List<HttpMessageConverter<?>> converters);
// }
// 
// Path: summer-core/src/main/java/org/smartx/summer/interceptor/JwtInterceptor.java
// @Component
// public class JwtInterceptor extends HandlerInterceptorAdapter {
// 
//     private static final String BEARER = "Bearer ";
// 
//     @Resource
//     private TokenProvider tokenProvider;
// 
//     @Override
//     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 
//         if (handler instanceof HandlerMethod) {
//             HandlerMethod maControl = (HandlerMethod) handler;
//             VerifyJwtRole verifyJwtRole = maControl.getMethodAnnotation(VerifyJwtRole.class);
// 
//             if (null == verifyJwtRole) {
//                 return true;
//             }
// 
//             Claims claims = null;
//             if (verifyJwtRole.verifyJwt()) {
//                 String authorizationHeader = request.getHeader(SessionAndTokenConstants.AUTHORIZATION_HEADER);
//                 if (StringUtils.isEmpty(authorizationHeader) || !authorizationHeader.startsWith(BEARER)) {
//                     throw new AuthenticationException("Missing or invalid Authorization header.");
//                 }
//                 // The part after "Bearer "
//                 final String token = authorizationHeader.substring(7);
//                 try {
//                     claims = tokenProvider.getClaimsFromToken(token);
// 
//                     tokenProvider.verifyToken(claims);
//                     Integer userId = tokenProvider.getUserIdByClaims(claims);
//                     request.setAttribute(SessionAndTokenConstants.SESSION_USER_ID, userId);
//                     request.setAttribute(SessionAndTokenConstants.TOKEN_CLAIMS, claims);
//                 } catch (SignatureException exception) {
//                     response.setHeader("WWW-Authenticate", "xBasic realm=\"fake\"");
//                     throw new AuthenticationException(TokenProvider.TOKEN_INVALID_SIGNATURE);
//                 } catch (final Exception e) {
//                     response.setHeader("WWW-Authenticate", "xBasic realm=\"fake\"");
//                     throw new AuthenticationException(TokenProvider.DEFAULT_INVALID_JWT_MSG);
//                 }
//             } else {
//                 claims = (Claims) request.getAttribute(SessionAndTokenConstants.TOKEN_CLAIMS);
//             }
// 
//             Assert.notNull(claims, "Claims  could not be null");
// 
//             if (verifyJwtRole.roles().length > 0) {
//                 String[] requireRole = verifyJwtRole.roles();
//                 String[] roles = tokenProvider.getRolesFromClaims(claims);
//                 if (!Arrays.asList(roles).containsAll(Arrays.asList(requireRole))) {
//                     // 没有方法要求的角色
//                     throw new AuthenticationException("You are not the require role.");
//                 }
//             }
//             return true;
//         }
//         return true;
//     }
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartx.summer.config.register.FormatterRegister;
import org.smartx.summer.config.register.MessageConvertersRegister;
import org.smartx.summer.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;
package org.smartx.summer.config;



/**
 * Created by binglin on 2016/10/27.
 *
 * 代替spring-mvc.xml文件
 *
 * @author binglin
 */

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"org.smartx.summer.controller",
        "org.smartx.summer.interceptor",
        "org.smartx.summer.config.register",
        "org.smartx.summer.register",
        "org.smartx.summer.filter",
        "org.smartx.summer.session",
        "org.smartx.summer.config",
// Path: summer-core/src/main/java/org/smartx/summer/config/register/FormatterRegister.java
// public interface FormatterRegister {
//     /**
//      *
//      * 注册器
//      *
//      * @param registry formatter注册器
//      */
//     void registry(FormatterRegistry registry);
// }
// 
// Path: summer-core/src/main/java/org/smartx/summer/config/register/MessageConvertersRegister.java
// public interface MessageConvertersRegister {
// 
//     /**
//      * 注册器
//      *
//      * @param converters
//      */
//     void registry(List<HttpMessageConverter<?>> converters);
// }
// 
// Path: summer-core/src/main/java/org/smartx/summer/interceptor/JwtInterceptor.java
// @Component
// public class JwtInterceptor extends HandlerInterceptorAdapter {
// 
//     private static final String BEARER = "Bearer ";
// 
//     @Resource
//     private TokenProvider tokenProvider;
// 
//     @Override
//     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 
//         if (handler instanceof HandlerMethod) {
//             HandlerMethod maControl = (HandlerMethod) handler;
//             VerifyJwtRole verifyJwtRole = maControl.getMethodAnnotation(VerifyJwtRole.class);
// 
//             if (null == verifyJwtRole) {
//                 return true;
//             }
// 
//             Claims claims = null;
//             if (verifyJwtRole.verifyJwt()) {
//                 String authorizationHeader = request.getHeader(SessionAndTokenConstants.AUTHORIZATION_HEADER);
//                 if (StringUtils.isEmpty(authorizationHeader) || !authorizationHeader.startsWith(BEARER)) {
//                     throw new AuthenticationException("Missing or invalid Authorization header.");
//                 }
//                 // The part after "Bearer "
//                 final String token = authorizationHeader.substring(7);
//                 try {
//                     claims = tokenProvider.getClaimsFromToken(token);
// 
//                     tokenProvider.verifyToken(claims);
//                     Integer userId = tokenProvider.getUserIdByClaims(claims);
//                     request.setAttribute(SessionAndTokenConstants.SESSION_USER_ID, userId);
//                     request.setAttribute(SessionAndTokenConstants.TOKEN_CLAIMS, claims);
//                 } catch (SignatureException exception) {
//                     response.setHeader("WWW-Authenticate", "xBasic realm=\"fake\"");
//                     throw new AuthenticationException(TokenProvider.TOKEN_INVALID_SIGNATURE);
//                 } catch (final Exception e) {
//                     response.setHeader("WWW-Authenticate", "xBasic realm=\"fake\"");
//                     throw new AuthenticationException(TokenProvider.DEFAULT_INVALID_JWT_MSG);
//                 }
//             } else {
//                 claims = (Claims) request.getAttribute(SessionAndTokenConstants.TOKEN_CLAIMS);
//             }
// 
//             Assert.notNull(claims, "Claims  could not be null");
// 
//             if (verifyJwtRole.roles().length > 0) {
//                 String[] requireRole = verifyJwtRole.roles();
//                 String[] roles = tokenProvider.getRolesFromClaims(claims);
//                 if (!Arrays.asList(roles).containsAll(Arrays.asList(requireRole))) {
//                     // 没有方法要求的角色
//                     throw new AuthenticationException("You are not the require role.");
//                 }
//             }
//             return true;
//         }
//         return true;
//     }
// }


// Path: summer-demo/src/main/java/org/smartx/summer/config/WebConfig.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartx.summer.config.register.FormatterRegister;
import org.smartx.summer.config.register.MessageConvertersRegister;
import org.smartx.summer.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;

package org.smartx.summer.config;



/**
 * Created by binglin on 2016/10/27.
 *
 * 代替spring-mvc.xml文件
 *
 * @author binglin
 */

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"org.smartx.summer.controller",
        "org.smartx.summer.interceptor",
        "org.smartx.summer.config.register",
        "org.smartx.summer.register",
        "org.smartx.summer.filter",
        "org.smartx.summer.session",
        "org.smartx.summer.config",
        "org.smartx.summer.listener"})