mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 20:50:14 +08:00
apps
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package org.maxkey.authn.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.fasterxml.jackson.core.exc.StreamWriteException;
|
||||
import com.fasterxml.jackson.databind.DatabindException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@Controller
|
||||
public class AuthEntryPoint {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(AuthEntryPoint.class);
|
||||
|
||||
@RequestMapping(value={"/auth/entrypoint"})
|
||||
public void entryPoint(
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws StreamWriteException, DatabindException, IOException {
|
||||
_logger.trace("AuthEntryPoint /entrypoint.");
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
|
||||
final Map<String, Object> body = new HashMap<>();
|
||||
body.put("status", HttpServletResponse.SC_UNAUTHORIZED);
|
||||
body.put("error", "Unauthorized");
|
||||
body.put("message", "Unauthorized");
|
||||
body.put("path", request.getServletPath());
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.writeValue(response.getOutputStream(), body);
|
||||
}
|
||||
}
|
||||
@@ -78,8 +78,8 @@ public class PermissionAdapter implements AsyncHandlerInterceptor {
|
||||
//判断用户是否登录
|
||||
if(WebContext.getAuthentication()==null
|
||||
||WebContext.getAuthentication().getAuthorities()==null){//判断用户和角色,判断用户是否登录用户
|
||||
_logger.trace("No Authentication ... forward to /login");
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
|
||||
_logger.trace("No Authentication ... forward to /auth/entrypoint");
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/auth/entrypoint");
|
||||
dispatcher.forward(request, response);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user