001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.ldap.model.exception;
021
022
023import java.security.cert.CertPathValidatorException.BasicReason;
024import java.security.cert.CertPathValidatorException.Reason;
025
026
027public class LdapTlsHandshakeFailCause
028{
029    private Throwable cause;
030    private Throwable rootCause;
031    private Reason reason;
032    private String reasonPhrase;
033
034
035    public LdapTlsHandshakeFailCause()
036    {
037    }
038
039
040    public LdapTlsHandshakeFailCause( Throwable cause, Throwable rootCause, Reason reason, String reasonPhrase )
041    {
042        this.cause = cause;
043        this.rootCause = rootCause;
044        this.reason = reason;
045        this.reasonPhrase = reasonPhrase;
046    }
047
048
049    public Throwable getCause()
050    {
051        return cause;
052    }
053
054
055    public void setCause( Throwable cause )
056    {
057        this.cause = cause;
058    }
059
060
061    public Throwable getRootCause()
062    {
063        return rootCause;
064    }
065
066
067    public void setRootCause( Throwable rootCause )
068    {
069        this.rootCause = rootCause;
070    }
071
072
073    public Reason getReason()
074    {
075        return reason;
076    }
077
078
079    public void setReason( Reason reason )
080    {
081        this.reason = reason;
082    }
083
084
085    public String getReasonPhrase()
086    {
087        return reasonPhrase;
088    }
089
090
091    public void setReasonPhrase( String reasonPhrase )
092    {
093        this.reasonPhrase = reasonPhrase;
094    }
095
096    /**
097     * Additional reasons.
098     * 
099     * @see BasicReason
100     *
101     */
102    public enum LdapApiReason implements Reason
103    {
104        NO_VALID_CERTIFICATION_PATH,
105        SELF_SIGNED,
106        HOST_NAME_VERIFICATION_FAILED,
107    }
108
109
110    public String getMessage()
111    {
112        String message = reasonPhrase;
113        if ( rootCause != null && rootCause != cause )
114        {
115            message += ": " + rootCause.getMessage();
116        }
117        return message;
118    }
119
120}