CAS Server 4.0二次开发说明文档(6)

2019-05-17 09:49

org.restlet.jee org.restlet.ext.slf4j 2.1.0 9.2. 修改webx.xml

在web.xml中添加如下配置

restlet org.restlet.ext.spring.RestletFrameworkServlet 1 restlet /v1/* 9.3. 请求票据授权

POST http://192.168.0.99:9000/cas/v1/tickets username=adminoue&password=4009696109

发送一个POST请求到/cas/v1/tickets,传递请求参数为username=adminoue&password=4009696109。请求成功后会返回http://192.168.0.99:9000/cas/v1/tickets/TGT-7-U71jox1ykWosLwQQSpcc5g47jdKul9ccgjgxgIchl64rSTpa1K-localhost。

其TGT-7-U71jox1ykWosLwQQSpcc5g47jdKul9ccgjgxgIchl64rSTpa1K-localhost为服务器端返回的请求票根。下文在请求服务的时候需携带该信息。

9.4. 请求服务授权

POST

http://192.168.0.99:9000/cas/v1/tickets/TGT-7-U71jox1ykWosLwQQSpcc5g47jdKul9ccgjgxgIchl64rSTpa1K-localhost service=http://www.aimeizi.net即可,最终返回一串ST-4-3V9Fs9PbbcUZ5PiIJaR6-localhost表示登录成功。

这里需要携带上文请求后返回的请求票据,请求该票据并传递service=你的应用地址最终返回登录成功后的票据信息。

9.5. Java Client测试

这里使用commons-httpclient来模拟上述中的请求流程。 import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import java.io.IOException; import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by Administrator on 2016/5/11 0011. */ public class Client { public static String getTicket(final String server, final String username, final String password, final String service) { notNull(server, \ notNull(username, \ notNull(password, \ notNull(service, \ return getServiceTicket(server, getTicketGrantingTicket(server, username, password), service); } /** * 取得ST * * @param server * @param ticketGrantingTicket * @param service */ private static String getServiceTicket(final String server, final String ticketGrantingTicket, final String service) { if (ticketGrantingTicket == null) return null; final HttpClient client = new HttpClient(); final PostMethod post = new PostMethod(server + \ post.setRequestBody(new NameValuePair[]{new NameValuePair(\ try { client.executeMethod(post); final String response = post.getResponseBodyAsString(); switch (post.getStatusCode()) { case 200: return response; default: warning(\server!\ info(\(1k): \+ response.substring(0, Math.min(1024, response.length()))); break; } } catch (final IOException e) { warning(e.getMessage()); } finally { post.releaseConnection(); } return null; } /** * @param server * @param username * @param password */ private static String getTicketGrantingTicket(final String server, final String username, final String password) { final HttpClient client = new HttpClient(); final PostMethod post = new PostMethod(server); post.setRequestBody(new NameValuePair[]{new NameValuePair(%username), new NameValuePair(\ try { client.executeMethod(post); final String response = post.getResponseBodyAsString(); info(\ switch (post.getStatusCode()) { case 201: { final Matcher matcher = Pattern.compile(\ if (matcher.matches()) return matcher.group(1); warning(\ info(\(1k): \+ response.substring(0, Math.min(1024, response.length()))); break; } default: warning(\server!\ info(\(1k): \+ response.substring(0, Math.min(1024, response.length()))); break; } } catch (final IOException e) { warning(e.getMessage()); } finally { post.releaseConnection();


CAS Server 4.0二次开发说明文档(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:国家安全网上法律知识竞赛参考答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: