org.jasig.cas.client.util.CommonUtils Java Examples

The following examples show how to use org.jasig.cas.client.util.CommonUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CasTicketValidatorUtils.java    From shiro-cas-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
protected static TicketValidator buildCas30TicketValidator(final ShiroCasProperties casProperties) {
      
      final boolean allowAnyProxy = casProperties.isAcceptAnyProxy();
final String allowedProxyChains = casProperties.getAllowedProxyChains();
final String casServerUrlPrefix = casProperties.getCasServerUrlPrefix();

final Class<? extends Cas20ServiceTicketValidator> ticketValidatorClass = StringUtils.hasText(casProperties.getTicketValidatorClass()) ? ReflectUtils.loadClass(casProperties.getTicketValidatorClass()) : null; 
final Cas20ServiceTicketValidator validator;

if (allowAnyProxy || CommonUtils.isNotBlank(allowedProxyChains)) {
	final Cas20ProxyTicketValidator v = createNewTicketValidator(ticketValidatorClass, casServerUrlPrefix, Cas30ProxyTicketValidator.class);
	v.setAcceptAnyProxy(allowAnyProxy);
	v.setAllowedProxyChains(CommonUtils.createProxyList(allowedProxyChains));
	validator = v;
} else {
	validator = createNewTicketValidator(ticketValidatorClass, casServerUrlPrefix, Cas30ServiceTicketValidator.class);
}
validator.setProxyCallbackUrl(casProperties.getProxyCallbackUrl());
validator.setProxyGrantingTicketStorage(proxyGrantingTicketStorage);

HttpURLConnectionFactory factory = new HttpsURLConnectionFactory( HttpsURLConnection.getDefaultHostnameVerifier(), getSSLConfig(casProperties));

validator.setURLConnectionFactory(factory);

validator.setProxyRetriever(new Cas20ProxyRetriever(casServerUrlPrefix, casProperties.getEncoding(), factory));
validator.setRenew(casProperties.isRenew());
validator.setEncoding(casProperties.getEncoding());

      return validator;
      
  }
 
Example #2
Source File: CasTicketValidatorUtils.java    From shiro-cas-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
protected static TicketValidator buildCas20TicketValidator(final ShiroCasProperties casProperties) {
      
      final boolean allowAnyProxy = casProperties.isAcceptAnyProxy();
final String allowedProxyChains = casProperties.getAllowedProxyChains();
final String casServerUrlPrefix = casProperties.getCasServerUrlPrefix();

final Class<? extends Cas20ServiceTicketValidator> ticketValidatorClass = StringUtils.hasText(casProperties.getTicketValidatorClass()) ? ReflectUtils.loadClass(casProperties.getTicketValidatorClass()) : null; 
final Cas20ServiceTicketValidator validator;

if (allowAnyProxy || CommonUtils.isNotBlank(allowedProxyChains)) {
	final Cas20ProxyTicketValidator v = createNewTicketValidator(ticketValidatorClass, casServerUrlPrefix, Cas20ProxyTicketValidator.class);
	v.setAcceptAnyProxy(allowAnyProxy);
	v.setAllowedProxyChains(CommonUtils.createProxyList(allowedProxyChains));
	validator = v;
} else {
	validator = createNewTicketValidator(ticketValidatorClass, casServerUrlPrefix, Cas20ServiceTicketValidator.class);
}
validator.setProxyCallbackUrl(casProperties.getProxyCallbackUrl());
validator.setProxyGrantingTicketStorage(proxyGrantingTicketStorage);

HttpURLConnectionFactory factory = new HttpsURLConnectionFactory( HttpsURLConnection.getDefaultHostnameVerifier(), getSSLConfig(casProperties));

validator.setURLConnectionFactory(factory);

validator.setProxyRetriever(new Cas20ProxyRetriever(casServerUrlPrefix, casProperties.getEncoding(), factory));
validator.setRenew(casProperties.isRenew());
validator.setEncoding(casProperties.getEncoding());

      return validator;
  }
 
Example #3
Source File: ShibcasAuthServlet.java    From shib-cas-authn3 with Apache License 2.0 5 votes vote down vote up
/**
 * Use the CAS CommonUtils to build the CAS Service URL.
 */
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response) {
    String serviceUrl = CommonUtils.constructServiceUrl(request, response, null, serverName,
        serviceParameterName, artifactParameterName, true);

    if ("embed".equalsIgnoreCase(entityIdLocation)) {
        serviceUrl += (new EntityIdParameterBuilder().getParameterString(request, false));
    }


    return serviceUrl;
}
 
Example #4
Source File: ShibcasAuthServlet.java    From shib-cas-authn3 with Apache License 2.0 5 votes vote down vote up
/**
 * Use the CAS CommonUtils to build the CAS Service URL.
 */
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response) {
    String serviceUrl = CommonUtils.constructServiceUrl(request, response, null, serverName,
        serviceParameterName, artifactParameterName, true);

    if ("embed".equalsIgnoreCase(entityIdLocation)) {
        serviceUrl += (new EntityIdParameterBuilder().getParameterString(request, false));
    }


    return serviceUrl;
}
 
Example #5
Source File: CasUrlUtils.java    From shiro-cas-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
public static String constructLogoutRedirectUrl(CasClientProperties casProperties, String contextPath, String serverUrl){
	String callbackUrl = CasUrlUtils.constructCallbackUrl(casProperties, contextPath, serverUrl);
	return CommonUtils.constructRedirectUrl(casProperties.getCasServerLogoutUrl(), casProperties.getServiceParameterName(), callbackUrl, casProperties.isRenew(), casProperties.isGateway());
}
 
Example #6
Source File: CasUrlUtils.java    From shiro-cas-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
public static String constructLoginRedirectUrl(CasClientProperties casProperties, String contextPath, String serverUrl){
	String callbackUrl = CasUrlUtils.constructCallbackUrl(casProperties, contextPath, serverUrl);
	return CommonUtils.constructRedirectUrl(casProperties.getCasServerLoginUrl(), casProperties.getServiceParameterName(), callbackUrl, casProperties.isRenew(), casProperties.isGateway());
}
 
Example #7
Source File: ShibcasAuthServlet.java    From shib-cas-authn3 with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the CAS CommonUtils to build the CAS Redirect URL.
 */
private String constructRedirectUrl(final String serviceUrl, final boolean renew, final boolean gateway) {
    return CommonUtils.constructRedirectUrl(casLoginUrl, "service", serviceUrl, renew, gateway, null);
}
 
Example #8
Source File: SakaiCasAuthenticationFilter.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void init() {
    super.init();
    CommonUtils.assertNotNull(this.casServerLoginUrl, "casServerLoginUrl cannot be null.");
}
 
Example #9
Source File: SakaiCasAuthenticationFilter.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    
    if (isRequestUrlExcluded(request)) {
        log.debug("Request is ignored.");
        filterChain.doFilter(request, response);
        return;
    }
    
    final HttpSession session = request.getSession(false);
    final Assertion assertion = session != null ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : null;

    if (assertion != null && loggedOutOfSakai()) {
        log.debug("found a CAS assertion and we are logged out of Sakai. Invalidating the session so we don't get logged back on by an old assertion.");
        session.invalidate();
    }  else if (assertion != null) {
        filterChain.doFilter(request, response);
        return;
    }

    final String serviceUrl = constructServiceUrl(request, response);
    final String ticket = retrieveTicketFromRequest(request);
    final boolean wasGatewayed = this.gateway && this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);

    if (CommonUtils.isNotBlank(ticket) || wasGatewayed) {
        filterChain.doFilter(request, response);
        return;
    }

    final String modifiedServiceUrl;

    log.debug("no ticket and no assertion found");
    if (this.gateway) {
        log.debug("setting gateway attribute in session");
        modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);
    } else {
        modifiedServiceUrl = serviceUrl;
    }

    if (log.isDebugEnabled()) {
    	log.debug("Constructed service url: {}", modifiedServiceUrl);
    }

    final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getProtocol().getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);

    if (log.isDebugEnabled()) {
    	log.debug("redirecting to \"{}\"", urlToRedirectTo);
    }
    this.authenticationRedirectStrategy.redirect(request, response, urlToRedirectTo);
}
 
Example #10
Source File: ShibcasAuthServlet.java    From shib-cas-authn3 with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the CAS CommonUtils to build the CAS Redirect URL.
 */
private String constructRedirectUrl(final String serviceUrl, final boolean renew, final boolean gateway) {
    return CommonUtils.constructRedirectUrl(casLoginUrl, "service", serviceUrl, renew, gateway, null);
}
 
Example #11
Source File: SakaiCasAuthenticationFilter.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void init() {
    super.init();
    CommonUtils.assertNotNull(this.casServerLoginUrl, "casServerLoginUrl cannot be null.");
}
 
Example #12
Source File: SakaiCasAuthenticationFilter.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    
    if (isRequestUrlExcluded(request)) {
        log.debug("Request is ignored.");
        filterChain.doFilter(request, response);
        return;
    }
    
    final HttpSession session = request.getSession(false);
    final Assertion assertion = session != null ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : null;

    if (assertion != null && loggedOutOfSakai()) {
        log.debug("found a CAS assertion and we are logged out of Sakai. Invalidating the session so we don't get logged back on by an old assertion.");
        session.invalidate();
    }  else if (assertion != null) {
        filterChain.doFilter(request, response);
        return;
    }

    final String serviceUrl = constructServiceUrl(request, response);
    final String ticket = retrieveTicketFromRequest(request);
    final boolean wasGatewayed = this.gateway && this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);

    if (CommonUtils.isNotBlank(ticket) || wasGatewayed) {
        filterChain.doFilter(request, response);
        return;
    }

    final String modifiedServiceUrl;

    log.debug("no ticket and no assertion found");
    if (this.gateway) {
        log.debug("setting gateway attribute in session");
        modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);
    } else {
        modifiedServiceUrl = serviceUrl;
    }

    if (log.isDebugEnabled()) {
    	log.debug("Constructed service url: {}", modifiedServiceUrl);
    }

    final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getProtocol().getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);

    if (log.isDebugEnabled()) {
    	log.debug("redirecting to \"{}\"", urlToRedirectTo);
    }
    this.authenticationRedirectStrategy.redirect(request, response, urlToRedirectTo);
}
 
Example #13
Source File: CasUrlUtils.java    From shiro-cas-spring-boot-starter with Apache License 2.0 3 votes vote down vote up
public static String constructRedirectUrl(CasClientProperties casProperties, String casServerPath, String contextPath, String serverUrl)  {

		StringBuilder casRedirectUrl = new StringBuilder(casProperties.getCasServerUrlPrefix());
		if (!casRedirectUrl.toString().endsWith("/")) {
			casRedirectUrl.append("/");
		}
		casRedirectUrl.append(casServerPath);
		
		String callbackUrl = CasUrlUtils.constructCallbackUrl(casProperties, contextPath, serverUrl);
		
		return CommonUtils.constructRedirectUrl(casRedirectUrl.toString(), casProperties.getServiceParameterName(), callbackUrl, casProperties.isRenew(), casProperties.isGateway());
		
	}
 
Example #14
Source File: CasUrlUtils.java    From shiro-cas-spring-boot-starter with Apache License 2.0 3 votes vote down vote up
public static String constructServiceUrl(ServletRequest request, ServletResponse response, CasClientProperties casProperties) {
	
	return CommonUtils.constructServiceUrl(WebUtils.toHttp(request), WebUtils.toHttp(response), casProperties.getServerName(),
			casProperties.getServerName(), casProperties.getServiceParameterName(),
			casProperties.getArtifactParameterName(), casProperties.isEncodeServiceUrl());
	
}
 
Example #15
Source File: ShibcasAuthServlet.java    From shib-cas-authn3 with Apache License 2.0 2 votes vote down vote up
/**
 * Like the above, but with a flag indicating whether we're validating a service ticket,
 * in which case we should not modify the service URL returned by CAS CommonUtils; this
 * avoids appending the entity ID twice when entityIdLocation=embed, since the ID is already
 * embedded in the string during validation.
 */
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final boolean isValidatingTicket) {
    return isValidatingTicket
        ? CommonUtils.constructServiceUrl(request, response, null, serverName, serviceParameterName, artifactParameterName, true)
        : constructServiceUrl(request, response);
}
 
Example #16
Source File: ShibcasAuthServlet.java    From shib-cas-authn3 with Apache License 2.0 2 votes vote down vote up
/**
 * Like the above, but with a flag indicating whether we're validating a service ticket,
 * in which case we should not modify the service URL returned by CAS CommonUtils; this
 * avoids appending the entity ID twice when entityIdLocation=embed, since the ID is already
 * embedded in the string during validation.
 */
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final boolean isValidatingTicket) {
    return isValidatingTicket
        ? CommonUtils.constructServiceUrl(request, response, null, serverName, serviceParameterName, artifactParameterName, true)
        : constructServiceUrl(request, response);
}