需求:对于不同的应用系统登录界面也不一样,但是cas服务端只有一个登录界面,而且风格与客户端的应用系统很不搭边。此时我们希望可以使用客户端的登录界面(即外部界面)。下面给出一个官方的解决方案
https://wiki.jasig.org/display/CAS/Using+CAS+from+external+link+or+custom+external+form
修改cas-server.war中 ./WEB-INF\view\jsp\default\ui\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" />
<%
}
%>
客户端:
访问方式一,直接用url访问,并提交相应的登录参数:
https://cas.example.com/cas/loginservice=http%3A%2F%2Fapp.example.com%2Fmyapp%2F&username=myuser&password=mypass&auto=true
访问方式二:
<html>
<head />
<body>
<form method="GET" action="https://cas.example.com/cas/">
<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://app.example.com/myapp/" />
</form>
</body>
</html>
官网说明:
https://wiki.jasig.org/display/CAS/Using+CAS+from+external+link+or+custom+external+form