Skip to content

Commit

Permalink
添加 UtilRequest 工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
叶云轩.MacBookPro committed Dec 30, 2019
1 parent 4fcfc11 commit 741ad85
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cjwy-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
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);
}
}
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;
}

}

0 comments on commit 741ad85

Please sign in to comment.