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.shared.ldap.extras.extended;
021
022
023import org.apache.directory.shared.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<CertGenerationResponse> implements CertGenerationRequest
034{
035    /** The serial version UUID */
036    private static final long serialVersionUID = 1L;
037
038    /** the Dn of the server entry which will be updated*/
039    private String targetDN;
040
041    /** the issuer Dn that will be set in the certificate*/
042    private String issuerDN;// = "CN=ApacheDS, OU=Directory, O=ASF, C=US";
043
044    /** the Dn of the subject that is present in the certificate*/
045    private String subjectDN;// = "CN=ApacheDS, OU=Directory, O=ASF, C=US";
046
047    /** name of the algorithm used for generating the keys*/
048    private String keyAlgorithm;// = "RSA";
049
050    
051    /**
052     * Creates a new instance of CertGenerationRequest.
053     *
054     * @param messageId the message id
055     * @param targerDN the Dn of target entry whose key and certificate values will be changed
056     * @param issuerDN Dn to be used as the issuer's Dn in the certificate
057     * @param subjectDN Dn to be used as certificate's subject
058     * @param keyAlgorithm crypto algorithm name to be used for generating the keys
059     */
060    public CertGenerationRequestImpl( int messageId, String targerDN, String issuerDN, String subjectDN, String keyAlgorithm )
061    {
062        super( messageId );
063        setRequestName( EXTENSION_OID );
064        this.targetDN = targerDN;
065        this.issuerDN = issuerDN;
066        this.subjectDN = subjectDN;
067        this.keyAlgorithm = keyAlgorithm;
068    }
069
070
071    /**
072     * Creates a new instance of CertGenerationRequest.
073     */
074    public CertGenerationRequestImpl()
075    {
076        setRequestName( EXTENSION_OID );
077    }
078
079
080    /**
081     * {@inheritDoc}
082     */
083    public String getTargetDN()
084    {
085        return targetDN;
086    }
087
088
089    /**
090     * {@inheritDoc}
091     */
092    public void setTargetDN( String targetDN )
093    {
094        this.targetDN = targetDN;
095    }
096
097
098    /**
099     * {@inheritDoc}
100     */
101    public String getIssuerDN()
102    {
103        return issuerDN;
104    }
105
106
107    /**
108     * {@inheritDoc}
109     */
110    public void setIssuerDN( String issuerDN )
111    {
112        this.issuerDN = issuerDN;
113    }
114
115
116    /**
117     * {@inheritDoc}
118     */
119    public String getSubjectDN()
120    {
121        return subjectDN;
122    }
123
124
125    /**
126     * {@inheritDoc}
127     */
128    public void setSubjectDN( String subjectDN )
129    {
130        this.subjectDN = subjectDN;
131    }
132
133
134    /**
135     * {@inheritDoc}
136     */
137    public String getKeyAlgorithm()
138    {
139        return keyAlgorithm;
140    }
141
142
143    /**
144     * {@inheritDoc}
145     */
146    public void setKeyAlgorithm( String keyAlgorithm )
147    {
148        this.keyAlgorithm = keyAlgorithm;
149    }
150
151
152    @Override
153    public CertGenerationResponse getResultResponse()
154    {
155        return new CertGenerationResponseImpl();
156    }
157    
158    
159    @Override
160    public String toString()
161    {
162        StringBuilder sb = new StringBuilder();
163        sb.append( "Certficate Generation Object { " ).append( " Target Dn: " ).append( targetDN ).append( ',' );
164        sb.append( " Issuer Dn: " ).append( issuerDN ).append( ',' );
165        sb.append( " Subject Dn: " ).append( subjectDN ).append( ',' );
166        sb.append( " Key Algorithm: " ).append( keyAlgorithm ).append( " }" );
167
168        return sb.toString();
169    }
170}