Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.adaptors.ldap;
 
 import java.util.List;
 
 import  org.springframework.ldap.core.LdapTemplate;
 import  org.springframework.ldap.core.ContextSource;
 
Abstract class to handle common LDAP functionality.

Author(s):
Scott Battaglia
Version:
$Revision$ $Date$
Since:
3.0.3
 
 public abstract class AbstractLdapUsernamePasswordAuthenticationHandler extends
LdapTemplate to execute ldap queries.
 
     @NotNull
     private LdapTemplate ldapTemplate;
    
    
Instance of ContextSource
 
     @NotNull
     private ContextSource contextSource;

    
The filter path to the uid of the user.
 
     @NotNull
     private String filter;
    
    
List of error definitions and their types, based on which the user will be directed to a given view in the flow
 
     private List<LdapErrorDefinitionldapErrorDefinitions;
    
    
Whether the LdapTemplate should ignore partial results.
 
     private boolean ignorePartialResultException = false;

    
Method to set the datasource and generate a JdbcTemplate.

Parameters:
contextSource the datasource to use.
 
     public final void setContextSource(final ContextSource contextSource) {
         this. = contextSource;
     }
     
     public final void setIgnorePartialResultException(final boolean ignorePartialResultException) {
         this. = ignorePartialResultException;
     }
     
     public void setLdapErrorDefinitions(final List<LdapErrorDefinitionldapErrorDefs) {
         this. = ldapErrorDefs;
     }

    
Method to return the LdapTemplate

Returns:
a fully created LdapTemplate.
 
     protected final LdapTemplate getLdapTemplate() {
         return this.;
     }
 
     protected final ContextSource getContextSource() {
         return this.;
     }
 
     protected final String getFilter() {
         return this.;
     }
 
     public final void afterPropertiesSet() throws Exception {
         Assert.isTrue(this..contains("%u") || this..contains("%U"), "filter must contain %u or %U");
 
         if (this. == null) {
            this. = new LdapTemplate(this.);
        }
        this..setIgnorePartialResultException(this.);
    }

    
Available ONLY for subclasses that are doing special things with the ContextSource.

Parameters:
ldapTemplate the LDAPTemplate to use.
    protected final void setLdapTemplate(final LdapTemplate ldapTemplate) {
        this. = ldapTemplate;
    }
    protected void afterPropertiesSetInternal() throws Exception {
        // template method with nothing to do for sub classes.
    }

    

Parameters:
filter The filter to set.
    public final void setFilter(final String filter) {
        this. = filter;
    }
    
    
Available ONLY for subclasses that would want to customize how ldap error codes are handled

Parameters:
e The ldap exception that occurred.
Returns:
an instance of AuthenticationException
    protected AuthenticationException handleLdapError(final Exception e) {
        if (this. == null || this..size() == 0) {
            if (this..isDebugEnabled())
                this..debug("No error definitions are defined. Throwing error " + e.getMessage());
            return .;
        }
        if (this..isDebugEnabled())
            this..debug("Handling error: " + e.getMessage());
        for (final LdapErrorDefinition ldapErrorDef : this.)
            if (ldapErrorDef.matches(e.getMessage())) {
                if (this..isDebugEnabled())
                    this..debug("Found error type " + ldapErrorDef.getType() +  ". Throwing error for " + e.getMessage());
                return new LdapAuthenticationException(.e.getMessage(), ldapErrorDef.getType());
            }
        if (this..isDebugEnabled())
            this..debug("No error definition could be matched against the error. Throwing default error for " + e.getMessage());
    }
New to GrepCode? Check out our FAQ X