コード例 #1
0
ファイル: SafeSessionAction.go プロジェクト: safawo/fast
func (this *ConsultSessionAction) Post() {
	reqMsg := &ConsultSessionRequest{}
	if !this.GetReqJson(reqMsg) {
		return
	}

	rspMsg := &ConsultSessionResponse{}
	rspMsg.Init(reqMsg)

	rspMsg.SessionSeed = utils.RandStr() + "sessionId"
	rspMsg.SessionSeed = utils.EnCodeBase64(rspMsg.SessionSeed)
	rspMsg.SessionSeed = utils.Md5(rspMsg.SessionSeed)

	this.SendJson(rspMsg)
}
コード例 #2
0
ファイル: LogMgr.go プロジェクト: safawo/fast
func (this *logMgrImpl) WriteLog(rspMsg mvc.FastResponseInterface, object, content string) {
	sessMgr := SessionMgr()
	session, ok := sessMgr.GetSession(rspMsg.GetReqSessionId())
	if !ok {
		return
	}

	operateMgr := OperateMgr()
	operateCode := strings.Replace(rspMsg.GetReqActionId(), "/", ".", -1)
	operateCode = utils.Substr(operateCode, 1, len(operateCode))
	operate, ok := operateMgr.GetOperate(operateCode)
	if !ok {
		return
	}

	log := &OperateLog{}

	log.UserName = session.LoginUserName
	log.Subsys = operate.Subsys
	log.OperateGroup = operate.OperateGroup
	log.OperateName = operate.OperateName

	log.OperateRet = rspMsg.GetRspRetId()
	log.OperateRetDetail = rspMsg.GetRspRetMsg()

	log.OperateObj = object
	log.OperateContent = content

	log.UserIpAddress = session.ClientIp
	log.UserHostName = session.ClientHost

	log.OperateTime = rspMsg.GetReqStartTime()

	log.LogType = "User"
	log.SerialNum = utils.RandStr()

	this.WriteRawLog(log)

}
コード例 #3
0
ファイル: SafeRoleAction.go プロジェクト: safawo/fast
func (this *CreateSafeRoleAction) Post() {
	reqMsg := &CreateSafeRoleRequest{}
	if !this.GetReqJson(reqMsg) {
		return
	}

	db := ds.DB()
	defer db.Close()

	addRoleSql := "insert into fast.safeRole values($1,$2,$3,$4,$5,$6,$7)"
	addRoleStmt, err := db.Prepare(addRoleSql)
	utils.VerifyErr(err)

	reqMsg.Id = strings.TrimSpace(reqMsg.Id)

	if reqMsg.Id == comm.NULL_STR {
		reqMsg.Id = utils.RandStr()
	}

	addRoleStmt.Exec(
		reqMsg.Id,
		reqMsg.Name,
		reqMsg.RoleDetail,
		reqMsg.RoleRemark,
		reqMsg.IsUser,
		reqMsg.IsDepart,
		reqMsg.DefaultSafeObject)
	addRoleStmt.Close()

	fmt.Println("addRoleSql:", addRoleSql)

	rspMsg := &CreateSafeRoleResponse{}
	rspMsg.Init(reqMsg)
	rspMsg.SafeRole = reqMsg.SafeRole

	WriteLog(rspMsg, rspMsg.Name, comm.NULL_STR)
	this.SendJson(rspMsg)
}
コード例 #4
0
ファイル: UserMgr.go プロジェクト: safawo/fast
func (this *userMgrImpl) createUser(user *SafeUser) (msgId string, ok bool) {
	msgId = msg.MSG_FAIL
	ok = false

	if user == nil {
		return
	}

	user.Name = strings.TrimSpace(user.Name)
	user.EmployeeId = strings.TrimSpace(user.EmployeeId)
	user.Password = strings.TrimSpace(user.Password)

	if user.Name == comm.NULL_STR ||
		user.Password == comm.NULL_STR {
		msgId = msg.MSG_PARA_ABSENT
		return
	}

	user.Id = utils.RandStr()

	user.Password = utils.PasswordBySeed(user.Password, user.GetId())

	if this.existUserByName(user.Name) {
		msgId = MSG_USERNAME_CLASH
		return
	}

	if this.existUserByEmployee(user.EmployeeId) {
		msgId = MSG_EMPLOYEEID_CLASH
		return
	}

	db := ds.DB()
	defer db.Close()

	createUserSql := "insert into fast.safeUser values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)"
	createUserStmt, err := db.Prepare(createUserSql)
	utils.VerifyErr(err)
	createUserStmt.Exec(
		user.Id,
		user.DepartId,
		user.Name,
		user.Password,
		user.EmployeeId,
		user.NickName,
		user.FirstName,
		user.LastName,
		user.Mobile,
		user.Email,
		user.UserRemark,
		user.IsLock,
		user.LockReason,
		user.IsForever,
		user.AccountExpired)
	createUserStmt.Close()

	createMapRoleSql := "insert into fast.safeRole values($1,$2,$3,$4,$5,$6,$7)"
	createMapRoleStmt, err := db.Prepare(createMapRoleSql)
	utils.VerifyErr(err)
	createMapRoleStmt.Exec(
		user.Id,
		comm.NULL_STR,
		comm.NULL_STR,
		comm.NULL_STR,
		true,
		false,
		comm.NULL_STR)
	createMapRoleStmt.Close()

	insertRoleAllocSql := "insert into fast.roleAlloc values($1,$2)"
	insertRoleAllocStmt, err := db.Prepare(insertRoleAllocSql)
	utils.VerifyErr(err)
	for _, v := range user.Roles {
		insertRoleAllocStmt.Exec(v, user.Id)
	}
	insertRoleAllocStmt.Exec(user.Id, user.Id)

	insertRoleAllocStmt.Close()

	insertOperateAuthSql := "insert into fast.operateAuth values($1,$2)"
	insertOperateAuthStmt, err := db.Prepare(insertOperateAuthSql)
	utils.VerifyErr(err)
	for _, v := range user.Operates {
		insertOperateAuthStmt.Exec(v, user.Id)
	}
	insertOperateAuthStmt.Close()

	insertObjAuthSql := "insert into fast.objectAuth values($1,$2)"
	insertObjAuthStmt, err := db.Prepare(insertObjAuthSql)
	utils.VerifyErr(err)
	for _, v := range user.Objects {
		insertObjAuthStmt.Exec(v, user.Id)
	}
	insertObjAuthStmt.Close()

	this.mapUser[user.Id] = user

	msgId = msg.MSG_SUCCESS
	ok = true

	return
}
コード例 #5
0
ファイル: SessionMgr.go プロジェクト: safawo/fast
func (this *sessionMgrImpl) login(req *http.Request, userName, pasword, hostIp, hostName string) (session *SafeSession, msgId string, ok bool) {
	session = nil
	msgId = comm.NULL_STR
	ok = false

	userName = strings.TrimSpace(userName)
	pasword = strings.TrimSpace(pasword)

	if userName == comm.NULL_STR || pasword == comm.NULL_STR {
		msgId = msg.MSG_PARA_ABSENT
		return
	}

	user, ok := UserMgr().getUserByName(userName)
	if !ok {
		msgId = MSG_USER_INVALID
		return
	}

	msgId, ok = UserMgr().isValid(user.GetId())
	if !ok {
		return
	}

	pasword = utils.PasswordBySeed(pasword, user.GetId())

	if user.Password != pasword {
		msgId = MSG_PASSWORD_ERROR
		ok = false
		return
	}

	if this.IsOnLine(userName) {
		this.Offline(userName)
	}

	clientOnlineLimit := LicenseMgr().GetAllowInt("clientOnlineLimit")
	activateClient := len(this.mapSessions)
	if activateClient >= clientOnlineLimit && !LicenseMgr().IsEmpty() {
		msgId = msg.MSG_LICENSE_NOENOUGH
		ok = false
		return
	}

	session = &SafeSession{}

	session.LoginUserId = user.Id
	session.LoginUserName = user.Name

	session.RandId = utils.RandStr()
	session.ConnTime = utils.StrTime()

	session.ClientIp = hostIp
	session.ClientHost = hostName
	session.ServerIp = req.Host
	session.ServerHost = req.Host

	session.KeepAliveTime = session.ConnTime
	session.SessionStatus = SAFE_SESSION_LOGIN

	session.Id = session.LoginUserName + "&" + session.ConnTime + "&" + utils.RandStr()
	session.Id = utils.EnCodeBase64(session.GetId())
	session.Id = utils.Md5(session.GetId())

	this.mapSessions[session.GetId()] = session

	db := ds.DB()
	defer db.Close()

	insertSql := "insert into fast.safeSession values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)"
	insertStmt, err := db.Prepare(insertSql)
	utils.VerifyErr(err)
	insertStmt.Exec(
		session.Id,
		session.RandId,
		session.ConnTime,
		session.LoginUserId,
		session.LoginUserName,
		session.ClientIp,
		session.ClientHost,
		session.ServerIp,
		session.ServerHost,
		session.KeepAliveTime,
		session.SessionStatus)

	insertStmt.Close()

	msgId = msg.MSG_SUCCESS
	ok = true

	return
}