Skip to content

Commit

Permalink
Fix typo principle > principal
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Oct 2, 2023
1 parent b5629d9 commit 350b352
Show file tree
Hide file tree
Showing 33 changed files with 139 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.thoughtworks.go.plugin.access.secrets.v1;

import com.google.common.collect.Sets;
import net.javacrumbs.jsonunit.fluent.JsonFluentAssert;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

Expand All @@ -29,7 +29,7 @@ class SecretsMessageConverterV1Test {
class lookupSecretsRequestBody {
@Test
void shouldSendLookupKeysWithSecretConfiguration() {
final String requestBody = new SecretsMessageConverterV1().lookupSecretsRequestBody(Sets.newLinkedHashSet(List.of("username", "password")), Map.of("FilePath", "/var/lib/secret.config"));
final String requestBody = new SecretsMessageConverterV1().lookupSecretsRequestBody(new LinkedHashSet<>(List.of("username", "password")), Map.of("FilePath", "/var/lib/secret.config"));

JsonFluentAssert.assertThatJson(requestBody)
.isEqualTo("{\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.thoughtworks.go.domain.User;
import com.thoughtworks.go.server.domain.Username;
import com.thoughtworks.go.server.newsecurity.utils.SessionUtils;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.server.service.SecurityService;
import com.thoughtworks.go.server.service.UserService;
import org.slf4j.Logger;
Expand Down Expand Up @@ -83,7 +83,7 @@ private boolean persisted(User user) {
private User getUser(HttpServletRequest request) {
Long userId = SessionUtils.getUserId(request);
if (userId == null) {
final GoUserPrinciple currentUser = SessionUtils.getCurrentUser();
final GoUserPrincipal currentUser = SessionUtils.getCurrentUser();

Username userName = new Username(currentUser.getUsername());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.thoughtworks.go.server.newsecurity.models.AuthenticationToken;
import com.thoughtworks.go.server.newsecurity.utils.SessionUtils;
import com.thoughtworks.go.server.security.GoAuthority;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.server.service.AgentService;
import com.thoughtworks.go.server.service.GoConfigService;
import com.thoughtworks.go.util.Clock;
Expand Down Expand Up @@ -93,7 +93,7 @@ private void tokenBasedFilter(HttpServletRequest request, HttpServletResponse re
return;
}

GoUserPrinciple agentUser = new GoUserPrinciple("_go_agent_" + uuid, "", GoAuthority.ROLE_AGENT.asAuthority());
GoUserPrincipal agentUser = new GoUserPrincipal("_go_agent_" + uuid, "", GoAuthority.ROLE_AGENT.asAuthority());
AuthenticationToken<AgentToken> authentication = new AuthenticationToken<>(agentUser, agentToken, null, clock.currentTimeMillis(), null);

LOGGER.debug("Adding agent user to current session and proceeding.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

import java.util.HashSet;
import java.util.Set;

public class AuthorityVerifier {
private final HashSet<GrantedAuthority> grantedAuthorities;
private final Set<GrantedAuthority> grantedAuthorities;

public AuthorityVerifier(Set<GrantedAuthority> grantedAuthorities) {
Assert.notEmpty(grantedAuthorities, "granted authority must not be empty");
Assert.noNullElements(grantedAuthorities.toArray(), "granted authority must not contain null elements");
this.grantedAuthorities = new HashSet<>(grantedAuthorities);
this.grantedAuthorities = Set.copyOf(grantedAuthorities);
}

public boolean hasAnyAuthorityMatching(Set<GrantedAuthority> userAuthorities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
*/
package com.thoughtworks.go.server.newsecurity.models;

import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.util.Clock;
import com.thoughtworks.go.util.SystemEnvironment;

public class AuthenticationToken<T extends Credentials> {
private final GoUserPrinciple user;
private final GoUserPrincipal user;
private final T credentials;
private final String authConfigId;
private final long authenticatedAt;
private final String pluginId;
private boolean invalidated;

public AuthenticationToken(GoUserPrinciple user,
public AuthenticationToken(GoUserPrincipal user,
T credentials,
String pluginId,
long authenticatedAt,
Expand All @@ -40,7 +40,7 @@ public AuthenticationToken(GoUserPrinciple user,
this.authenticatedAt = authenticatedAt;
}

public GoUserPrinciple getUser() {
public GoUserPrincipal getUser() {
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.thoughtworks.go.server.newsecurity.models.Credentials;
import com.thoughtworks.go.server.security.AuthorityGranter;
import com.thoughtworks.go.server.security.OnlyKnownUsersAllowedException;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.server.service.GoConfigService;
import com.thoughtworks.go.server.service.PluginRoleService;
import com.thoughtworks.go.server.service.UserService;
Expand Down Expand Up @@ -100,7 +100,7 @@ protected abstract AuthenticationResponse authenticateWithExtension(String plugi
SecurityAuthConfig authConfig,
List<PluginRoleConfig> pluginRoleConfigs);

protected abstract AuthenticationToken<T> createAuthenticationToken(GoUserPrinciple userPrinciple,
protected abstract AuthenticationToken<T> createAuthenticationToken(GoUserPrincipal uuserPrincipal,
T credentials,
String pluginId,
String authConfigId);
Expand All @@ -124,10 +124,10 @@ public AuthenticationToken<T> authenticateUser(T credentials, SecurityAuthConfig
pluginRoleService.updatePluginRoles(pluginId, user.getUsername(), CaseInsensitiveString.list(response.getRoles()));
LOGGER.debug("Successfully authenticated user: `{}` using the authorization plugin: `{}`", user.getUsername(), pluginId);

final GoUserPrinciple goUserPrinciple = new GoUserPrinciple(user.getUsername(), user.getDisplayName(),
final GoUserPrincipal goUserPrincipal = new GoUserPrincipal(user.getUsername(), user.getDisplayName(),
authorityGranter.authorities(user.getUsername()));

return createAuthenticationToken(goUserPrinciple, credentials, pluginId, authConfig.getId());
return createAuthenticationToken(goUserPrincipal, credentials, pluginId, authConfig.getId());

}
} catch (OnlyKnownUsersAllowedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.thoughtworks.go.server.newsecurity.models.AccessTokenCredential;
import com.thoughtworks.go.server.newsecurity.models.AuthenticationToken;
import com.thoughtworks.go.server.security.AuthorityGranter;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.server.service.AuthorizationExtensionCacheService;
import com.thoughtworks.go.server.service.GoConfigService;
import com.thoughtworks.go.server.service.PluginRoleService;
Expand Down Expand Up @@ -100,10 +100,10 @@ public void setStore(AuthorizationMetadataStore store) {
}

@Override
protected AuthenticationToken<AccessTokenCredential> createAuthenticationToken(GoUserPrinciple userPrinciple,
protected AuthenticationToken<AccessTokenCredential> createAuthenticationToken(GoUserPrincipal uuserPrincipal,
AccessTokenCredential credentials,
String pluginId,
String authConfigId) {
return new AuthenticationToken<>(userPrinciple, credentials, pluginId, clock.currentTimeMillis(), authConfigId);
return new AuthenticationToken<>(uuserPrincipal, credentials, pluginId, clock.currentTimeMillis(), authConfigId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.thoughtworks.go.server.newsecurity.models.AnonymousCredential;
import com.thoughtworks.go.server.newsecurity.models.AuthenticationToken;
import com.thoughtworks.go.server.security.AuthorityGranter;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.util.Clock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -46,7 +46,7 @@ public AuthenticationToken<AnonymousCredential> authenticate(AnonymousCredential
}

private AuthenticationToken<AnonymousCredential> createNewToken() {
GoUserPrinciple anonymous = new GoUserPrinciple("anonymous", "anonymous", authorityGranter.authorities("anonymous"));
GoUserPrincipal anonymous = new GoUserPrincipal("anonymous", "anonymous", authorityGranter.authorities("anonymous"));

AuthenticationToken<AnonymousCredential> authenticationToken = new AuthenticationToken<>(anonymous, AnonymousCredential.INSTANCE, null, clock.currentTimeMillis(), null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.thoughtworks.go.server.newsecurity.models.AuthenticationToken;
import com.thoughtworks.go.server.newsecurity.models.UsernamePassword;
import com.thoughtworks.go.server.security.AuthorityGranter;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.server.service.GoConfigService;
import com.thoughtworks.go.server.service.PluginRoleService;
import com.thoughtworks.go.server.service.UserService;
Expand Down Expand Up @@ -78,10 +78,10 @@ protected AuthenticationResponse authenticateWithExtension(String pluginId,
}

@Override
protected AuthenticationToken<UsernamePassword> createAuthenticationToken(GoUserPrinciple userPrinciple,
protected AuthenticationToken<UsernamePassword> createAuthenticationToken(GoUserPrincipal uuserPrincipal,
UsernamePassword credentials,
String pluginId,
String authConfigId) {
return new AuthenticationToken<>(userPrinciple, credentials, pluginId, clock.currentTimeMillis(), authConfigId);
return new AuthenticationToken<>(uuserPrincipal, credentials, pluginId, clock.currentTimeMillis(), authConfigId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.thoughtworks.go.server.newsecurity.models.AccessToken;
import com.thoughtworks.go.server.newsecurity.models.AuthenticationToken;
import com.thoughtworks.go.server.security.AuthorityGranter;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.server.service.GoConfigService;
import com.thoughtworks.go.server.service.PluginRoleService;
import com.thoughtworks.go.server.service.UserService;
Expand Down Expand Up @@ -81,11 +81,11 @@ protected AuthenticationResponse authenticateWithExtension(String pluginId,
}

@Override
protected AuthenticationToken<AccessToken> createAuthenticationToken(GoUserPrinciple userPrinciple,
protected AuthenticationToken<AccessToken> createAuthenticationToken(GoUserPrincipal uuserPrincipal,
AccessToken credentials,
String pluginId,
String authConfigId) {
return new AuthenticationToken<>(userPrinciple, credentials, pluginId, clock.currentTimeMillis(), authConfigId);
return new AuthenticationToken<>(uuserPrincipal, credentials, pluginId, clock.currentTimeMillis(), authConfigId);
}

private String rootUrlFrom(String urlString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.thoughtworks.go.server.domain.Username;
import com.thoughtworks.go.server.newsecurity.models.AnonymousCredential;
import com.thoughtworks.go.server.newsecurity.models.AuthenticationToken;
import com.thoughtworks.go.server.security.userdetail.GoUserPrinciple;
import com.thoughtworks.go.server.security.userdetail.GoUserPrincipal;
import com.thoughtworks.go.util.Clock;
import com.thoughtworks.go.util.SystemEnvironment;
import org.slf4j.Logger;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class SessionUtils {
private static final String SAVED_REQUEST = "GOCD_SECURITY_SAVED_REQUEST";
private static final PortResolver PORT_RESOLVER = new PortResolverImpl();

private static final ThreadLocal<GoUserPrinciple> USERS = ThreadLocal.withInitial(() -> new GoUserPrinciple("anonymous", "anonymous", ROLE_ANONYMOUS.asAuthority()));
private static final ThreadLocal<GoUserPrincipal> USERS = ThreadLocal.withInitial(() -> new GoUserPrincipal("anonymous", "anonymous", ROLE_ANONYMOUS.asAuthority()));

public static void setAuthenticationTokenWithoutRecreatingSession(AuthenticationToken<?> authenticationToken,
HttpServletRequest request) {
Expand Down Expand Up @@ -155,11 +155,11 @@ public static void setUserId(HttpServletRequest request, Long id) {
}
}

public static GoUserPrinciple getCurrentUser() {
public static GoUserPrincipal getCurrentUser() {
return USERS.get();
}

public static void setCurrentUser(GoUserPrinciple user) {
public static void setCurrentUser(GoUserPrincipal user) {
if (user == null) {
throw new IllegalArgumentException("Use unsetCurrentUser instead");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@
*/
package com.thoughtworks.go.server.security.userdetail;

import com.google.common.collect.Sets;
import com.thoughtworks.go.server.domain.Username;
import org.springframework.security.core.GrantedAuthority;

import java.util.Set;

public class GoUserPrinciple {
public class GoUserPrincipal {
private final Set<GrantedAuthority> authorities;

private final String displayName;
private final Username username;

public GoUserPrinciple(String username, String displayName, GrantedAuthority... authorities) {
this(username, displayName, Sets.newHashSet(authorities));
public GoUserPrincipal(String username, String displayName, GrantedAuthority... authorities) {
this(username, displayName, Set.of(authorities));
}

public GoUserPrinciple(String username, String displayName, Set<GrantedAuthority> authorities) {
public GoUserPrincipal(String username, String displayName, Set<GrantedAuthority> authorities) {
this.username = new Username(username, displayName);
this.authorities = authorities;
this.displayName = displayName;
Expand All @@ -56,9 +55,9 @@ public String getDisplayName() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GoUserPrinciple)) return false;
if (!(o instanceof GoUserPrincipal)) return false;

GoUserPrinciple that = (GoUserPrinciple) o;
GoUserPrincipal that = (GoUserPrincipal) o;

if (authorities != null ? !authorities.equals(that.authorities) : that.authorities != null) return false;
if (displayName != null ? !displayName.equals(that.displayName) : that.displayName != null) return false;
Expand Down

0 comments on commit 350b352

Please sign in to comment.