• 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

59.26
/Source/JNA/waffle-shiro/src/main/java/waffle/shiro/dynamic/DynamicAuthenticationFilter.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.dynamic;
8

9
import javax.servlet.ServletRequest;
10
import javax.servlet.ServletResponse;
11

12
import org.apache.shiro.authc.AuthenticationToken;
13
import org.apache.shiro.subject.Subject;
14
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
import waffle.shiro.negotiate.NegotiateAuthenticationFilter;
19

20
/**
21
 * When combined with the {@link waffle.shiro.negotiate.NegotiateAuthenticationStrategy}, this filter can be used to
22
 * allow a client to choose which authentication filter is used at runtime. This filter assumes the shiro.ini is
23
 * configured with both the {@link waffle.shiro.negotiate.NegotiateAuthenticationRealm} and some User/Password Realm
24
 * like: {@link waffle.shiro.GroupMappingWaffleRealm}.
25
 * <p>
26
 * Requires use of {@link waffle.shiro.negotiate.NegotiateAuthenticationStrategy} when more than one realm is configured
27
 * in shiro.ini (which should be the case for multiple authentication type options).
28
 * <p>
29
 * To use {@link waffle.shiro.negotiate.NegotiateAuthenticationRealm}, the client must pass the parameter
30
 * {@link #PARAM_NAME_AUTHTYPE} with a value of {@link #PARAM_VAL_AUTHTYPE_NEGOTIATE}.
31
 * <p>
32
 * Example shiro.ini snippet below:
33
 *
34
 * <pre>
35
 *  # =======================
36
 *  # Shiro INI configuration
37
 *  # =======================
38
 *
39
 *  [main]
40
 *
41
 *  # Setup custom AuthenticationRealm
42
 *  waffleRealmSSO = waffle.shiro.negotiate.NegotiateAuthenticationRealm
43
 *  waffleUserPass = waffle.shiro.GroupMappingWaffleRealm
44
 *  securityManager.realms = $waffleRealmSSO, $waffleUserPass
45
 *
46
 *
47
 *  # Use the configured native session manager:
48
 *  sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
49
 *  securityManager.sessionManager = $sessionManager
50
 *
51
 *  # the following call is only necessary in a web-configured ShiroFilter (otherwise
52
 *  # a native session manager is already enabled):
53
 *  securityManager.sessionMode = native
54
 *
55
 *
56
 *  # cookie for single sign on
57
 *  cookie = org.apache.shiro.web.servlet.SimpleCookie
58
 *  cookie.name = SSOcookie
59
 *  cookie.path = /
60
 *  securityManager.sessionManager.sessionIdCookie = $cookie
61
 *
62
 *
63
 *  authcStrategy = waffle.shiro.negotiate.NegotiateAuthenticationStrategy
64
 *  securityManager.authenticator.authenticationStrategy = $authcStrategy
65
 *
66
 *  # Waffle filter
67
 *  waffleFilter = waffle.shiro.dynamic.DynamicAuthenticationFilter
68
 *
69
 *  #Configure filter chains and filter parameters
70
 *  authc.loginUrl = /login.jsp
71
 *  waffleFilter.loginUrl = /login.jsp
72
 *  logout.redirectUrl = login.jsp
73
 *
74
 *  ...
75
 *
76
 *  [urls]
77
 *  # The 'urls' section is used for url-based security
78
 *  /logout = logout
79
 *  /* = waffleFilter
80
 * </pre>
81
 */
82
public class DynamicAuthenticationFilter extends FormAuthenticationFilter {
2✔
83

84
    /** The Constant LOGGER. */
85
    private static final Logger LOGGER = LoggerFactory.getLogger(DynamicAuthenticationFilter.class);
2✔
86

87
    /** The Constant PARAM_NAME_AUTHTYPE. */
88
    public static final String PARAM_NAME_AUTHTYPE = "authType";
89

90
    /** The Constant PARAM_VAL_AUTHTYPE_NEGOTIATE. */
91
    public static final String PARAM_VAL_AUTHTYPE_NEGOTIATE = "j_negotiate";
92

93
    /**
94
     * Wrapper to make protected methods in different package callable from here.
95
     */
96
    private static final class WrapNegotiateAuthenticationFilter extends NegotiateAuthenticationFilter {
97

98
        /** The parent. */
99
        private final DynamicAuthenticationFilter parent;
100

101
        /**
102
         * Instantiates a new wrap negotiate authentication filter.
103
         *
104
         * @param newParent
105
         *            the new parent
106
         */
107
        WrapNegotiateAuthenticationFilter(final DynamicAuthenticationFilter newParent) {
2✔
108
            this.parent = newParent;
2✔
109
        }
2✔
110

111
        @Override
112
        public boolean onAccessDenied(final ServletRequest request, final ServletResponse response) throws Exception {
113
            return super.onAccessDenied(request, response);
×
114
        }
115

116
        @Override
117
        protected boolean onLoginSuccess(final AuthenticationToken token, final Subject subject,
118
                final ServletRequest request, final ServletResponse response) throws Exception {
119
            return this.parent.onLoginSuccess(token, subject, request, response);
×
120
        }
121
    }
122

123
    /** The filter negotiate. */
124
    private final WrapNegotiateAuthenticationFilter filterNegotiate = new WrapNegotiateAuthenticationFilter(this);
2✔
125

126
    /**
127
     * Wrapper to make protected methods in different package callable from here.
128
     */
129
    private static final class WrapFormAuthenticationFilter extends FormAuthenticationFilter {
130

131
        /** The parent. */
132
        private final DynamicAuthenticationFilter parent;
133

134
        /**
135
         * Instantiates a new wrap form authentication filter.
136
         *
137
         * @param newParent
138
         *            the new parent
139
         */
140
        WrapFormAuthenticationFilter(final DynamicAuthenticationFilter newParent) {
2✔
141
            this.parent = newParent;
2✔
142
        }
2✔
143

144
        @Override
145
        public boolean onAccessDenied(final ServletRequest request, final ServletResponse response) throws Exception {
146
            return super.onAccessDenied(request, response);
×
147
        }
148

149
        @Override
150
        protected boolean onLoginSuccess(final AuthenticationToken token, final Subject subject,
151
                final ServletRequest request, final ServletResponse response) throws Exception {
152
            return this.parent.onLoginSuccess(token, subject, request, response);
×
153
        }
154
    }
155

156
    /** The filter form authc. */
157
    private final WrapFormAuthenticationFilter filterFormAuthc = new WrapFormAuthenticationFilter(this);
2✔
158

159
    /**
160
     * Call
161
     * {@link org.apache.shiro.web.filter.AccessControlFilter#onAccessDenied(javax.servlet.ServletRequest, javax.servlet.ServletResponse)}
162
     * for the user selected authentication type, which performs login logic.
163
     * <p>
164
     * {@inheritDoc}
165
     */
166
    @Override
167
    protected boolean executeLogin(final ServletRequest request, final ServletResponse response) throws Exception {
168
        if (this.isAuthTypeNegotiate(request)) {
×
169
            DynamicAuthenticationFilter.LOGGER.debug("using filterNegotiate");
×
170
            return this.filterNegotiate.onAccessDenied(request, response);
×
171
        }
172
        DynamicAuthenticationFilter.LOGGER.debug("using filterFormAuthc");
×
173
        return this.filterFormAuthc.onAccessDenied(request, response);
×
174
    }
175

176
    /**
177
     * Checks if is auth type negotiate.
178
     *
179
     * @param request
180
     *            the request
181
     *
182
     * @return true, if is auth type negotiate
183
     */
184
    boolean isAuthTypeNegotiate(final ServletRequest request) {
185
        final String authType = request.getParameter(DynamicAuthenticationFilter.PARAM_NAME_AUTHTYPE);
2✔
186
        return authType != null && DynamicAuthenticationFilter.PARAM_VAL_AUTHTYPE_NEGOTIATE.equalsIgnoreCase(authType);
2✔
187
    }
188

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