• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Waffle / waffle / 6516

11 Mar 2026 12:15AM UTC coverage: 46.217%. Remained the same
6516

push

github

web-flow
Update dependency org.eclipse.jdt:ecj to v3.45.0

276 of 734 branches covered (37.6%)

Branch coverage included in aggregate %.

1019 of 2068 relevant lines covered (49.27%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.13
/Source/JNA/waffle-jna/src/main/java/waffle/servlet/spi/SecurityFilterProviderCollection.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2010-2026 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
6
 */
7
package waffle.servlet.spi;
8

9
import com.sun.jna.platform.win32.Win32Exception;
10

11
import java.io.IOException;
12
import java.lang.reflect.Constructor;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.List;
16

17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19

20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22

23
import waffle.util.AuthorizationHeader;
24
import waffle.windows.auth.IWindowsAuthProvider;
25
import waffle.windows.auth.IWindowsIdentity;
26

27
/**
28
 * A collection of security filter providers.
29
 */
30
public class SecurityFilterProviderCollection {
31

32
    /** The Constant LOGGER. */
33
    private static final Logger LOGGER = LoggerFactory.getLogger(SecurityFilterProviderCollection.class);
2✔
34

35
    /** The providers. */
36
    private final List<SecurityFilterProvider> providers = new ArrayList<>();
2✔
37

38
    /**
39
     * Instantiates a new security filter provider collection.
40
     *
41
     * @param providerArray
42
     *            the provider array
43
     */
44
    public SecurityFilterProviderCollection(final SecurityFilterProvider[] providerArray) {
×
45
        for (final SecurityFilterProvider provider : providerArray) {
×
46
            SecurityFilterProviderCollection.LOGGER.info("using '{}'", provider.getClass().getName());
×
47
            this.providers.add(provider);
×
48
        }
49
    }
×
50

51
    /**
52
     * Instantiates a new security filter provider collection.
53
     *
54
     * @param providerNames
55
     *            the provider names
56
     * @param auth
57
     *            the auth
58
     */
59
    @SuppressWarnings("unchecked")
60
    public SecurityFilterProviderCollection(final String[] providerNames, final IWindowsAuthProvider auth) {
2✔
61
        Class<SecurityFilterProvider> providerClass;
62
        Constructor<SecurityFilterProvider> providerConstructor;
63
        for (String providerName : providerNames) {
2✔
64
            providerName = providerName.trim();
2✔
65
            SecurityFilterProviderCollection.LOGGER.info("loading '{}'", providerName);
2✔
66
            try {
67
                providerClass = (Class<SecurityFilterProvider>) Class.forName(providerName);
2✔
68
                providerConstructor = providerClass.getConstructor(IWindowsAuthProvider.class);
2✔
69
                final SecurityFilterProvider provider = providerConstructor.newInstance(auth);
2✔
70
                this.providers.add(provider);
2✔
71
            } catch (final ClassNotFoundException e) {
×
72
                SecurityFilterProviderCollection.LOGGER.error("error loading '{}'", providerName);
×
73
                throw new RuntimeException(e);
×
74
            } catch (final SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException
×
75
                    | IllegalAccessException | InvocationTargetException e) {
×
76
                SecurityFilterProviderCollection.LOGGER.error("error loading '{}': {}", providerName, e.getMessage());
×
77
                SecurityFilterProviderCollection.LOGGER.trace("", e);
1✔
78
            }
1✔
79
        }
1✔
80
    }
1✔
81

82
    /**
83
     * Instantiates a new security filter provider collection.
84
     *
85
     * @param auth
86
     *            the auth
87
     */
1✔
88
    public SecurityFilterProviderCollection(final IWindowsAuthProvider auth) {
2✔
89
        this.providers.add(new NegotiateSecurityFilterProvider(auth));
2✔
90
        this.providers.add(new BasicSecurityFilterProvider(auth));
2✔
91
    }
1✔
92

93
    /**
94
     * Tests whether a specific security package is supported by any of the underlying providers.
95
     *
96
     * @param securityPackage
97
     *            Security package.
98
     *
99
     * @return True if the security package is supported, false otherwise.
100
     */
101
    public boolean isSecurityPackageSupported(final String securityPackage) {
1✔
102
        return this.get(securityPackage) != null;
1✔
103
    }
104

105
    /**
106
     * Gets the.
107
     *
108
     * @param securityPackage
109
     *            the security package
110
     *
111
     * @return the security filter provider
112
     */
113
    private SecurityFilterProvider get(final String securityPackage) {
1✔
114
        for (final SecurityFilterProvider provider : this.providers) {
2✔
115
            if (provider.isSecurityPackageSupported(securityPackage)) {
2✔
116
                return provider;
1✔
117
            }
1✔
118
        }
2✔
119
        return null;
1✔
120
    }
121

122
    /**
123
     * Filter.
124
     *
125
     * @param request
126
     *            Http Request
127
     * @param response
128
     *            Http Response
129
     *
130
     * @return Windows Identity or NULL.
131
     *
132
     * @throws IOException
133
     *             on doFilter.
134
     */
135
    public IWindowsIdentity doFilter(final HttpServletRequest request, final HttpServletResponse response)
136
            throws IOException {
×
137
        final AuthorizationHeader authorizationHeader = new AuthorizationHeader(request);
×
138
        final SecurityFilterProvider provider = this.get(authorizationHeader.getSecurityPackage());
×
139
        if (provider == null) {
×
140
            throw new RuntimeException("Unsupported security package: " + authorizationHeader.getSecurityPackage());
×
141
        }
142
        try {
×
143
            return provider.doFilter(request, response);
×
144
        } catch (final Win32Exception e) {
×
145
            throw new IOException(e);
×
146
        }
147
    }
148

149
    /**
150
     * Returns true if authentication still needs to happen despite an existing principal.
151
     *
152
     * @param request
153
     *            Http Request
154
     *
155
     * @return True if authentication is required.
156
     */
157
    public boolean isPrincipalException(final HttpServletRequest request) {
×
158
        for (final SecurityFilterProvider provider : this.providers) {
×
159
            if (provider.isPrincipalException(request)) {
×
160
                return true;
×
161
            }
×
162
        }
×
163
        return false;
×
164
    }
165

166
    /**
167
     * Send authorization headers.
168
     *
169
     * @param response
170
     *            Http Response
171
     */
172
    public void sendUnauthorized(final HttpServletResponse response) {
×
173
        for (final SecurityFilterProvider provider : this.providers) {
×
174
            provider.sendUnauthorized(response);
×
175
        }
×
176
    }
×
177

178
    /**
179
     * Number of providers.
180
     *
181
     * @return Number of providers.
182
     */
183
    public int size() {
1✔
184
        return this.providers.size();
1✔
185
    }
186

187
    /**
188
     * Get a security provider by class name.
189
     *
190
     * @param name
191
     *            Class name.
192
     *
193
     * @return A security provider instance.
194
     *
195
     * @throws ClassNotFoundException
196
     *             when class not found.
197
     */
198
    public SecurityFilterProvider getByClassName(final String name) throws ClassNotFoundException {
1✔
199
        for (final SecurityFilterProvider provider : this.providers) {
2✔
200
            if (provider.getClass().getName().equals(name)) {
2✔
201
                return provider;
1✔
202
            }
1✔
203
        }
2✔
204
        throw new ClassNotFoundException(name);
1✔
205
    }
206
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc