Rest client authentication for CAS protected resource_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Rest client authentication for CAS protected resource

Rest client authentication for CAS protected resource

 2013/7/16 18:52:32  zyjbupt  程序员俱乐部  我要评论(0)
  • 摘要:三步搞定通过Restclient访问被CAS保护的资源:Step1:获取一个TicketgrantingticketfinalRestClientclient=newRestClient();StringticketGrantingTicket=null;finalStringtgtResponse=client.resource("https://yourcasserver/v1/tickets").accept(MediaType.TEXT_HTML).post
  • 标签:for client
三步搞定通过Rest client访问被CAS保护的资源:

Step 1: 获取一个Ticket granting ticket

    final RestClient client = new RestClient();
    String ticketGrantingTicket = null;
   
    final String tgtResponse = client
        .resource("https://yourcasserver/v1/tickets")
        .accept(MediaType.TEXT_HTML)
       .post("username=$username&password=$password")
        .getEntity(String.class);

    final Matcher matcher = Pattern.compile(".*action=\".*/(.*?)\".*").matcher(
        tgtResponse);

    if (matcher.matches())
    {
      ticketGrantingTicket = matcher.group(1);
    }


Step 2: 获取一个Service Ticket

    final String serviceTicket = client
        .resource(
            "https://yourcasserver/v1/tickets/" + ticketGrantingTicket)
        .accept(MediaType.TEXT_HTML)
        .post("service=$serviceUrl")
        .getEntity(String.class);


Step 3: 请求CAS protected resource

client.resource(RESOURCE_URL)
        .queryParam("ticket", serviceTicket).accept(MediaType.APPLICATION_XML)
        .get(xxx.class);
发表评论
用户名: 匿名