1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.extras.extended.ads_impl.startTls;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory;
25 import org.apache.directory.api.ldap.codec.api.ExtendedResponseDecorator;
26 import org.apache.directory.api.ldap.codec.api.LdapApiService;
27 import org.apache.directory.api.ldap.extras.extended.startTls.StartTlsRequest;
28 import org.apache.directory.api.ldap.extras.extended.startTls.StartTlsRequestImpl;
29 import org.apache.directory.api.ldap.extras.extended.startTls.StartTlsResponse;
30 import org.apache.directory.api.ldap.extras.extended.startTls.StartTlsResponseImpl;
31 import org.apache.directory.api.ldap.model.message.ExtendedRequest;
32 import org.apache.directory.api.ldap.model.message.ExtendedResponse;
33
34
35
36
37
38
39
40
41 public class StartTlsFactory implements ExtendedOperationFactory
42 {
43 private LdapApiService codec;
44
45
46 public StartTlsFactory( LdapApiService codec )
47 {
48 this.codec = codec;
49 }
50
51
52
53
54
55 public String getOid()
56 {
57 return StartTlsRequest.EXTENSION_OID;
58 }
59
60
61
62
63
64 public StartTlsResponse newResponse( byte[] encodedValue ) throws DecoderException
65 {
66 StartTlsResponseDecorator response = new StartTlsResponseDecorator( codec,
67 new StartTlsResponseImpl() );
68 response.setResponseValue( encodedValue );
69 return response;
70 }
71
72
73
74
75
76 public StartTlsRequest newRequest( byte[] value )
77 {
78 StartTlsRequestDecorator req = new StartTlsRequestDecorator( codec, new StartTlsRequestImpl() );
79
80 if ( value != null )
81 {
82 req.setRequestValue( value );
83 }
84
85 return req;
86 }
87
88
89
90
91
92 public StartTlsRequestDecorator decorate( ExtendedRequest modelRequest )
93 {
94 if ( modelRequest instanceof StartTlsRequestDecorator )
95 {
96 return ( StartTlsRequestDecorator ) modelRequest;
97 }
98
99 return new StartTlsRequestDecorator( codec, ( StartTlsRequest ) modelRequest );
100 }
101
102
103
104
105
106 public StartTlsResponseDecorator decorate( ExtendedResponse decoratedResponse )
107 {
108 if ( decoratedResponse instanceof StartTlsResponseDecorator )
109 {
110 return ( StartTlsResponseDecorator ) decoratedResponse;
111 }
112
113 if ( decoratedResponse instanceof StartTlsResponse )
114 {
115 return new StartTlsResponseDecorator( codec, ( StartTlsResponse ) decoratedResponse );
116 }
117
118
119 @SuppressWarnings("unchecked")
120 ExtendedResponseDecorator<ExtendedResponse> response = ( ExtendedResponseDecorator<ExtendedResponse> ) decoratedResponse;
121
122
123 StartTlsResponse startTlsResponse = new StartTlsResponseImpl( response.getMessageId() );
124
125 startTlsResponse.getLdapResult().setResultCode( response.getLdapResult().getResultCode() );
126 startTlsResponse.getLdapResult().setDiagnosticMessage( response.getLdapResult().getDiagnosticMessage() );
127 StartTlsResponseDecorator decorated = new StartTlsResponseDecorator( codec, new StartTlsResponseImpl() );
128
129 return decorated;
130 }
131 }