• 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

90.2
/Source/JNA/waffle-spring-security5/src/main/java/waffle/spring/WindowsAuthenticationProvider.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.spring;
8

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

11
import java.util.Locale;
12

13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15
import org.springframework.security.authentication.AuthenticationProvider;
16
import org.springframework.security.authentication.AuthenticationServiceException;
17
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
18
import org.springframework.security.core.Authentication;
19
import org.springframework.security.core.GrantedAuthority;
20

21
import waffle.servlet.WindowsPrincipal;
22
import waffle.windows.auth.IWindowsAuthProvider;
23
import waffle.windows.auth.IWindowsIdentity;
24
import waffle.windows.auth.PrincipalFormat;
25

26
/**
27
 * A Waffle authentication provider for Spring-security.
28
 */
29
public class WindowsAuthenticationProvider implements AuthenticationProvider {
30

31
    /** The Constant LOGGER. */
32
    private static final Logger LOGGER = LoggerFactory.getLogger(WindowsAuthenticationProvider.class);
3✔
33

34
    /** The principal format. */
35
    private PrincipalFormat principalFormat = PrincipalFormat.FQN;
3✔
36

37
    /** The role format. */
38
    private PrincipalFormat roleFormat = PrincipalFormat.FQN;
3✔
39

40
    /** The allow guest login. */
41
    private boolean allowGuestLogin = true;
3✔
42

43
    /** The auth provider. */
44
    private IWindowsAuthProvider authProvider;
45

46
    /** The granted authority factory. */
47
    private GrantedAuthorityFactory grantedAuthorityFactory = WindowsAuthenticationToken.DEFAULT_GRANTED_AUTHORITY_FACTORY;
3✔
48

49
    /** The default granted authority. */
50
    private GrantedAuthority defaultGrantedAuthority = WindowsAuthenticationToken.DEFAULT_GRANTED_AUTHORITY;
3✔
51

52
    /**
53
     * Instantiates a new windows authentication provider.
54
     */
55
    public WindowsAuthenticationProvider() {
3✔
56
        WindowsAuthenticationProvider.LOGGER.debug("[waffle.spring.WindowsAuthenticationProvider] loaded");
3✔
57
    }
3✔
58

59
    @Override
60
    public Authentication authenticate(final Authentication authentication) {
61
        final UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
3✔
62
        IWindowsIdentity windowsIdentity;
63
        try {
64
            windowsIdentity = this.authProvider.logonUser(auth.getName(), auth.getCredentials().toString());
3✔
65
        } catch (final Win32Exception e) {
×
66
            throw new AuthenticationServiceException(e.getMessage(), e);
×
67
        }
3✔
68
        WindowsAuthenticationProvider.LOGGER.debug("logged in user: {} ({})", windowsIdentity.getFqn(),
3✔
69
                windowsIdentity.getSidString());
3✔
70

71
        if (!this.allowGuestLogin && windowsIdentity.isGuest()) {
3!
72
            WindowsAuthenticationProvider.LOGGER.warn("guest login disabled: {}", windowsIdentity.getFqn());
3✔
73
            throw new GuestLoginDisabledAuthenticationException(windowsIdentity.getFqn());
3✔
74
        }
75

76
        final WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity, this.principalFormat,
3✔
77
                this.roleFormat);
78
        WindowsAuthenticationProvider.LOGGER.debug("roles: {}", windowsPrincipal.getRolesString());
3✔
79

80
        final WindowsAuthenticationToken token = new WindowsAuthenticationToken(windowsPrincipal,
3✔
81
                this.grantedAuthorityFactory, this.defaultGrantedAuthority);
82

83
        WindowsAuthenticationProvider.LOGGER.info("successfully logged in user: {}", windowsIdentity.getFqn());
3✔
84
        return token;
3✔
85
    }
86

87
    /**
88
     * Supports.
89
     *
90
     * @param authentication
91
     *            the authentication
92
     *
93
     * @return true, if successful
94
     */
