Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF 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
   *
  *     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.apache.shiro.cas;
 
 
This filter validates the CAS service ticket to authenticate the user. It must be configured on the URL recognized by the CAS server. For example, in shiro.ini:
 [main]
 casFilter = org.apache.shiro.cas.CasFilter
 ...

 [urls]
 /shiro-cas = casFilter
 ...
 
(example : http://host:port/mycontextpath/shiro-cas)

Since:
1.2
 
 public class CasFilter extends AuthenticatingFilter {
     
     private static Logger logger = LoggerFactory.getLogger(CasFilter.class);
     
     // the name of the parameter service ticket in url
     private static final String TICKET_PARAMETER = "ticket";
     
     // the url where the application is redirected if the CAS service ticket validation failed (example : /mycontextpatch/cas_error.jsp)
     private String failureUrl;
    
    
The token created for this authentication is a CasToken containing the CAS service ticket received on the CAS service url (on which the filter must be configured).

Parameters:
request the incoming request
response the outgoing response
Throws:
java.lang.Exception if there is an error processing the request.
 
     @Override
     protected AuthenticationToken createToken(ServletRequest requestServletResponse responsethrows Exception {
         HttpServletRequest httpRequest = (HttpServletRequestrequest;
         String ticket = httpRequest.getParameter();
         return new CasToken(ticket);
     }
    
    
Execute login by creating token and logging subject with this token.

Parameters:
request the incoming request
response the outgoing response
Throws:
java.lang.Exception if there is an error processing the request.
 
     @Override
     protected boolean onAccessDenied(ServletRequest requestServletResponse responsethrows Exception {
         return executeLogin(requestresponse);
     }
    
    
Returns false to always force authentication (user is never considered authenticated by this filter).

Parameters:
request the incoming request
response the outgoing response
mappedValue the filter-specific config value mapped to this filter in the URL rules mappings.
Returns:
false
 
     @Override
     protected boolean isAccessAllowed(ServletRequest requestServletResponse responseObject mappedValue) {
         return false;
     }
    
    
If login has been successful, redirect user to the original protected url.

Parameters:
token the token representing the current authentication
subject the current authenticated subjet
request the incoming request
response the outgoing response
Throws:
java.lang.Exception if there is an error processing the request.
    @Override
    protected boolean onLoginSuccess(AuthenticationToken tokenSubject subjectServletRequest request,
                                     ServletResponse responsethrows Exception {
        issueSuccessRedirect(requestresponse);
        return false;
    }
    
    
If login has failed, redirect user to the CAS error page (no ticket or ticket validation failed) except if the user is already authenticated, in which case redirect to the default success url.

Parameters:
token the token representing the current authentication
ae the current authentication exception
request the incoming request
response the outgoing response
    @Override
    protected boolean onLoginFailure(AuthenticationToken tokenAuthenticationException aeServletRequest request,
                                     ServletResponse response) {
        // is user authenticated or in remember me mode ?
        Subject subject = getSubject(requestresponse);
        if (subject.isAuthenticated() || subject.isRemembered()) {
            try {
                issueSuccessRedirect(requestresponse);
            } catch (Exception e) {
                .error("Cannot redirect to the default success url"e);
            }
        } else {
            try {
                WebUtils.issueRedirect(requestresponse);
            } catch (IOException e) {
                .error("Cannot redirect to failure url : {}"e);
            }
        }
        return false;
    }
    
    public void setFailureUrl(String failureUrl) {
        this. = failureUrl;
    }
New to GrepCode? Check out our FAQ X