CAS 整合/v1/tickets/{TGT id} 与/serviceValidate ,生成ST时直接验证其合法性。

来源:互联网 发布:通信网络维护简介 编辑:程序博客网 时间:2024/06/05 06:57

CAS 整合/v1/tickets/{TGT id} 与/serviceValidate ,生成ST时直接验证其合法性。

其目的是模拟客户端(C/S结构)调用服务器去验证TGT的合法性,省略调用/serviceValidate。

修改如下:


TicketGrantingTicketResource.java

成功后直接返回( true / false )

/* * Licensed to Jasig under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Jasig licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file * except in compliance with the License.  You may obtain a * copy of the License at the following location: * *   http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied.  See the License for the * specific language governing permissions and limitations * under the License. */package org.jasig.cas.integration.restlet;import javax.validation.constraints.NotNull;import org.jasig.cas.CentralAuthenticationService;import org.jasig.cas.authentication.principal.SimpleWebApplicationServiceImpl;import org.jasig.cas.ticket.InvalidTicketException;import org.jasig.cas.validation.Assertion;import org.jasig.cas.validation.Cas20ProtocolValidationSpecification;import org.jasig.cas.validation.ValidationSpecification;import org.jasig.cas.web.support.ArgumentExtractor;import org.restlet.Context;import org.restlet.Request;import org.restlet.Response;import org.restlet.data.Form;import org.restlet.data.MediaType;import org.restlet.data.Status;import org.restlet.representation.Representation;import org.restlet.representation.Variant;import org.restlet.resource.Delete;import org.restlet.resource.Post;import org.restlet.resource.ServerResource;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;/** * Implementation of a Restlet resource for creating Service Tickets from a * TicketGrantingTicket, as well as deleting a TicketGrantingTicket. * * @author Scott Battaglia * @since 3.3 * */public final class TicketGrantingTicketResource extends ServerResource {    private static final Logger LOGGER = LoggerFactory.getLogger(TicketGrantingTicketResource.class);    @Autowired    private CentralAuthenticationService centralAuthenticationService;    /** Extracts parameters from Request object. */    @NotNull    private ArgumentExtractor argumentExtractor;    @NotNull    private Class<?> validationSpecificationClass = Cas20ProtocolValidationSpecification.class;    private String ticketGrantingTicketId;    public void init(final Context context, final Request request, final Response response) {        super.init(context, request, response);        this.ticketGrantingTicketId = (String) request.getAttributes().get("ticketGrantingTicketId");        this.setNegotiated(false);        this.getVariants().add(new Variant(MediaType.APPLICATION_WWW_FORM));    }    @Delete    public void removeRepresentations() {        this.centralAuthenticationService.destroyTicketGrantingTicket(this.ticketGrantingTicketId);        getResponse().setStatus(Status.SUCCESS_OK);    }@Post    public void acceptRepresentation(final Representation entity) {        final Form form = new Form(entity);        final String serviceUrl = form.getFirstValue("service");        try {            final String serviceTicketId = this.centralAuthenticationService.grantServiceTicket(                    this.ticketGrantingTicketId,                    new SimpleWebApplicationServiceImpl(serviceUrl));            //Modify by lumz for validate Service Tickets 2016年4月6日15:09:41            String resultReturn = "false";            if (new SimpleWebApplicationServiceImpl(serviceUrl) == null || serviceTicketId == null) {            LOGGER.debug("Could not identify service and/or service ticket. Service: {}, Service ticket id: {}", new SimpleWebApplicationServiceImpl(serviceUrl), serviceTicketId);                return;            }            final Assertion assertion = centralAuthenticationService.validateServiceTicket(serviceTicketId, new SimpleWebApplicationServiceImpl(serviceUrl));            final ValidationSpecification validationSpecification = this.getCommandClass();            if (validationSpecification.isSatisfiedBy(assertion)) {            resultReturn = "ture";            }else{            resultReturn = "false";            }            getResponse().setEntity(resultReturn, MediaType.TEXT_PLAIN);//            getResponse().setEntity(serviceTicketId, MediaType.TEXT_PLAIN);        } catch (final InvalidTicketException e) {            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND, "TicketGrantingTicket could not be found.");        } catch (final Exception e) {            LOGGER.error(e.getMessage(), e);            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage());        }    }    private ValidationSpecification getCommandClass() {        try {            return (ValidationSpecification) this.validationSpecificationClass.newInstance();        } catch (final Exception e) {            throw new RuntimeException(e);        }    }}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 obb文件丢失了怎么办 dnf登录闪退怎么办 泰拉瑞亚地图找不到备份怎么办 服务器没远程管理卡怎么办 tplink上不了网怎么办 键盘端口坏了怎么办 小米路由dns错误怎么办 电脑内存性能低怎么办 nas硬盘坏了怎么办 360安装环境异常怎么办 连接不上服务器怎么办 路由器被绑定mac怎么办 mac地址绑定失败怎么办 触摸屏忘了密码怎么办? 小区高层水压低怎么办 高层楼房水压不够怎么办 热水器温度太高怎么办 热水器出热水小怎么办 天然气热水器水压不够怎么办 热水器水变小了怎么办 液压齿轮泵没力怎么办 gps总是浮点解怎么办 电源要做到稳压怎么办 变压器输出电压低怎么办 变压器输出电压高怎么办 家里空调带不动怎么办 小天才定位不准怎么办 伐木锯链条不出油怎么办 角磨机切割片卸不下来怎么办 油泵电机声音大怎么办 汽车油泵声音大怎么办 水泵电机噪音大怎么办 注塑机油泵超载怎么办 模具老是粘模怎么办 打印机提示卡纸2怎么办 扬子空调显示e9怎么办 供应商不配合售后怎么办? 数控车床显示屏不亮怎么办? 西威变频器过载怎么办 vgm申报错了怎么办 老公常年不回家怎么办