/*
 * Copyright 2005 The JA-SIG Collaborative. All rights reserved. See license
 * distributed with this file and available online at
 * http://www.uportal.org/license.html
 */
package org.jasig.cas.adaptors.x509.authentication.principal;

import java.security.cert.X509Certificate;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.cas.authentication.principal.Credentials;
import org.jasig.cas.authentication.principal.CredentialsToPrincipalResolver;
import org.jasig.cas.authentication.principal.Principal;

/**
 * Abstract class in support of multiple resolvers for X509 Certificates.
 * 
 * @author Scott Battaglia
 * @version $Revision$ $Date$
 * @since 3.0.4
 */
public abstract class AbstractX509CertificateCredentialsToPrincipalResolver
    implements CredentialsToPrincipalResolver {
    /** Log instance. */
    protected Log log = LogFactory.getLog(this.getClass());

    public final Principal resolvePrincipal(final Credentials credentials) {
        final Principal principal = resolvePrincipalInternal(((X509CertificateCredentials) credentials)
            .getCertificate());
        
        if (log.isInfoEnabled()) {
            log.info("Created Principal for: " + principal == null ? "No principal created." : principal.getId());
        }
        
        return principal;
    }

    public boolean supports(final Credentials credentials) {
        return credentials != null
            && X509CertificateCredentials.class.isAssignableFrom(credentials
                .getClass());
    }

    protected abstract Principal resolvePrincipalInternal(
        final X509Certificate certificate);
}

@@ -840,16 +840,17 @@
 olver %7B%0A
+%0A
     /** 
@@ -1180,24 +1180,64 @@
 nabled()) %7B%0A
+            if (principal !=null) %7B%0A    
             
@@ -1254,17 +1254,17 @@
 Created 
-P
+p
 rincipal
@@ -1286,19 +1286,65 @@
 ipal
- == null ? 
+.getId());%0A            %7D else %7B%0A                log.info(
 %22No 
@@ -1366,30 +1366,24 @@
 ed.%22
- : principal.getId());
+);%0A            %7D
 %0A   

fix for null pointer