在使用cas3的時候,往往有這樣的需求,希望每個應用有個獨立的登錄頁面
這塊cas 官方文檔有一些說明
https://wiki.jasig.org/display/CAS/Using+CAS+without+the+Login+Screen
首先從官方的角度,不建議使用多個登錄頁面,這樣對安全會形成短板。但是
用戶需求之上,如果我們要實現,有下面幾種方式
1.通過參數來判斷css來改變布局甚至一些圖片,典型cas里面的default-view中
casLoginView.jsp 里面就有這樣的描述,通過描述可以看出他通過不同css來區分
weblogin和mobilelogin。
比如片段
<c:if
test="${not empty requestScope['isMobile'] and not empty mobileCss}">
<meta name="viewport"
content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!--<link type="text/css" rel="stylesheet" media="screen" href="<c:url value="/css/fss-framework-1.1.2.css" />" />
<link type="text/css" rel="stylesheet" href="<c:url value="/css/fss-mobile-${requestScope['browserType']}-layout.css" />" />
<link type="text/css" rel="stylesheet" href="${mobileCss}" />-->
</c:if>
2.cas服務端(或者各種應用中)建立一個獨立的form頁面
參考:https://wiki.jasig.org/display/CAS/Using+CAS+from+external+link+or+custom+external+form
比如:
在cas(或者各種的應用頁面) web-inf/ 頁面添加testlogin.html
代碼:
<html>
<head />
<body>
<form method="GET" action="http://192.168.2.109:8080/cas/login">
<p>Username : <input type="text" name="username" /></p>
<p>Password : <input type="password" name="password" /></p>
<p>Remember me : <input type="checkbox" name="rememberMe" value="true" /></p>
<p><input type="submit" value="Login !" /></p>
<input type="hidden" name="auto" value="true" />
<input type="hidden" name="service" value="http://localhost/user/checklogintocas.php" />
</form>
</body>
</html>
casLoginView.jsp
實現自動提交功能:
...
<%@ page contentType="text/html; charset=UTF-8" %>
<%
String auto = request.getParameter("auto");
if (auto != null && auto.equals("true")) {
%>
<html>
<head>
<script language="javascript">
function doAutoLogin() {
document.forms[0].submit();
}
</script>
</head>
<body onload="doAutoLogin();">
<form id="credentials" method="POST" action="<%= request.getContextPath() %>/login?service=<%= request.getParameter("service") %>">
<input type="hidden" name="lt" value="${loginTicket}" />
<input type="hidden" name="execution" value="${flowExecutionKey}" />
<input type="hidden" name="_eventId" value="submit" />
<input type="hidden" name="username" value="<%= request.getParameter("username") %>" />
<input type="hidden" name="password" value="<%= request.getParameter("password") %>" />
<% if ("true".equals(request.getParameter("rememberMe"))) {%>
<input type="hidden" name="rememberMe" value="true" />
<% } %>
<input type="submit" value="Submit" style="visibility: hidden;" />
</form>
</body>
</html>
<%
} else {
%>
<jsp:directive.include file="includes/top.jsp" />
...
<jsp:directive.include file="includes/bottom.jsp" />
<%
}
%>
3.第三種方法 其實是第二種方法的啟發,直接把用if-else 把多個頁面組合在一起,通過參數來判斷顯示。(最好能可以支持多套casLoginView.jsp 不過研究下來好像比較難,也許cas開發者也是為了怕再次開放的人用太多靈活的多套casLoginView.jsp 頁面跳來跳去把項目搞混吧。)