// Path: src/main/java/com/zeven/course/util/Token.java
// public class Token {
// 
//     private int id;
//     private String name;
//     private String role;
//     private int err = 0;
//     public static final int ExpiredJwtError = 1;
//     public static final int SignatureError = 2;
// 
//     public Token(String token) {
//         try {
//             Claims claims = Jwts.parser().setSigningKey(Auth.key).parseClaimsJws(token).getBody();
//             this.id = Integer.parseInt(claims.get("id").toString());
//             this.name = claims.get("name").toString();
//             this.role = claims.get("role").toString();
//         } catch (ExpiredJwtException e){
//             this.err = ExpiredJwtError;
//         } catch (SignatureException e) {
//             this.err = SignatureError;
//         }
// 
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getRole() {
//         return role;
//     }
// 
//     public int getErr() {
//         return err;
//     }
// 
// }


import com.zeven.course.util.Token;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
package com.zeven.course.interceptor;



/**
 * Created by fangf on 2016/5/21.
 * OAuth权限认证
 */
public class AccessInterceptor extends CrossDomainInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String path = request.getContextPath();
        String uri = request.getRequestURI();
        if (!uri.startsWith(path+"/Access")) {
            String auth = request.getHeader("Authorization");
            if (auth==null){
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                        "Authentication Failed: Require Authorization");
                return false;
            }
// Path: src/main/java/com/zeven/course/util/Token.java
// public class Token {
// 
//     private int id;
//     private String name;
//     private String role;
//     private int err = 0;
//     public static final int ExpiredJwtError = 1;
//     public static final int SignatureError = 2;
// 
//     public Token(String token) {
//         try {
//             Claims claims = Jwts.parser().setSigningKey(Auth.key).parseClaimsJws(token).getBody();
//             this.id = Integer.parseInt(claims.get("id").toString());
//             this.name = claims.get("name").toString();
//             this.role = claims.get("role").toString();
//         } catch (ExpiredJwtException e){
//             this.err = ExpiredJwtError;
//         } catch (SignatureException e) {
//             this.err = SignatureError;
//         }
// 
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getRole() {
//         return role;
//     }
// 
//     public int getErr() {
//         return err;
//     }
// 
// }


// Path: src/main/java/com/zeven/course/interceptor/AccessInterceptor.java
import com.zeven.course.util.Token;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

package com.zeven.course.interceptor;



/**
 * Created by fangf on 2016/5/21.
 * OAuth权限认证
 */
public class AccessInterceptor extends CrossDomainInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String path = request.getContextPath();
        String uri = request.getRequestURI();
        if (!uri.startsWith(path+"/Access")) {
            String auth = request.getHeader("Authorization");
            if (auth==null){
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                        "Authentication Failed: Require Authorization");
                return false;
            }
            Token token = new Token(auth);