本文整理汇总了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);
}
示例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);
}