-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Filter to swagger - Add Token Interceptor
- Loading branch information
Showing
3 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/br/com/spring/restful/interceptor/TokenInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package br.com.spring.restful.interceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Component | ||
public class TokenInterceptor implements HandlerInterceptor { | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
|
||
System.out.println("||----------> Token authorization validation"); | ||
|
||
if (!request.getRequestURI().contains("swagger") && StringUtils.isEmpty(request.getHeader("Authorization"))) { | ||
throw new Exception("Could not check the authorization"); | ||
} | ||
|
||
return HandlerInterceptor.super.preHandle(request, response, handler); | ||
} | ||
|
||
} |