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

org.beangle.security.realm.cas.CasConfig.scala Maven / Gradle / Ivy

There is a newer version: 4.3.21
Show newest version
/*
 * Copyright (C) 2005, The Beangle Software.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 */

package org.beangle.security.realm.cas

import jakarta.servlet.http.HttpServletRequest
import org.beangle.commons.bean.Initializing
import org.beangle.commons.lang.{Assert, Strings}
import org.beangle.web.servlet.util.RequestUtils

/** Cas 配置
 *
 * @see https://apereo.github.io/cas/4.2.x/protocol/CAS-Protocol-Specification.html
 */
object CasConfig {

  def getLocalServer(request: HttpServletRequest): String = {
    val sb = new StringBuilder()
    val scheme = if (RequestUtils.isHttps(request)) "https" else "http"
    val port = RequestUtils.getServerPort(request)
    val serverName = request.getServerName
    var includePort = true
    sb.append(scheme).append("://")
    includePort = port != (if (scheme == "http") 80 else 443)
    if (null != serverName) {
      sb.append(serverName)
      if (includePort && port > 0) sb.append(':').append(port)
    }
    sb.toString
  }

  val TicketName = "ticket"

  val ServiceName  = "service"
}

class CasConfig(server: String) extends Initializing {
  val casServer: String = Strings.stripEnd(server, "/")

  /** 目标cas是否是网关 */
  var gateway = false

  var loginUri = "/login"

  var logoutUri = "/logout"

  var validateUri = "/serviceValidate"

  var checkAliveUri = "/checkAlive"

  var localLoginUri: Option[String] = None

  def init(): Unit = {
    Assert.notEmpty(this.loginUri, "loginUri must be specified. like /login")
    if (gateway) {
      require(localLoginUri.nonEmpty, "local login uri required when gateway is true")
    }
  }

  /**
   * The enterprise-wide CAS login URL. Usually something like
   * https://www.mycompany.com/cas/login.
   */
  def loginUrl: String = casServer + loginUri

  def logoutUrl: String = casServer + logoutUri
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy