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;
8
9 import jakarta.servlet.http.HttpServletRequest;
10 import jakarta.servlet.http.HttpServletRequestWrapper;
11
12 import java.security.Principal;
13
14 /**
15 * Negotiate Request wrapper.
16 */
17 public class NegotiateRequestWrapper extends HttpServletRequestWrapper {
18
19 /** The principal. */
20 private final WindowsPrincipal principal;
21
22 /**
23 * Instantiates a new negotiate request wrapper.
24 *
25 * @param newRequest
26 * the new request
27 * @param newPrincipal
28 * the new principal
29 */
30 public NegotiateRequestWrapper(final HttpServletRequest newRequest, final WindowsPrincipal newPrincipal) {
31 super(newRequest);
32 this.principal = newPrincipal;
33 }
34
35 /**
36 * User principal.
37 *
38 * @return the user principal
39 */
40 @Override
41 public Principal getUserPrincipal() {
42 return this.principal;
43 }
44
45 /**
46 * Authentication type.
47 *
48 * @return the auth type
49 */
50 @Override
51 public String getAuthType() {
52 return "NEGOTIATE";
53 }
54
55 /**
56 * Remote username.
57 *
58 * @return the remote user
59 */
60 @Override
61 public String getRemoteUser() {
62 return this.principal.getName();
63 }
64
65 /**
66 * Returns true if the user is in a given role.
67 *
68 * @param role
69 * the role
70 *
71 * @return true, if is user in role
72 */
73 @Override
74 public boolean isUserInRole(final String role) {
75 return this.principal.hasRole(role);
76 }
77 }