mirror of
https://github.com/apache/rocketmq-dashboard.git
synced 2025-09-11 20:15:44 +08:00
Add frontend session check logic
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
package org.apache.rocketmq.console.controller;
|
package org.apache.rocketmq.console.controller;
|
||||||
|
|
||||||
import org.apache.rocketmq.console.config.RMQConfigure;
|
import org.apache.rocketmq.console.config.RMQConfigure;
|
||||||
|
import org.apache.rocketmq.console.model.LoginInfo;
|
||||||
import org.apache.rocketmq.console.model.User;
|
import org.apache.rocketmq.console.model.User;
|
||||||
import org.apache.rocketmq.console.model.UserInfo;
|
import org.apache.rocketmq.console.model.UserInfo;
|
||||||
import org.apache.rocketmq.console.service.UserService;
|
import org.apache.rocketmq.console.service.UserService;
|
||||||
@@ -49,8 +50,12 @@ public class LoginController {
|
|||||||
@RequestMapping(value = "/check.query", method = RequestMethod.GET)
|
@RequestMapping(value = "/check.query", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object check(HttpServletRequest request) {
|
public Object check(HttpServletRequest request) {
|
||||||
WebUtil.setSessionValue(request, WebUtil.NEED_LOGIN, configure.isLoginRequired());
|
LoginInfo loginInfo = new LoginInfo();
|
||||||
return new Boolean(configure.isLoginRequired());
|
|
||||||
|
loginInfo.setLogined(WebUtil.getValueFromSession(request, WebUtil.USER_NAME) != null);
|
||||||
|
loginInfo.setLoginRequired(configure.isLoginRequired());
|
||||||
|
|
||||||
|
return loginInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/login.do", method = RequestMethod.POST)
|
@RequestMapping(value = "/login.do", method = RequestMethod.POST)
|
||||||
@@ -69,7 +74,9 @@ public class LoginController {
|
|||||||
UserInfo userInfo = WebUtil.setLoginInfo(request, response, user);
|
UserInfo userInfo = WebUtil.setLoginInfo(request, response, user);
|
||||||
WebUtil.setSessionValue(request, WebUtil.USER_INFO, userInfo);
|
WebUtil.setSessionValue(request, WebUtil.USER_INFO, userInfo);
|
||||||
WebUtil.setSessionValue(request, WebUtil.USER_NAME, username);
|
WebUtil.setSessionValue(request, WebUtil.USER_NAME, username);
|
||||||
return Boolean.TRUE;
|
userInfo.setSessionId(WebUtil.getSessionId(request));
|
||||||
|
|
||||||
|
return userInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.rocketmq.console.model;
|
||||||
|
|
||||||
|
public class LoginInfo {
|
||||||
|
private boolean loginRequired;
|
||||||
|
private boolean logined;
|
||||||
|
|
||||||
|
public boolean isLoginRequired() {
|
||||||
|
return loginRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginRequired(boolean loginRequired) {
|
||||||
|
this.loginRequired = loginRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLogined() {
|
||||||
|
return logined;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogined(boolean logined) {
|
||||||
|
this.logined = logined;
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ public class UserInfo {
|
|||||||
private User user;
|
private User user;
|
||||||
private long loginTime;
|
private long loginTime;
|
||||||
private String ip;
|
private String ip;
|
||||||
|
private String sessionId;
|
||||||
|
|
||||||
public long getLoginTime() {
|
public long getLoginTime() {
|
||||||
return loginTime;
|
return loginTime;
|
||||||
@@ -46,12 +47,21 @@ public class UserInfo {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSessionId() {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionId(String sessionId) {
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "UserInfo{" +
|
return "UserInfo{" +
|
||||||
"user=" + user +
|
"user=" + user +
|
||||||
", loginTime=" + loginTime +
|
", loginTime=" + loginTime +
|
||||||
", ip='" + ip + '\'' +
|
", ip='" + ip + '\'' +
|
||||||
|
", sessionId='" + sessionId + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -133,4 +133,8 @@ public class WebUtil {
|
|||||||
HttpSession session = request.getSession();
|
HttpSession session = request.getSession();
|
||||||
session.setAttribute(key, value);
|
session.setAttribute(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getSessionId(HttpServletRequest request) {
|
||||||
|
return request.getSession().getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,14 +37,6 @@ var app = angular.module('app', [
|
|||||||
if (initFlag) return;
|
if (initFlag) return;
|
||||||
initFlag = true;
|
initFlag = true;
|
||||||
|
|
||||||
//TODO: make the session timeout consistent with backend
|
|
||||||
// var sessionId = $cookies.get("JSESSIONID");
|
|
||||||
// console.log("sessionId "+ sessionId);
|
|
||||||
//
|
|
||||||
// if (sessionId === undefined || sessionId == null) {
|
|
||||||
// $window.sessionStorage.clear();
|
|
||||||
// }
|
|
||||||
|
|
||||||
var url = '/login/check.query';
|
var url = '/login/check.query';
|
||||||
var setting = {
|
var setting = {
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@@ -62,7 +54,11 @@ var app = angular.module('app', [
|
|||||||
init(function(resp){
|
init(function(resp){
|
||||||
if (resp.status == 0) {
|
if (resp.status == 0) {
|
||||||
// console.log('resp.data==='+resp.data);
|
// console.log('resp.data==='+resp.data);
|
||||||
loginFlag = resp.data;
|
var loginInfo = resp.data;
|
||||||
|
loginFlag = loginInfo.loginRequired;
|
||||||
|
if (!loginInfo.logined) {
|
||||||
|
$window.sessionStorage.clear();
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
Notification.error({message: "" + resp.errMsg, delay: 2000});
|
Notification.error({message: "" + resp.errMsg, delay: 2000});
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,8 @@ app.controller('loginController', ['$scope','$location','$http','Notification','
|
|||||||
if (resp.status == 0) {
|
if (resp.status == 0) {
|
||||||
Notification.info({message: 'Login successful, redirect now', delay: 2000});
|
Notification.info({message: 'Login successful, redirect now', delay: 2000});
|
||||||
$window.sessionStorage.setItem("username", $("#username").val());
|
$window.sessionStorage.setItem("username", $("#username").val());
|
||||||
|
//alert("XXXXX resp.data="+resp.data.sessionId);
|
||||||
|
//$window.sessionStorage.setItem("sessionId", resp.data.sessionId);
|
||||||
window.location = "/";
|
window.location = "/";
|
||||||
initFlag = false;
|
initFlag = false;
|
||||||
} else{
|
} else{
|
||||||
|
Reference in New Issue
Block a user