95
    @Override
96
    public boolean supports(final Class<? extends Object> authentication) {
97
        return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication);
3✔
98
    }
99

100
    /**
101
     * Gets the principal format.
102
     *
103
     * @return the principal format
104
     */
105
    public PrincipalFormat getPrincipalFormat() {
106
        return this.principalFormat;
3✔
107
    }
108

109
    /**
110
     * Sets the principal format enum.
111
     *
112
     * @param value
113
     *            the new principal format enum
114
     */
115
    public void setPrincipalFormatEnum(final PrincipalFormat value) {
116
        this.principalFormat = value;
3✔
117
    }
3✔
118

119
    /**
120
     * Sets the principal format.
121
     *
122
     * @param value
123
     *            the new principal format
124
     */
125
    public void setPrincipalFormat(final String value) {
126
        this.setPrincipalFormatEnum(PrincipalFormat.valueOf(value.toUpperCase(Locale.ENGLISH)));
3✔
127
    }
3✔
128

129
    /**
130
     * Gets the role format.
131
     *
132
     * @return the role format
133
     */
134
    public PrincipalFormat getRoleFormat() {
135
        return this.roleFormat;
3✔
136
    }
137

138
    /**
139
     * Sets the role format enum.
140
     *
141
     * @param value
142
     *            the new role format enum
143
     */
144
    public void setRoleFormatEnum(final PrincipalFormat value) {
145
        this.roleFormat = value;
3✔
146
    }
3✔
147

148
    /**
149
     * Sets the role format.
150
     *
151
     * @param value
152
     *            the new role format
153
     */
154
    public void setRoleFormat(final String value) {
155
        this.setRoleFormatEnum(PrincipalFormat.valueOf(value.toUpperCase(Locale.ENGLISH)));
3✔
156
    }
3✔
157

158
    /**
159
     * Checks if is allow guest login.
160
     *
161
     * @return true, if is allow guest login
162
     */
163
    public boolean isAllowGuestLogin() {
164
        return this.allowGuestLogin;
3✔
165
    }
166

167
    /**
168
     * Sets the allow guest login.
169
     *
170
     * @param value
171
     *            the new allow guest login
172
     */
173
    public void setAllowGuestLogin(final boolean value) {
174
        this.allowGuestLogin = value;
3✔
175
    }
3✔
176

177
    /**
178
     * Gets the auth provider.
179
     *
180
     * @return the auth provider
181
     */
182
    public IWindowsAuthProvider getAuthProvider() {
183
        return this.authProvider;
3✔
184
    }
185

186
    /**
187
     * Sets the auth provider.
188
     *
189
     * @param value
190
     *            the new auth provider
191
     */
192
    public void setAuthProvider(final IWindowsAuthProvider value) {
193
        this.authProvider = value;
3✔
194
    }
3✔
195

196
    /**
197
     * Gets the granted authority factory.
198
     *
199
     * @return the granted authority factory
200
     */
201
    public GrantedAuthorityFactory getGrantedAuthorityFactory() {
202
        return this.grantedAuthorityFactory;
×
203
    }
204

205
    /**
206
     * Sets the granted authority factory.
207
     *
208
     * @param value
209
     *            the new granted authority factory
210
     */
211
    public void setGrantedAuthorityFactory(final GrantedAuthorityFactory value) {
212
        this.grantedAuthorityFactory = value;
3✔
213
    }
3✔
214

215
    /**
216
     * Gets the default granted authority.
217
     *
218
     * @return the default granted authority
219
     */
220
    public GrantedAuthority getDefaultGrantedAuthority() {
221
        return this.defaultGrantedAuthority;
×
222
    }
223

224
    /**
225
     * Sets the default granted authority.
226
     *
227
     * @param value
228
     *            the new default granted authority
229
     */
230
    public void setDefaultGrantedAuthority(final GrantedAuthority value) {
231
        this.defaultGrantedAuthority = value;
3✔
232
    }
3✔
233
}
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