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

Waffle / waffle / 6516

11 Mar 2026 12:15AM UTC coverage: 46.217%. Remained the same
6516

push

github

web-flow
Update dependency org.eclipse.jdt:ecj to v3.45.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

0.0
/Source/JNA/waffle-jna/src/main/java/waffle/windows/auth/impl/WindowsIdentityImpl.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.windows.auth.impl;
8

9
import com.sun.jna.platform.win32.Advapi32Util;
10
import com.sun.jna.platform.win32.Advapi32Util.Account;
11
import com.sun.jna.platform.win32.Kernel32;
12
import com.sun.jna.platform.win32.WinNT.HANDLE;
13
import com.sun.jna.platform.win32.WinNT.WELL_KNOWN_SID_TYPE;
14

15
import java.util.ArrayList;
16
import java.util.List;
17

18
import waffle.windows.auth.IWindowsAccount;
19
import waffle.windows.auth.IWindowsIdentity;
20
import waffle.windows.auth.IWindowsImpersonationContext;
21

22
/**
23
 * Windows Identity.
24
 */
25
public class WindowsIdentityImpl implements IWindowsIdentity {
26

27
    /** The windows identity. */
28
    private final HANDLE windowsIdentity;
29

30
    /** The user groups. */
31
    private Account[] userGroups;
32

33
    /** The windows account. */
34
    private Account windowsAccount;
35

36
    /**
37
     * Instantiates a new windows identity impl.
38
     *
39
     * @param newWindowsIdentity
40
     *            the new windows identity
41
     */
42
    public WindowsIdentityImpl(final HANDLE newWindowsIdentity) {
×
43
        this.windowsIdentity = newWindowsIdentity;
×
44
    }
×
45

46
    /**
47
     * Gets the windows account.
48
     *
49
     * @return the windows account
50
     */
51
    private Account getWindowsAccount() {
52
        if (this.windowsAccount == null) {
×
53
            this.windowsAccount = Advapi32Util.getTokenAccount(this.windowsIdentity);
×
54
        }
55
        return this.windowsAccount;
×
56
    }
57

58
    /**
59
     * Gets the user groups.
60
     *
61
     * @return the user groups
62
     */
63
    private Account[] getUserGroups() {
64
        if (this.userGroups == null) {
×
65
            this.userGroups = Advapi32Util.getTokenGroups(this.windowsIdentity);
×
66
        }
67
        return this.userGroups.clone();
×
68
    }
69

70
    @Override
71
    public String getFqn() {
72
        return this.getWindowsAccount().fqn;
×
73
    }
74

75
    @Override
76
    public IWindowsAccount[] getGroups() {
77

78
        final Account[] groups = this.getUserGroups();
×
79

80
        final List<IWindowsAccount> result = new ArrayList<>(groups.length);
×
81
        for (final Account userGroup : groups) {
×
82
            final WindowsAccountImpl account = new WindowsAccountImpl(userGroup);
×
83
            result.add(account);
×
84
        }
85

86
        return result.toArray(new IWindowsAccount[0]);
×
87
    }
88

89
    @Override
90
    public byte[] getSid() {
91
        return this.getWindowsAccount().sid;
×
92
    }
93

94
    @Override
95
    public String getSidString() {
96
        return this.getWindowsAccount().sidString;
×
97
    }
98

99
    @Override
100
    public void dispose() {
101
        if (this.windowsIdentity != null) {
×
102
            Kernel32.INSTANCE.CloseHandle(this.windowsIdentity);
×
103
        }
104
    }
×
105

106
    @Override
107
    public IWindowsImpersonationContext impersonate() {
108
        return new WindowsIdentityImpersonationContextImpl(this.windowsIdentity);
×
109
    }
110

111
    @Override
112
    public boolean isGuest() {
113
        for (final Account userGroup : this.getUserGroups()) {
×
114
            if (Advapi32Util.isWellKnownSid(userGroup.sid, WELL_KNOWN_SID_TYPE.WinBuiltinGuestsSid)) {
×
115
                return true;
×
116
            }
117
            if (Advapi32Util.isWellKnownSid(userGroup.sid, WELL_KNOWN_SID_TYPE.WinAccountDomainGuestsSid)) {
×
118
                return true;
×
119
            }
120
            if (Advapi32Util.isWellKnownSid(userGroup.sid, WELL_KNOWN_SID_TYPE.WinAccountGuestSid)) {
×
121
                return true;
×
122
            }
123
        }
124
        return Advapi32Util.isWellKnownSid(this.getSid(), WELL_KNOWN_SID_TYPE.WinAnonymousSid);
×
125
    }
126
}
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