Skip to content

Commit 8af52ae

Browse files
committed
concord-server: rename SecurityUtils.getCurrent to getPrincipal
1 parent 62f06cc commit 8af52ae

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

server/impl/src/main/java/com/walmartlabs/concord/server/boot/filters/ConcordAuthenticatingFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public ConcordAuthenticatingFilter(Set<AuthenticationHandler> authenticationHand
7979

8080
@Override
8181
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {
82-
Subject subject = SecurityUtils.getSubject(false);
82+
Subject subject = SecurityUtils.getSubject();
8383
if (subject != null && subject.isRemembered()) {
8484
AuthenticationToken t = getFirstToken(subject);
8585
if (t != null) {

server/impl/src/main/java/com/walmartlabs/concord/server/process/ProcessSecurityContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public byte[] serializePrincipals(PrincipalCollection src) {
8181
}
8282

8383
public void storeCurrentSubject(ProcessKey processKey) {
84-
Subject s = SecurityUtils.getSubject(false);
84+
Subject s = SecurityUtils.getSubject();
8585
if (s == null) {
8686
throw new IllegalStateException("Subject is not available. This is a bug.");
8787
}
@@ -125,7 +125,7 @@ public <T> T runAs(UUID userID, Callable<T> c) throws Exception {
125125
.principals(principals)
126126
.buildSubject();
127127

128-
ThreadContext.bind(subject);
128+
SecurityUtils.bindSubject(subject);
129129

130130
return c.call();
131131
} finally {
@@ -146,7 +146,7 @@ public <T> T runAsCurrentUser(ProcessKey processKey, Callable<T> c) throws Excep
146146
.buildSubject();
147147

148148
try {
149-
ThreadContext.bind(subject);
149+
SecurityUtils.bindSubject(subject);
150150

151151
return c.call();
152152
} finally {

server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/PayloadStoreProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Payload process(Chain chain, Payload payload) {
8282

8383
String serializedHeaders = serialize(headers);
8484

85-
Subject initiator = SecurityUtils.getSubject(false);
85+
Subject initiator = SecurityUtils.getSubject();
8686
if (initiator == null) {
8787
throw new IllegalStateException("Subject is not available. This is a bug.");
8888
}

server/impl/src/main/java/com/walmartlabs/concord/server/security/SecurityUtils.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,45 +43,44 @@
4343
public final class SecurityUtils {
4444

4545
public static void logout() {
46-
Subject subject = getSubject(false);
46+
Subject subject = getSubject();
4747
if (subject == null) {
4848
return;
4949
}
5050
subject.logout();
5151
}
5252

5353
public static boolean hasRole(String role) {
54-
Subject s = getSubject(false);
55-
if (s == null) {
54+
Subject subject = getSubject();
55+
if (subject == null) {
5656
return false;
5757
}
58-
return s.hasRole(role);
58+
return subject.hasRole(role);
5959
}
6060

6161
public static boolean isPermitted(String permission) {
62-
Subject s = getSubject(false);
63-
if (s == null) {
62+
Subject subject = getSubject();
63+
if (subject == null) {
6464
return false;
6565
}
66-
return s.isPermitted(permission);
66+
return subject.isPermitted(permission);
6767
}
6868

69-
public static Subject getSubject(boolean create) {
70-
Subject subject = ThreadContext.getSubject();
71-
if (subject == null && create) {
72-
subject = (new Subject.Builder()).buildSubject();
73-
ThreadContext.bind(subject);
74-
}
75-
return subject;
69+
public static void bindSubject(Subject subject) {
70+
ThreadContext.bind(subject);
7671
}
7772

78-
public static <T> T getCurrent(Class<T> type) {
73+
public static Subject getSubject() {
74+
return ThreadContext.getSubject();
75+
}
76+
77+
public static <T> T getPrincipal(Class<T> type) {
7978
SecurityManager securityManager = ThreadContext.getSecurityManager();
8079
if (securityManager == null) {
8180
return null;
8281
}
8382

84-
Subject subject = getSubject(false);
83+
Subject subject = getSubject();
8584
if (subject == null) {
8685
return null;
8786
}
@@ -94,12 +93,12 @@ public static <T> T getCurrent(Class<T> type) {
9493
return principals.oneByType(type);
9594
}
9695

97-
public static <T> T assertCurrent(Class<T> type) {
98-
T p = getCurrent(type);
99-
if (p == null) {
96+
public static <T> T assertPrincipal(Class<T> type) {
97+
T principal = getPrincipal(type);
98+
if (principal == null) {
10099
throw new AuthenticationException("Can't determine the current principal (" + type.getName() + ")");
101100
}
102-
return p;
101+
return principal;
103102
}
104103

105104
public static byte[] serialize(PrincipalCollection data) {

server/impl/src/main/java/com/walmartlabs/concord/server/security/UserPrincipal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public class UserPrincipal implements Serializable {
3535
private static final long serialVersionUID = 1L;
3636

3737
public static UserPrincipal getCurrent() {
38-
return SecurityUtils.getCurrent(UserPrincipal.class);
38+
return SecurityUtils.getPrincipal(UserPrincipal.class);
3939
}
4040

4141
public static UserPrincipal assertCurrent() {
42-
return SecurityUtils.assertCurrent(UserPrincipal.class);
42+
return SecurityUtils.assertPrincipal(UserPrincipal.class);
4343
}
4444

4545
private final String realm;

server/impl/src/main/java/com/walmartlabs/concord/server/security/github/GithubKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class GithubKey implements AuthenticationToken {
2929

3030
public static GithubKey getCurrent() {
31-
return SecurityUtils.getCurrent(GithubKey.class);
31+
return SecurityUtils.getPrincipal(GithubKey.class);
3232
}
3333

3434
private static final long serialVersionUID = 1L;

server/impl/src/main/java/com/walmartlabs/concord/server/security/ldap/LdapPrincipal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public LdapPrincipal(String username,
6363
}
6464

6565
public static LdapPrincipal getCurrent() {
66-
return SecurityUtils.getCurrent(LdapPrincipal.class);
66+
return SecurityUtils.getPrincipal(LdapPrincipal.class);
6767
}
6868

6969
public String getUsername() {

server/impl/src/main/java/com/walmartlabs/concord/server/security/sessionkey/SessionKeyPrincipal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class SessionKeyPrincipal {
2727

2828
public static SessionKeyPrincipal getCurrent() {
29-
return SecurityUtils.getCurrent(SessionKeyPrincipal.class);
29+
return SecurityUtils.getPrincipal(SessionKeyPrincipal.class);
3030
}
3131

3232
private final PartialProcessKey processKey;

server/impl/src/test/java/com/walmartlabs/concord/server/org/secret/PasswordCheckerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* =====
2121
*/
2222

23+
import com.walmartlabs.concord.server.security.SecurityUtils;
2324
import com.walmartlabs.concord.server.security.UserPrincipal;
2425
import com.walmartlabs.concord.server.user.UserEntry;
2526
import org.apache.shiro.mgt.DefaultSecurityManager;
@@ -53,7 +54,7 @@ public void bindUser() {
5354
ctx.setPrincipals(new SimplePrincipalCollection(p, p.getRealm()));
5455

5556
Subject subject = securityManager.createSubject(ctx);
56-
ThreadContext.bind(subject);
57+
SecurityUtils.bindSubject(subject);
5758
}
5859

5960
@AfterEach

0 commit comments

Comments
 (0)