8
8
package io .lighty .aaa ;
9
9
10
10
import io .lighty .aaa .config .AAAConfiguration ;
11
- import io .lighty .server .LightyServerBuilder ;
11
+ import io .lighty .server .LightyJettyServerProvider ;
12
12
import java .util .ArrayList ;
13
13
import java .util .HashMap ;
14
14
import java .util .List ;
15
15
import java .util .Map ;
16
16
import java .util .concurrent .CompletableFuture ;
17
17
import org .eclipse .jetty .server .Handler ;
18
- import org .eclipse .jetty .server .handler .ContextHandlerCollection ;
19
- import org .eclipse .jetty .servlet .FilterHolder ;
20
- import org .eclipse .jetty .servlet .ServletContextHandler ;
21
- import org .eclipse .jetty .servlet .ServletHolder ;
22
18
import org .eclipse .jetty .servlets .CrossOriginFilter ;
23
19
import org .glassfish .jersey .internal .guava .Preconditions ;
24
- import org .glassfish .jersey .server .ResourceConfig ;
25
- import org .glassfish .jersey .servlet .ServletContainer ;
26
20
import org .opendaylight .aaa .api .AuthenticationService ;
27
21
import org .opendaylight .aaa .api .ClaimCache ;
28
22
import org .opendaylight .aaa .api .CredentialAuth ;
47
41
import org .opendaylight .aaa .tokenauthrealm .auth .AuthenticationManager ;
48
42
import org .opendaylight .aaa .tokenauthrealm .auth .HttpBasicAuth ;
49
43
import org .opendaylight .aaa .tokenauthrealm .auth .TokenAuthenticators ;
44
+ import org .opendaylight .aaa .web .FilterDetails ;
45
+ import org .opendaylight .aaa .web .ServletDetails ;
46
+ import org .opendaylight .aaa .web .WebContext ;
50
47
import org .opendaylight .aaa .web .servlet .jersey2 .JerseyServletSupport ;
51
48
import org .opendaylight .mdsal .binding .api .DataBroker ;
52
49
import org .opendaylight .yang .gen .v1 .urn .opendaylight .aaa .app .config .rev170619 .DatastoreConfig ;
@@ -79,7 +76,7 @@ public final class AAALightyShiroProvider {
79
76
private AAALightyShiroProvider (final DataBroker dataBroker ,
80
77
final AAAConfiguration aaaConfiguration ,
81
78
final CredentialAuth <PasswordCredentials > credentialAuth ,
82
- final LightyServerBuilder server ) {
79
+ final LightyJettyServerProvider server ) {
83
80
this .dataBroker = dataBroker ;
84
81
this .certificateManager = aaaConfiguration .getCertificateManager ();
85
82
this .credentialAuth = credentialAuth ;
@@ -127,18 +124,7 @@ private AAALightyShiroProvider(final DataBroker dataBroker,
127
124
initAAAonServer (server );
128
125
}
129
126
130
- private void initAAAonServer (final LightyServerBuilder server ) {
131
- final ContextHandlerCollection contexts = new ContextHandlerCollection ();
132
- final ServletContextHandler mainHandler = new ServletContextHandler (contexts , "/auth" , true , false );
133
- final IdmLightApplication idmLightApplication = new IdmLightApplication (iidmStore , claimCache );
134
- final ServletHolder idmLightServlet = new ServletHolder (new ServletContainer (ResourceConfig .forApplication (
135
- idmLightApplication )));
136
- idmLightServlet .setInitParameter ("jersey.config.server.provider.packages" ,
137
- "org.opendaylight.aaa.impl.provider" );
138
- mainHandler .addServlet (idmLightServlet , "/*" );
139
- server .addContextHandler (contexts );
140
- this .handlers .add (contexts );
141
- this .handlers .add (mainHandler );
127
+ private void initAAAonServer (final LightyJettyServerProvider server ) {
142
128
this .aaaWebEnvironment = new AAAWebEnvironment (shiroConfiguration ,
143
129
dataBroker ,
144
130
certificateManager ,
@@ -151,22 +137,41 @@ private void initAAAonServer(final LightyServerBuilder server) {
151
137
final CustomFilterAdapterConfigurationImpl customFilterAdapterConfig =
152
138
new CustomFilterAdapterConfigurationImpl ();
153
139
customFilterAdapterConfig .update (properties );
154
- final FilterHolder customFilterAdapter = new FilterHolder (new CustomFilterAdapter (customFilterAdapterConfig ));
155
- server .addCommonFilter (customFilterAdapter , "/*" );
156
140
157
- final FilterHolder shiroFilter = new FilterHolder (new AAAShiroFilter (aaaWebEnvironment ));
158
- server .addCommonFilter (shiroFilter , "/*" );
141
+ final var webContextBuilder = WebContext .builder ()
142
+ .name ("RealmManagement" )
143
+ .contextPath ("/auth" )
144
+ .supportsSessions (true )
159
145
160
- final FilterHolder crossOriginFilter = new FilterHolder (new CrossOriginFilter ());
161
- crossOriginFilter .setInitParameter ("allowedMethods" , "GET,POST,OPTIONS,DELETE,PUT,HEAD" );
162
- crossOriginFilter .setInitParameter ("allowedHeaders" ,
163
- "origin, content-type, accept, authorization, Authorization" );
164
- server .addCommonFilter (crossOriginFilter , "/*" );
146
+ .addServlet (ServletDetails .builder ()
147
+ .servlet (new JerseyServletSupport ().createHttpServletBuilder (
148
+ new IdmLightApplication (iidmStore , claimCache )).build ())
149
+ .addUrlPattern ("/*" )
150
+ .build ())
151
+
152
+ .addFilter (FilterDetails .builder ()
153
+ .filter (new CustomFilterAdapter (customFilterAdapterConfig ))
154
+ .addUrlPattern ("/*" )
155
+ .build ())
156
+
157
+ .addFilter (FilterDetails .builder ()
158
+ .filter (new AAAShiroFilter (aaaWebEnvironment ))
159
+ .addUrlPattern ("/*" )
160
+ .build ())
161
+
162
+ .addFilter (FilterDetails .builder ()
163
+ .filter (new CrossOriginFilter ())
164
+ .addUrlPattern ("/*" ).putInitParam ("allowedMethods" , "GET,POST,OPTIONS,DELETE,PUT,HEAD" ).putInitParam (
165
+ "allowedHeaders" , "origin, content-type, accept, authorization, Authorization" )
166
+ .build ());
167
+
168
+
169
+ server .addContextHandler (webContextBuilder .build ());
165
170
}
166
171
167
172
public static CompletableFuture <AAALightyShiroProvider > newInstance (final DataBroker dataBroker ,
168
173
final AAAConfiguration aaaConfig , final CredentialAuth <PasswordCredentials > credentialAuth ,
169
- final LightyServerBuilder server ) {
174
+ final LightyJettyServerProvider server ) {
170
175
final CompletableFuture <AAALightyShiroProvider > completableFuture = new CompletableFuture <>();
171
176
INSTANCE = new AAALightyShiroProvider (dataBroker , aaaConfig , credentialAuth , server );
172
177
completableFuture .complete (INSTANCE );
0 commit comments