1 package org.metricshub.winrm.service.client.auth.ntlm;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.function.LongUnaryOperator;
24 import org.apache.http.Header;
25 import org.apache.http.HttpRequest;
26 import org.apache.http.auth.AuthenticationException;
27 import org.apache.http.auth.Credentials;
28 import org.apache.http.client.config.AuthSchemes;
29 import org.apache.http.message.BasicHeader;
30
31
32
33
34
35 public class NtlmMasqAsSpnegoScheme extends NTLMScheme {
36
37 private static final LongUnaryOperator FLAG_MODIFIER = flags ->
38 flags |
39 NTLMEngineUtils.NTLMSSP_NEGOTIATE_SIGN |
40 NTLMEngineUtils.NTLMSSP_NEGOTIATE_SEAL |
41 NTLMEngineUtils.NTLMSSP_NEGOTIATE_KEY_EXCH;
42
43 public NtlmMasqAsSpnegoScheme() {
44 super(newDefaultNtlmEngine());
45 }
46
47 private static NTLMEngine newDefaultNtlmEngine() {
48 return new NTLMEngineImpl() {
49 @Override
50 public Integer getDefaultFlags() {
51 final Long flags = (long) Type1Message.getDefaultFlags();
52 return (int) FLAG_MODIFIER.applyAsLong(flags);
53 }
54 };
55 }
56
57 @Override
58 public String getSchemeName() {
59 return AuthSchemes.SPNEGO;
60 }
61
62 @Override
63 public Header authenticate(final Credentials credentials, final HttpRequest httpRequest)
64 throws AuthenticationException {
65 final Header header = super.authenticate(credentials, httpRequest);
66
67
68 return new BasicHeader(header.getName(), header.getValue().replace("NTLM", getSchemeName()));
69 }
70 }