当前位置: 首页>>代码示例>>Java>>正文


Java Cas20ServiceTicketValidator.validate方法代码示例

本文整理汇总了Java中org.jasig.cas.client.validation.Cas20ServiceTicketValidator.validate方法的典型用法代码示例。如果您正苦于以下问题:Java Cas20ServiceTicketValidator.validate方法的具体用法?Java Cas20ServiceTicketValidator.validate怎么用?Java Cas20ServiceTicketValidator.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jasig.cas.client.validation.Cas20ServiceTicketValidator的用法示例。


在下文中一共展示了Cas20ServiceTicketValidator.validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: searchExperiment

import org.jasig.cas.client.validation.Cas20ServiceTicketValidator; //导入方法依赖的package包/类
public void searchExperiment() throws ServerConnectionException, FailedLoginException,
        ClientProtocolException, IOException {
    SearchExperimentsByCriteria experimentSearchCriteria = new SearchExperimentsByCriteria();
    CaArrayServer server = new CaArrayServer(BaseProperties.getServerHostname(),
            BaseProperties.getServerJndiPort());
    server.connect();
    /*
     * Verify anonymous search does not return results.
     */
    experimentSearchCriteria.doSearch(server);

    // Emulate a login from caIntegrator through CAS
    String ticket = login();
    
    /*
     * Validate the ticket.
     */
    try {
        Cas20ServiceTicketValidator v = new Cas20ServiceTicketValidator(BaseProperties.CAS_URL);
        v.validate(ticket, BaseProperties.getServiceURLforCAS());
    } catch (Exception e) {
        System.out.println(e);
    }

    /*
     * To properly authenticate users with CAS information for EJB calls the caArray application requires 2 pieces of information:
     * + The service value that was used at authentication time when the ticket was created
     * + The ticket value that was provided by CAS
     */
    server.connect(BaseProperties.getServiceURLforCAS(), ticket);
    experimentSearchCriteria.doSearch(server);

    /*
     * This shows that in addition to being able to authenticate with CAS the application also provides
     * the capability to authenticate against ldap in an SSO environment.
     */
    server.connect(BaseProperties.CAS_USERNAME, BaseProperties.CAS_USER_CAARRAY_PASSWORD);
    experimentSearchCriteria.doSearch(server);
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:40,代码来源:CASRemoteEJBClient.java

示例2: doFilter

import org.jasig.cas.client.validation.Cas20ServiceTicketValidator; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
        final FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    HttpSession session = request.getSession();
    final String ticket = CommonUtils.safeGetParameter(request, getArtifactParameterName());

    if (session != null && session.getAttribute(CONST_CAS_ASSERTION) == null && ticket != null) {
        try {
            final String service = constructServiceUrl(request, response);
            Cas20ServiceTicketValidator v = new Cas20ServiceTicketValidator(casServerUrl);
            v.validate(ticket, service);
            if (!new WebAuthentication().login(service, ticket)) {
                throw new GeneralSecurityException("JBoss Web authentication failed.");
            }
            /*
             * This line of obtaining the session again was necessary as following the login with
             * the WebAuthentication above, the original Session that was obtained was no longer
             * valid.
             */
            session = request.getSession();
            if (request.getUserPrincipal() instanceof AssertionPrincipal) {
                final AssertionPrincipal principal = (AssertionPrincipal) request.getUserPrincipal();
                session.setAttribute(CONST_CAS_ASSERTION, principal.getAssertion());
            } else {
                throw new GeneralSecurityException(
                        "JBoss Web authentication did not produce CAS AssertionPrincipal.");
            }
        } catch (final GeneralSecurityException e) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());
        } catch (TicketValidationException tve) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, tve.getMessage());
        }
    } else if (session != null && request.getUserPrincipal() == null) {
        // There is evidence that in some cases the principal can disappear
        // in JBoss despite a valid session.
        // This block forces consistency between principal and assertion.
        session.removeAttribute(CONST_CAS_ASSERTION);
    }
    chain.doFilter(request, response);
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:46,代码来源:CasWebAuthenticationFilter.java


注:本文中的org.jasig.cas.client.validation.Cas20ServiceTicketValidator.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。