Cisco Cisco Prime Home 6.3 开发者指南

下载
页码 78
Cisco Prime Home – Integration Guide
 
 
OL-28557-01   v5.0.1
 
64 
AuthBridgeHttpRequestHandler.scala 
 
package com.clearaccess.example.auth 
 
import org.springframework.web.HttpRequestHandler 
import javax.servlet.http.{HttpServletResponse, HttpServletRequest} 
import com.clearaccess.example.api.ControlPanelSessionService 
import com.clearaccess.example.{HttpConfiguration, 
HttpServletSupport} 
import org.springframework.beans.factory.annotation.Autowired 
 
/** 
* This HTTP Request Handler (see spring's HttpRequestHandler and 
web.xml): 
* - takes a 'guid' string parameter 
* - maps the 'guid' into a device mac with the provided 'GuidMapper' 
* - transforms the mac into an oui/serial number (assumes the sn is 
= mac) 
* - makes an authenticated call to the session web service with the 
device info 
* - redirects the browser to the control panel with the oui:sn and 
session id 

* === caveats === 
* 1) GuidMapper must be implemented 
* 2) the mac address maps directly to the oui/sn of the device 
* 3) the control panel is located on the same host as the web 
service 
*/ 
// xml wired 
class AuthBridgeHttpRequestHandler @Autowired()( 
val controlPanelSessionService: ControlPanelSessionService, 
val httpConfiguration: HttpConfiguration, 
val guidMapper: GuidMapper 
) extends HttpRequestHandler 
with HttpServletSupport { 
def handleRequest(request: HttpServletRequest, 
response:HttpServletResponse): Unit = try { 
// get the mac request parameter 
val mac = getRequestParameter(request, "mac") getOrElse { 
// otherwise, get the guid request parameter 
// then call the guidMapper to convert the guid to a device mac 
getRequestParameter(request,"guid").map(guidMapper.guidToMAC)get
OrElse { 
throw new AssertionError("mac or guid required") 
 
// extract the oui and serial number 
val oui: String = macOUI(mac) 
val sn: String = macSN(mac) 
 
// call the acs to create a session 
val cpSession = controlPanelSessionService.createProxySession(oui, 
sn) 
 
// redirect the browser to the control panel, preauthenticated 
val returnUrl = java.net.URLEncoder.encode("http://google.com", 
"UTF-8") 
val jSessionCookiePath = java.net.URLEncoder.encode("/acsportal") 
val location = "http://%s/acs-
portal/controlpanel/login?device=%s:%s& 
cpSessionId=%s&styleVariant=pc&returnUrl=%s&jSessionCookiePath=%s"
.format( 
httpConfiguration.host,