-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
叶云轩.MacBookPro
committed
Dec 30, 2019
1 parent
4fcfc11
commit 741ad85
Showing
3 changed files
with
58 additions
and
0 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
19 changes: 19 additions & 0 deletions
19
...mons/src/main/java/com/cjwy/projects/commons/http/exception/NoAuthorizationException.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,19 @@ | ||
package com.cjwy.projects.commons.http.exception; | ||
|
||
/** | ||
* 没有权限访问异常 | ||
* <p> | ||
* | ||
* @author 叶云轩 at [email protected] | ||
* @date 2019/12/31 3:08 上午 | ||
*/ | ||
public class NoAuthorizationException extends RuntimeException { | ||
|
||
public NoAuthorizationException() { | ||
super(); | ||
} | ||
|
||
public NoAuthorizationException(String message) { | ||
super(message); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
cjwy-commons/src/main/java/com/cjwy/projects/commons/http/utils/UtilRequest.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,34 @@ | ||
package com.cjwy.projects.commons.http.utils; | ||
|
||
import com.cjwy.projects.commons.http.exception.NoAuthorizationException; | ||
import org.springframework.util.StringUtils; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* UtilRequest | ||
* <p> | ||
* | ||
* @author 叶云轩 at [email protected] | ||
* @date 2019/12/31 3:04 上午 | ||
*/ | ||
public class UtilRequest { | ||
|
||
private UtilRequest() { | ||
} | ||
|
||
/** | ||
* 从请求头中获取认证信息的方法 | ||
* | ||
* @param request 请求 | ||
* @return token | ||
*/ | ||
public static String getAuthorizationInHeader(HttpServletRequest request) { | ||
String authorization = request.getHeader("Authorization"); | ||
if (StringUtils.isEmpty(authorization)) { | ||
throw new NoAuthorizationException(); | ||
} | ||
return authorization; | ||
} | ||
|
||
} |