需求:对于不一样的应用系统登陆界面也不同,可是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