mirror of
https://github.com/apache/rocketmq-dashboard.git
synced 2025-09-11 03:49:06 +08:00
Add frontend session check logic
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
package org.apache.rocketmq.console.controller;
|
||||
|
||||
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.UserInfo;
|
||||
import org.apache.rocketmq.console.service.UserService;
|
||||
@@ -49,8 +50,12 @@ public class LoginController {
|
||||
@RequestMapping(value = "/check.query", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object check(HttpServletRequest request) {
|
||||
WebUtil.setSessionValue(request, WebUtil.NEED_LOGIN, configure.isLoginRequired());
|
||||
return new Boolean(configure.isLoginRequired());
|
||||
LoginInfo loginInfo = new LoginInfo();
|
||||
|
||||
loginInfo.setLogined(WebUtil.getValueFromSession(request, WebUtil.USER_NAME) != null);
|
||||
loginInfo.setLoginRequired(configure.isLoginRequired());
|
||||
|
||||
return loginInfo;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login.do", method = RequestMethod.POST)
|
||||
@@ -69,7 +74,9 @@ public class LoginController {
|
||||
UserInfo userInfo = WebUtil.setLoginInfo(request, response, user);
|
||||
WebUtil.setSessionValue(request, WebUtil.USER_INFO, userInfo);
|
||||
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 long loginTime;
|
||||
private String ip;
|
||||
private String sessionId;
|
||||
|
||||
public long getLoginTime() {
|
||||
return loginTime;
|
||||
@@ -46,12 +47,21 @@ public class UserInfo {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(String sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"user=" + user +
|
||||
", loginTime=" + loginTime +
|
||||
", ip='" + ip + '\'' +
|
||||
", sessionId='" + sessionId + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@@ -133,4 +133,8 @@ public class WebUtil {
|
||||
HttpSession session = request.getSession();
|
||||
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;
|
||||
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 setting = {
|
||||
type: "GET",
|
||||
@@ -62,7 +54,11 @@ var app = angular.module('app', [
|
||||
init(function(resp){
|
||||
if (resp.status == 0) {
|
||||
// console.log('resp.data==='+resp.data);
|
||||
loginFlag = resp.data;
|
||||
var loginInfo = resp.data;
|
||||
loginFlag = loginInfo.loginRequired;
|
||||
if (!loginInfo.logined) {
|
||||
$window.sessionStorage.clear();
|
||||
}
|
||||
}else {
|
||||
Notification.error({message: "" + resp.errMsg, delay: 2000});
|
||||
}
|
||||
|
@@ -34,6 +34,8 @@ app.controller('loginController', ['$scope','$location','$http','Notification','
|
||||
if (resp.status == 0) {
|
||||
Notification.info({message: 'Login successful, redirect now', delay: 2000});
|
||||
$window.sessionStorage.setItem("username", $("#username").val());
|
||||
//alert("XXXXX resp.data="+resp.data.sessionId);
|
||||
//$window.sessionStorage.setItem("sessionId", resp.data.sessionId);
|
||||
window.location = "/";
|
||||
initFlag = false;
|
||||
} else{
|
||||
|
Reference in New Issue
Block a user