• 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

81.48
/Source/JNA/waffle-tomcat9/src/main/java/waffle/apache/GenericWindowsPrincipal.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.apache;
8

9
import java.util.ArrayList;
10
import java.util.HashMap;
11
import java.util.List;
12
import java.util.Map;
13

14
import org.apache.catalina.realm.GenericPrincipal;
15

16
import waffle.windows.auth.IWindowsAccount;
17
import waffle.windows.auth.IWindowsIdentity;
18
import waffle.windows.auth.PrincipalFormat;
19
import waffle.windows.auth.WindowsAccount;
20

21
/**
22
 * A Windows Principal.
23
 */
24
public class GenericWindowsPrincipal extends GenericPrincipal {
25

26
    /** The Constant serialVersionUID. */
27
    private static final long serialVersionUID = 1L;
28

29
    /** The sid. */
30
    private final byte[] sid;
31

32
    /** The sid string. */
33
    private final String sidString;
34

35
    /** The groups. */
36
    private final Map<String, WindowsAccount> groups;
37

38
    /**
39
     * A windows principal.
40
     *
41
     * @param windowsIdentity
42
     *            Windows identity.
43
     * @param principalFormat
44
     *            Principal format.
45
     * @param roleFormat
46
     *            Role format.
47
     */
48
    public GenericWindowsPrincipal(final IWindowsIdentity windowsIdentity, final PrincipalFormat principalFormat,
49
            final PrincipalFormat roleFormat) {
50
        super(windowsIdentity.getFqn(), "",
3✔
51
                GenericWindowsPrincipal.getRoles(windowsIdentity, principalFormat, roleFormat));
3✔
52
        this.sid = windowsIdentity.getSid();
3✔
53
        this.sidString = windowsIdentity.getSidString();
3✔
54
        this.groups = GenericWindowsPrincipal.getGroups(windowsIdentity.getGroups());
3✔
55
    }
1✔
56

57
    /**
58
     * Gets the roles.
59
     *
60
     * @param windowsIdentity
61
     *            the windows identity
62
     * @param principalFormat
63
     *            the principal format
64
     * @param roleFormat
65
     *            the role format
66
     *
67
     * @return the roles
68
     */
69
    private static List<String> getRoles(final IWindowsIdentity windowsIdentity, final PrincipalFormat principalFormat,
70
            final PrincipalFormat roleFormat) {
2✔
71
        final List<String> roles = new ArrayList<>();
3✔
72
        roles.addAll(GenericWindowsPrincipal.getPrincipalNames(windowsIdentity, principalFormat));
3✔
73
        for (final IWindowsAccount group : windowsIdentity.getGroups()) {
3✔
74
            roles.addAll(GenericWindowsPrincipal.getRoleNames(group, roleFormat));
1✔
75
        }
2✔
76
        return roles;
1✔
77
    }
78

79
    /**
80
     * Gets the groups.
81
     *
82
     * @param groups
83
     *            the groups
84
     *
85
     * @return the groups
86
     */
87
    private static Map<String, WindowsAccount> getGroups(final IWindowsAccount[] groups) {
2✔
88
        final Map<String, WindowsAccount> groupMap = new HashMap<>();
3✔
89
        for (final IWindowsAccount group : groups) {
3✔
90
            groupMap.put(group.getFqn(), new WindowsAccount(group));
1✔
91
        }
2✔
92
        return groupMap;
1✔
93
    }
94

95
    /**
96
     * Windows groups that the user is a member of.
97
     *
98
     * @return A map of group names to groups.
99
     */
100
    public Map<String, WindowsAccount> getGroups() {
2✔
101
        return this.groups;
1✔
102
    }
103

104
    /**
105
     * Byte representation of the SID.
106
     *
107
     * @return Array of bytes.
108
     */
109
    public byte[] getSid() {
2✔
110
        return this.sid.clone();
1✔
111
    }
112

113
    /**
114
     * String representation of the SID.
115
     *
116
     * @return String.
117
     */
118
    public String getSidString() {
2✔
119
        return this.sidString;
1✔
120
    }
121

122
    /**
123
     * Returns a list of role principal objects.
124
     *
125
     * @param group
126
     *            Windows group.
127
     * @param principalFormat
128
     *            Principal format.
129
     *
130
     * @return List of role principal objects.
131
     */
132
    private static List<String> getRoleNames(final IWindowsAccount group, final PrincipalFormat principalFormat) {
2✔
133
        final List<String> principals = new ArrayList<>();
3!
134
        switch (principalFormat) {
1!
135
            case FQN:
2✔
136
                principals.add(group.getFqn());
3✔
137
                break;
1✔
138
            case SID:
×
139
                principals.add(group.getSidString());
×
140
                break;
×
141
            case BOTH:
×
142
                principals.add(group.getFqn());
×
143
                principals.add(group.getSidString());
×
144
                break;
×
145
            case NONE:
146
            default:
147
                break;
148
        }
2✔
149
        return principals;
1✔
150
    }
151

152
    /**
153
     * Returns a list of user principal objects.
154
     *
155
     * @param windowsIdentity
156
     *            Windows identity.
157
     * @param principalFormat
158
     *            Principal format.
159
     *
160
     * @return A list of user principal objects.
161
     */
162
    private static List<String> getPrincipalNames(final IWindowsIdentity windowsIdentity,
163
            final PrincipalFormat principalFormat) {
2✔
164
        final List<String> principals = new ArrayList<>();
3✔
165
        switch (principalFormat) {
1✔
166
            case FQN:
2✔
167
                principals.add(windowsIdentity.getFqn());
3✔
168
                break;
1✔
169
            case SID:
2✔
170
                principals.add(windowsIdentity.getSidString());
3✔
171
                break;
1✔
172
            case BOTH:
2✔
173
                principals.add(windowsIdentity.getFqn());
3✔
174
                principals.add(windowsIdentity.getSidString());
3✔
175
                break;
1✔
176
            case NONE:
177
            default:
178
                break;
179
        }
2✔
180
        return principals;
1✔
181
    }
182

183
    /**
184
     * Get an array of roles as a string.
185
     *
186
     * @return Role1, Role2, ...
187
     */
188
    public String getRolesString() {
×
189
        return String.join(", ", this.getRoles());
×
190
    }
191

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