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 *    https://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.extras.extended.certGeneration;
021
022
023import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest;
024
025
026/**
027 * 
028 * An extended operation requesting the server to generate a public/private key pair and a certificate
029 * and store them in a specified target entry in the DIT.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 */
033public class CertGenerationRequestImpl extends AbstractExtendedRequest implements CertGenerationRequest
034{
035    /** the Dn of the server entry which will be updated*/
036    private String targetDN;
037
038    /** the issuer Dn that will be set in the certificate*/
039    private String issuerDN;
040
041    /** the Dn of the subject that is present in the certificate*/
042    private String subjectDN;
043
044    /** name of the algorithm used for generating the keys*/
045    private String keyAlgorithm;
046
047
048    /**
049     * Creates a new instance of CertGenerationRequest.
050     *
051     * @param messageId the message id
052     * @param targerDN the Dn of target entry whose key and certificate values will be changed
053     * @param issuerDN Dn to be used as the issuer's Dn in the certificate
054     * @param subjectDN Dn to be used as certificate's subject
055     * @param keyAlgorithm crypto algorithm name to be used for generating the keys
056     */
057    public CertGenerationRequestImpl( int messageId, String targerDN, String issuerDN, String subjectDN,
058        String keyAlgorithm )
059    {
060        super( messageId );
061        setRequestName( EXTENSION_OID );
062        this.targetDN = targerDN;
063        this.issuerDN = issuerDN;
064        this.subjectDN = subjectDN;
065        this.keyAlgorithm = keyAlgorithm;
066    }
067
068
069    /**
070     * Creates a new instance of CertGenerationRequest.
071     */
072    public CertGenerationRequestImpl()
073    {
074        setRequestName( EXTENSION_OID );
075    }
076
077
078    /**
079     * {@inheritDoc}
080     */
081    @Override
082    public String getTargetDN()
083    {
084        return targetDN;
085    }
086
087
088    /**
089     * {@inheritDoc}
090     */
091    @Override
092    public void setTargetDN( String targetDN )
093    {
094        this.targetDN = targetDN;
095    }
096
097
098    /**
099     * {@inheritDoc}
100     */
101    @Override
102    public String getIssuerDN()
103    {
104        return issuerDN;
105    }
106
107
108    /**
109     * {@inheritDoc}
110     */
111    @Override
112    public void setIssuerDN( String issuerDN )
113    {
114        this.issuerDN = issuerDN;
115    }
116
117
118    /**
119     * {@inheritDoc}
120     */
121    @Override
122    public String getSubjectDN()
123    {
124        return subjectDN;
125    }
126
127
128    /**
129     * {@inheritDoc}
130     */
131    @Override
132    public void setSubjectDN( String subjectDN )
133    {
134        this.subjectDN = subjectDN;
135    }
136
137
138    /**
139     * {@inheritDoc}
140     */
141    @Override
142    public String getKeyAlgorithm()
143    {
144        return keyAlgorithm;
145    }
146
147
148    /**
149     * {@inheritDoc}
150     */
151    @Override
152    public void setKeyAlgorithm( String keyAlgorithm )
153    {
154        this.keyAlgorithm = keyAlgorithm;
155    }
156
157
158    /**
159     * {@inheritDoc}
160     */
161    @Override
162    public CertGenerationResponse getResultResponse()
163    {
164        if ( getResponse() == null )
165        {
166            setResponse( new CertGenerationResponseImpl() );
167        }
168
169        return ( CertGenerationResponse ) getResponse();
170    }
171
172
173    /***
174     * {@inheritDoc}
175     */
176    @Override
177    public String toString()
178    {
179        StringBuilder sb = new StringBuilder();
180        sb.append( "Certficate Generation Object { " ).append( " Target Dn: " ).append( targetDN ).append( ',' );
181        sb.append( " Issuer Dn: " ).append( issuerDN ).append( ',' );
182        sb.append( " Subject Dn: " ).append( subjectDN ).append( ',' );
183        sb.append( " Key Algorithm: " ).append( keyAlgorithm ).append( " }" );
184
185        return sb.toString();
186    }
187}