1 /**
2 * Waffle (https://github.com/dblock/waffle)
3 *
4 * Copyright (c) 2010 - 2015 Application Security, Inc.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors:
12 * Application Security, Inc.
13 */
14 package waffle.servlet;
15
16 import java.security.Principal;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletRequestWrapper;
20
21 /**
22 * Negotiate Request wrapper.
23 *
24 * @author dblock[at]dblock[dot]org
25 */
26 public class NegotiateRequestWrapper extends HttpServletRequestWrapper {
27
28 /** The principal. */
29 private final WindowsPrincipal principal;
30
31 /**
32 * Instantiates a new negotiate request wrapper.
33 *
34 * @param newRequest
35 * the new request
36 * @param newPrincipal
37 * the new principal
38 */
39 public NegotiateRequestWrapper(final HttpServletRequest newRequest, final WindowsPrincipal newPrincipal) {
40 super(newRequest);
41 this.principal = newPrincipal;
42 }
43
44 /**
45 * User principal.
46 *
47 * @return the user principal
48 */
49 @Override
50 public Principal getUserPrincipal() {
51 return this.principal;
52 }
53
54 /**
55 * Authentication type.
56 *
57 * @return the auth type
58 */
59 @Override
60 public String getAuthType() {
61 return "NEGOTIATE";
62 }
63
64 /**
65 * Remote username.
66 *
67 * @return the remote user
68 */
69 @Override
70 public String getRemoteUser() {
71 return this.principal.getName();
72 }
73
74 /**
75 * Returns true if the user is in a given role.
76 *
77 * @param role
78 * the role
79 * @return true, if is user in role
80 */
81 @Override
82 public boolean isUserInRole(final String role) {
83 return this.principal.hasRole(role);
84 }
85 }