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;
41  
42      /** the Dn of the subject that is present in the certificate*/
43      private String subjectDN;
44  
45      /** name of the algorithm used for generating the keys*/
46      private String keyAlgorithm;
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      @Override
83      public String getTargetDN()
84      {
85          return targetDN;
86      }
87  
88  
89      /**
90       * {@inheritDoc}
91       */
92      @Override
93      public void setTargetDN( String targetDN )
94      {
95          this.targetDN = targetDN;
96      }
97  
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public String getIssuerDN()
104     {
105         return issuerDN;
106     }
107 
108 
109     /**
110      * {@inheritDoc}
111      */
112     @Override
113     public void setIssuerDN( String issuerDN )
114     {
115         this.issuerDN = issuerDN;
116     }
117 
118 
119     /**
120      * {@inheritDoc}
121      */
122     @Override
123     public String getSubjectDN()
124     {
125         return subjectDN;
126     }
127 
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public void setSubjectDN( String subjectDN )
134     {
135         this.subjectDN = subjectDN;
136     }
137 
138 
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     public String getKeyAlgorithm()
144     {
145         return keyAlgorithm;
146     }
147 
148 
149     /**
150      * {@inheritDoc}
151      */
152     @Override
153     public void setKeyAlgorithm( String keyAlgorithm )
154     {
155         this.keyAlgorithm = keyAlgorithm;
156     }
157 
158 
159     @Override
160     public CertGenerationResponse getResultResponse()
161     {
162         if ( getResponse() == null )
163         {
164             setResponse( new CertGenerationResponseImpl() );
165         }
166 
167         return ( CertGenerationResponse ) getResponse();
168     }
169 
170 
171     @Override
172     public String toString()
173     {
174         StringBuilder sb = new StringBuilder();
175         sb.append( "Certficate Generation Object { " ).append( " Target Dn: " ).append( targetDN ).append( ',' );
176         sb.append( " Issuer Dn: " ).append( issuerDN ).append( ',' );
177         sb.append( " Subject Dn: " ).append( subjectDN ).append( ',' );
178         sb.append( " Key Algorithm: " ).append( keyAlgorithm ).append( " }" );
179 
180         return sb.toString();
181     }
182 }