Revert "Publish ShiroWebEnvironmentLoaderListener to HTTP whiteboard"
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / shiro / web / env / ShiroWebContextSecurer.java
1 /*
2  * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.aaa.shiro.web.env;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.apache.shiro.web.env.EnvironmentLoaderListener;
13 import org.opendaylight.aaa.shiro.filters.AAAShiroFilter;
14 import org.opendaylight.aaa.web.FilterDetails;
15 import org.opendaylight.aaa.web.WebContext;
16 import org.opendaylight.aaa.web.WebContextBuilder;
17 import org.opendaylight.aaa.web.WebContextSecurer;
18
19 /**
20  * Secures a {@link WebContext} using Shiro.
21  *
22  * @author Michael Vorburger.ch
23  */
24 public class ShiroWebContextSecurer implements WebContextSecurer {
25     private final EnvironmentLoaderListener environmentLoaderListener;
26
27     public ShiroWebContextSecurer(final EnvironmentLoaderListener environmentLoaderListener) {
28         this.environmentLoaderListener = requireNonNull(environmentLoaderListener);
29     }
30
31     @Override
32     public void requireAuthentication(final WebContextBuilder webContextBuilder, final boolean asyncSupported,
33             final String... urlPatterns) {
34         webContextBuilder
35             .addListener(environmentLoaderListener)
36             // AAA filter in front of these REST web services as well as for moon endpoints
37             .addFilter(FilterDetails.builder()
38                 .filter(new AAAShiroFilter())
39                 .addUrlPatterns(urlPatterns)
40                 .asyncSupported(asyncSupported)
41                 .build());
42     }
43 }