parent
05b9dc84db
commit
2fc4fa18cf
@ -1,8 +1,48 @@
|
||||
import { ref } from 'vue'
|
||||
import { reactive } from 'vue'
|
||||
import axios from 'axios'
|
||||
|
||||
const userInfo = ref({
|
||||
isLogin: true,
|
||||
const userInfo = reactive({
|
||||
isLogin: false,
|
||||
userId: '',
|
||||
})
|
||||
|
||||
export const userApi = {
|
||||
loginProcess: async function (inputUsername, inputUserPassword) {
|
||||
const data = { username: inputUsername, password: inputUserPassword }
|
||||
axios.post('/public-api/loginProcess', data).then((response) => {
|
||||
if (response.status == 200 && response.data && response.data.success == true) {
|
||||
userInfo.isLogin = true
|
||||
userInfo.userId = response.data.username
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
logoutProcess: async function () {
|
||||
axios.post('/public-api/logoutProcess').then((response) => {
|
||||
if (response.status == 200 && response.data && response.data.success == true) {
|
||||
userInfo.isLogin = false
|
||||
userInfo.userId = ''
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
loginCheck: async function () {
|
||||
axios.get('/public-api/sessionCheck').then((response) => {
|
||||
if (response.status == 200 && response.data && response.data.success == true) {
|
||||
userInfo.isLogin = true
|
||||
userInfo.userId = response.data.username
|
||||
return true
|
||||
} else {
|
||||
userInfo.isLogin = false
|
||||
userInfo.userId = ''
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
window.userApi = userApi
|
||||
export default userInfo
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.bsmlab.dfx.dfxconsole.framework.config;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class ConsoleLogoutSuccessHandler implements LogoutSuccessHandler {
|
||||
@Override
|
||||
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.getWriter().write("{\"success\": true}");
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package com.bsmlab.dfx.dfxconsole.framework.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Controller
|
||||
public class PasswordGeneratorController {
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@RequestMapping(value = "/public-api/passwordGenerator")
|
||||
public Map<String, String> passwordGenerator(Map<String, String> paramMap) {
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
String plainPassword = paramMap.get("password");
|
||||
if(StringUtils.isNotEmpty(plainPassword)) {
|
||||
String encryptedPassword = passwordEncoder.encode(plainPassword);
|
||||
resultMap.put("password", encryptedPassword);
|
||||
}
|
||||
else {
|
||||
resultMap.put("password", "");
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.bsmlab.dfx.dfxconsole.framework.config;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Controller
|
||||
public class PublicApiController {
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
/**
|
||||
* 암호화 문자열을 만들기 위한 API
|
||||
* @param paramMap {"password": "평문 문자열"}
|
||||
* @return {"password": "암호화 문자열"}
|
||||
*/
|
||||
@RequestMapping(value = "/public-api/passwordGenerator")
|
||||
public ResponseEntity<?> passwordGenerator(Map<String, String> paramMap) {
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
String plainPassword = paramMap.get("password");
|
||||
if(StringUtils.isNotEmpty(plainPassword)) {
|
||||
String encryptedPassword = passwordEncoder.encode(plainPassword);
|
||||
resultMap.put("password", encryptedPassword);
|
||||
}
|
||||
else {
|
||||
resultMap.put("password", "");
|
||||
}
|
||||
return ResponseEntity.ok(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 로그인 세션을 확인하기 위한 API
|
||||
* @param userDetails DI 주입
|
||||
* @return {"success": true/false, "username": 사용자 아이디}
|
||||
*/
|
||||
@RequestMapping(value = "/public-api/sessionCheck")
|
||||
public ResponseEntity<?> sessionCheck(@AuthenticationPrincipal UserDetails userDetails) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
if(userDetails != null) {
|
||||
resultMap.put("success", true);
|
||||
resultMap.put("username", userDetails.getUsername());
|
||||
}
|
||||
else {
|
||||
resultMap.put("success", false);
|
||||
resultMap.put("username", "");
|
||||
}
|
||||
return ResponseEntity.ok(resultMap);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue