需求:對於不一樣的應用系統登陸界面也不同,可是cas服務端只有一個登陸界面,並且風格與客戶端的應用系統很不搭邊。此時咱們但願能夠使用客戶端的登陸界面(即外部界面)。下面給出一個官方的解決方案
https://wiki.jasig.org/display/CAS/Using+CAS+from+external+link+or+custom+external+formjavascript
修改cas-server.war中 ./WEB-INF\view\jsp\default\ui\casLoginView.jsp 內容以下:html
... <%@ 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" /> <% } %>
客戶端:java
訪問方式一,直接用url訪問,並提交相應的登陸參數: app
https://cas.example.com/cas/loginservice=http%3A%2F%2Fapp.example.com%2Fmyapp%2F&username=myuser&password=mypass&auto=truejsp
訪問方式二:ui
<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>
官網說明:url
https://wiki.jasig.org/display/CAS/Using+CAS+from+external+link+or+custom+external+formcode