2 * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
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
8 package org.opendaylight.aaa.shiro.web.env;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Arrays;
13 import org.apache.shiro.web.env.WebEnvironment;
14 import org.opendaylight.aaa.shiro.filters.AAAShiroFilter;
15 import org.opendaylight.aaa.web.FilterDetails;
16 import org.opendaylight.aaa.web.WebContext;
17 import org.opendaylight.aaa.web.WebContextSecurer;
20 * Secures a {@link WebContext} using Shiro.
22 * @author Michael Vorburger.ch
24 public class ShiroWebContextSecurer implements WebContextSecurer {
25 private final WebEnvironment webEnvironment;
27 public ShiroWebContextSecurer(final WebEnvironment webEnvironment) {
28 this.webEnvironment = requireNonNull(webEnvironment);
32 public void requireAuthentication(final WebContext.Builder webContextBuilder, final boolean asyncSupported,
33 final String... urlPatterns) {
34 // AAA filter in front of these REST web services as well as for moon endpoints
35 final var filterBuilder = FilterDetails.builder()
36 .filter(new AAAShiroFilter(webEnvironment))
37 .asyncSupported(asyncSupported);
38 Arrays.stream(urlPatterns).forEach(filterBuilder::addUrlPattern);
40 webContextBuilder.addFilter(filterBuilder.build());