All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ecfront.ez.framework.service.auth.EZAuthContext.scala Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package com.ecfront.ez.framework.service.auth

import com.ecfront.common.BeanHelper
import com.ecfront.ez.framework.service.rpc.foundation.EZRPCContext
import com.ecfront.ez.framework.service.storage.foundation.EZStorageContext

import scala.beans.BeanProperty
import scala.language.implicitConversions

/**
  * RPC上下文,带权限信息
  */
class EZAuthContext extends EZRPCContext {
  // 请求token
  @BeanProperty var token: Option[String] = None
  // 登录信息
  @BeanProperty var loginInfo: Option[Token_Info_VO] = None

  override def toStorageContext: EZStorageContext = {
    if (loginInfo.isDefined) {
      EZStorageContext(loginInfo.get.login_id, loginInfo.get.organization_code)
    } else {
      EZStorageContext()
    }
  }

}

object EZAuthContext {

  implicit def toAuthContext(rpcContext: EZRPCContext): EZAuthContext = {
    val auth = new EZAuthContext()
    BeanHelper.copyProperties(auth, rpcContext)
    auth
  }

  implicit def toStorageContext(authContext: EZAuthContext): EZStorageContext = {
    if (authContext.loginInfo.isDefined) {
      val loginInfo = authContext.loginInfo.get
      EZStorageContext(loginInfo.login_id, loginInfo.organization_code)
    } else {
      EZStorageContext()
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy