View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.extras.extended.certGeneration;
21  
22  
23  import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest;
24  
25  
26  /**
27   * 
28   * An extended operation requesting the server to generate a public/private key pair and a certificate
29   * and store them in a specified target entry in the DIT.
30   *
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class CertGenerationRequestImpl extends AbstractExtendedRequest implements
34      CertGenerationRequest
35  {
36      /** the Dn of the server entry which will be updated*/
37      private String targetDN;
38  
39      /** the issuer Dn that will be set in the certificate*/
40      private String issuerDN;// = "CN=ApacheDS, OU=Directory, O=ASF, C=US";
41  
42      /** the Dn of the subject that is present in the certificate*/
43      private String subjectDN;// = "CN=ApacheDS, OU=Directory, O=ASF, C=US";
44  
45      /** name of the algorithm used for generating the keys*/
46      private String keyAlgorithm;// = "RSA";
47  
48  
49      /**
50       * Creates a new instance of CertGenerationRequest.
51       *
52       * @param messageId the message id
53       * @param targerDN the Dn of target entry whose key and certificate values will be changed
54       * @param issuerDN Dn to be used as the issuer's Dn in the certificate
55       * @param subjectDN Dn to be used as certificate's subject
56       * @param keyAlgorithm crypto algorithm name to be used for generating the keys
57       */
58      public CertGenerationRequestImpl( int messageId, String targerDN, String issuerDN, String subjectDN,
59          String keyAlgorithm )
60      {
61          super( messageId );
62          setRequestName( EXTENSION_OID );
63          this.targetDN = targerDN;
64          this.issuerDN = issuerDN;
65          this.subjectDN = subjectDN;
66          this.keyAlgorithm = keyAlgorithm;
67      }
68  
69  
70      /**
71       * Creates a new instance of CertGenerationRequest.
72       */
73      public CertGenerationRequestImpl()
74      {
75          setRequestName( EXTENSION_OID );
76      }
77  
78  
79      /**
80       * {@inheritDoc}
81       */
82      public String getTargetDN()
83      {
84          return targetDN;
85      }
86  
87  
88      /**
89       * {@inheritDoc}
90       */
91      public void setTargetDN( String targetDN )
92      {
93          this.targetDN = targetDN;
94      }
95  
96  
97      /**
98       * {@inheritDoc}
99       */
100     public String getIssuerDN()
101     {
102         return issuerDN;
103     }
104 
105 
106     /**
107      * {@inheritDoc}
108      */
109     public void setIssuerDN( String issuerDN )
110     {
111         this.issuerDN = issuerDN;
112     }
113 
114 
115     /**
116      * {@inheritDoc}
117      */
118     public String getSubjectDN()
119     {
120         return subjectDN;
121     }
122 
123 
124     /**
125      * {@inheritDoc}
126      */
127     public void setSubjectDN( String subjectDN )
128     {
129         this.subjectDN = subjectDN;
130     }
131 
132 
133     /**
134      * {@inheritDoc}
135      */
136     public String getKeyAlgorithm()
137     {
138         return keyAlgorithm;
139     }
140 
141 
142     /**
143      * {@inheritDoc}
144      */
145     public void setKeyAlgorithm( String keyAlgorithm )
146     {
147         this.keyAlgorithm = keyAlgorithm;
148     }
149 
150 
151     @Override
152     public CertGenerationResponse getResultResponse()
153     {
154         return new CertGenerationResponseImpl();
155     }
156 
157 
158     @Override
159     public String toString()
160     {
161         StringBuilder sb = new StringBuilder();
162         sb.append( "Certficate Generation Object { " ).append( " Target Dn: " ).append( targetDN ).append( ',' );
163         sb.append( " Issuer Dn: " ).append( issuerDN ).append( ',' );
164         sb.append( " Subject Dn: " ).append( subjectDN ).append( ',' );
165         sb.append( " Key Algorithm: " ).append( keyAlgorithm ).append( " }" );
166 
167         return sb.toString();
168     }
169 }