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

Waffle / waffle / 6364

01 Feb 2026 02:07AM UTC coverage: 46.217%. Remained the same
6364

push

github

web-flow
Merge pull request #3206 from Waffle/renovate/checkstyle.version

Update dependency com.puppycrawl.tools:checkstyle to v13.1.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

75.0
/Source/JNA/waffle-shiro/src/main/java/waffle/shiro/AbstractWaffleRealm.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.shiro;
8

9
import org.apache.shiro.authc.AuthenticationException;
10
import org.apache.shiro.authc.AuthenticationInfo;
11
import org.apache.shiro.authc.AuthenticationToken;
12
import org.apache.shiro.authc.SimpleAuthenticationInfo;
13
import org.apache.shiro.authc.UsernamePasswordToken;
14
import org.apache.shiro.authc.credential.CredentialsMatcher;
15
import org.apache.shiro.authc.credential.HashingPasswordService;
16
import org.apache.shiro.authc.credential.PasswordMatcher;
17
import org.apache.shiro.authc.credential.PasswordService;
18
import org.apache.shiro.authz.AuthorizationInfo;
19
import org.apache.shiro.crypto.hash.Hash;
20
import org.apache.shiro.lang.util.ByteSource;
21
import org.apache.shiro.realm.AuthorizingRealm;
22
import org.apache.shiro.subject.PrincipalCollection;
23
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25

26
import waffle.windows.auth.IWindowsAuthProvider;
27
import waffle.windows.auth.IWindowsIdentity;
28
import waffle.windows.auth.impl.WindowsAuthProviderImpl;
29

30
/**
31
 * A {@link org.apache.shiro.realm.Realm} that authenticates with Active Directory using WAFFLE. Authorization is left
32
 * for subclasses to define by implementing the {@link #buildAuthorizationInfo} method.
33
 */
34
public abstract class AbstractWaffleRealm extends AuthorizingRealm {
2✔
35

36
    /** The Constant LOGGER. */
37
    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractWaffleRealm.class);
2✔
38

39
    /** The Constant REALM_NAME. */
40
    private static final String REALM_NAME = "WAFFLE";
41

42
    /** The provider. */
43
    private IWindowsAuthProvider provider = new WindowsAuthProviderImpl();
2✔
44

45
    @Override
46
    protected final AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authToken) {
47
        AuthenticationInfo authenticationInfo = null;
2✔
48
        if (authToken instanceof UsernamePasswordToken) {
2!
49
            final UsernamePasswordToken token = (UsernamePasswordToken) authToken;
2✔
50
            final String username = token.getUsername();
2✔
51
            IWindowsIdentity identity = null;
2✔
52
            try {
53
                AbstractWaffleRealm.LOGGER.debug("Attempting login for user {}", username);
2✔
54
                identity = this.provider.logonUser(username, new String(token.getPassword()));
2✔
55
                if (identity.isGuest()) {
2✔
56
                    AbstractWaffleRealm.LOGGER.debug("Guest identity for user {}; denying access", username);
2✔
57
                    throw new AuthenticationException("Guest identities are not allowed access");
2✔
58
                }
59
                final Object principal = new WaffleFqnPrincipal(identity);
2✔
60
                authenticationInfo = this.buildAuthenticationInfo(token, principal);
2✔
61
                AbstractWaffleRealm.LOGGER.debug("Successful login for user {}", username);
2✔
62
            } catch (final RuntimeException e) {
2✔
63
                AbstractWaffleRealm.LOGGER.debug("Failed login for user {}", username);
2✔
64
                throw new AuthenticationException("Login failed", e);
2✔
65
            } finally {
66
                if (identity != null) {
2✔
67
                    identity.dispose();
2✔
68
                }
69
            }
70
        }
71
        return authenticationInfo;
2✔
72
    }
73

74
    /**
75
     * Builds the authentication info.
76
     *
77
     * @param token
78
     *            the token
79
     * @param principal
80
     *            the principal
81
     *
82
     * @return the authentication info
83
     */
84
    private AuthenticationInfo buildAuthenticationInfo(final UsernamePasswordToken token, final Object principal) {
85
        AuthenticationInfo authenticationInfo;
86
        final HashingPasswordService hashService = this.getHashService();
2✔
87
        if (hashService != null) {
2!
88
            final Hash hash = hashService.hashPassword(token.getPassword());
×
89
            final ByteSource salt = hash.getSalt();
×
90
            authenticationInfo = new SimpleAuthenticationInfo(principal, hash, salt, AbstractWaffleRealm.REALM_NAME);
×
91
        } else {
×
92
            final Object creds = token.getCredentials();
2✔
93
            authenticationInfo = new SimpleAuthenticationInfo(principal, creds, AbstractWaffleRealm.REALM_NAME);
2✔
94
        }
95
        return authenticationInfo;
2✔
96
    }
97

98
    @Override
99
    protected final AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {
100
        final WaffleFqnPrincipal principal = principals.oneByType(WaffleFqnPrincipal.class);
2✔
101
        return principal == null ? null : this.buildAuthorizationInfo(principal);
2!
102
    }
103

104
    /**
105
     * Assembles the appropriate authorization information for the specified principal.
106
     *
107
     * @param principal
108
     *            the principal for which to assemble authorization information
109
     *
110
     * @return the authorization information for the specified principal
111
     */
112
    protected abstract AuthorizationInfo buildAuthorizationInfo(WaffleFqnPrincipal principal);
113

114
    /**
115
     * Allow overriding the default implementation of {@link IWindowsAuthProvider} This is only needed for testing,
116
     * since for normal usage the default is what you want.
117
     *
118
     * @param value
119
     *            the windows authorization provider
120
     */
121
    void setProvider(final IWindowsAuthProvider value) {
122
        this.provider = value;
2✔
123
    }
2✔
124

125
    /**
126
     * Gets the hash service.
127
     *
128
     * @return the hash service
129
     */
130
    private HashingPasswordService getHashService() {
131
        final CredentialsMatcher matcher = this.getCredentialsMatcher();
2✔
132
        if (matcher instanceof PasswordMatcher) {
2!
133
            final PasswordMatcher passwordMatcher = (PasswordMatcher) matcher;
×
134
            final PasswordService passwordService = passwordMatcher.getPasswordService();
×
135
            if (passwordService instanceof HashingPasswordService) {
×
136
                return (HashingPasswordService) passwordService;
×
137
            }
138
        }
139
        return null;
2✔
140
    }
141

142
}
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