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
47
48
49
50
51 public StartTlsFactory( LdapApiService codec )
52 {
53 this.codec = codec;
54 }
55
56
57
58
59
60 @Override
61 public String getOid()
62 {
63 return StartTlsRequest.EXTENSION_OID;
64 }
65
66
67
68
69
70 @Override
71 public StartTlsResponse newResponse( byte[] encodedValue ) throws DecoderException
72 {
73 StartTlsResponseDecorator response = new StartTlsResponseDecorator( codec,
74 new StartTlsResponseImpl() );
75 response.setResponseValue( encodedValue );
76 return response;
77 }
78
79
80
81
82
83 @Override
84 public StartTlsRequest newRequest( byte[] value )
85 {
86 StartTlsRequestDecorator req = new StartTlsRequestDecorator( codec, new StartTlsRequestImpl() );
87
88 if ( value != null )
89 {
90 req.setRequestValue( value );
91 }
92
93 return req;
94 }
95
96
97
98
99
100 @Override
101 public StartTlsRequestDecorator decorate( ExtendedRequest modelRequest )
102 {
103 if ( modelRequest instanceof StartTlsRequestDecorator )
104 {
105 return ( StartTlsRequestDecorator ) modelRequest;
106 }
107
108 return new StartTlsRequestDecorator( codec, ( StartTlsRequest ) modelRequest );
109 }
110
111
112
113
114
115 @Override
116 public StartTlsResponseDecorator decorate( ExtendedResponse decoratedResponse )
117 {
118 if ( decoratedResponse instanceof StartTlsResponseDecorator )
119 {
120 return ( StartTlsResponseDecorator ) decoratedResponse;
121 }
122
123 if ( decoratedResponse instanceof StartTlsResponse )
124 {
125 return new StartTlsResponseDecorator( codec, ( StartTlsResponse ) decoratedResponse );
126 }
127
128
129 @SuppressWarnings("unchecked")
130 ExtendedResponseDecorator<ExtendedResponse> response = ( ExtendedResponseDecorator<ExtendedResponse> ) decoratedResponse;
131
132
133 StartTlsResponse startTlsResponse = new StartTlsResponseImpl( response.getMessageId() );
134
135 startTlsResponse.getLdapResult().setResultCode( response.getLdapResult().getResultCode() );
136 startTlsResponse.getLdapResult().setDiagnosticMessage( response.getLdapResult().getDiagnosticMessage() );
137 return new StartTlsResponseDecorator( codec, new StartTlsResponseImpl() );
138 }
139 }