Skip to content

Commit

Permalink
Merge pull request #299 from AuthGuard/refactor/endpoints
Browse files Browse the repository at this point in the history
Make all relevant services domain-scoped
  • Loading branch information
kmehrunes committed Jan 27, 2024
2 parents a0460e4 + 5ff486f commit 3bc0be6
Show file tree
Hide file tree
Showing 126 changed files with 930 additions and 727 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>authguard</artifactId>
<groupId>com.nexblocks.authguard</groupId>
<version>0.21.0</version>
<version>0.22.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Expand Up @@ -14,8 +14,8 @@
@DTOStyle
@JsonSerialize(as = AccountDTO.class)
@JsonDeserialize(as = AccountDTO.class)
public interface Account {
long getId();
public interface Account extends DomainScoped {
String getId();
Instant getCreatedAt();
Instant getLastModified();

Expand All @@ -28,7 +28,6 @@ public interface Account {
String getMiddleName();
String getLastName();
String getFullName();
String getDomain();

List<PermissionDTO> getPermissions();
List<String> getRoles();
Expand Down
Expand Up @@ -8,6 +8,6 @@
@Value.Immutable
@DTOStyle
public interface AccountLock {
long getAccountId();
String getAccountId();
Instant getExpiresAt();
}
Expand Up @@ -12,6 +12,6 @@
public interface ActionToken {
String getToken();
String getAction();
Long getAccountId();
String getAccountId();
long getValidFor();
}
Expand Up @@ -12,12 +12,13 @@
@JsonSerialize(as = ApiKeyDTO.class)
@JsonDeserialize(as = ApiKeyDTO.class)
public interface ApiKey {
long getId();
String getId();
Instant getCreatedAt();
Instant getLastModified();
Long getAppId();
String getAppId();
String getKey();
String getType();
String getName();
boolean isForClient();
Instant getExpiresAt();
}
Expand Up @@ -12,14 +12,13 @@
@DTOStyle
@JsonSerialize(as = AppDTO.class)
@JsonDeserialize(as = AppDTO.class)
public interface App {
long getId();
public interface App extends DomainScoped {
String getId();
Instant getCreatedAt();
Instant getLastModified();
String getExternalId();
String getName();
Long getAccountId();
String getDomain();
String getAccountId();
String getBaseUrl();
List<PermissionDTO> getPermissions();
List<String> getRoles();
Expand Down
Expand Up @@ -11,14 +11,13 @@
@DTOStyle
@JsonSerialize(as = ClientDTO.class)
@JsonDeserialize(as = ClientDTO.class)
public interface Client {
long getId();
public interface Client extends DomainScoped {
String getId();
Instant getCreatedAt();
Instant getLastModified();
String getExternalId();
String getName();
Long getAccountId();
String getDomain();
String getAccountId();
String getBaseUrl();
String getClientType();
boolean isActive();
Expand Down
Expand Up @@ -11,7 +11,7 @@
@DTOStyle
@JsonDeserialize(as = CredentialsDTO.class)
public interface Credentials {
long getId();
String getId();
Instant getCreatedAt();
Instant getLastModified();
Instant getPasswordUpdatedAt();
Expand Down
@@ -0,0 +1,5 @@
package com.nexblocks.authguard.api.dto.entities;

public interface DomainScoped {
String getDomain();
}
Expand Up @@ -8,10 +8,10 @@
@Value.Immutable
@DTOStyle
public interface ExchangeAttempt {
long getId();
String getId();
Instant getCreatedAt();
Instant getLastModified();
Long getEntityId();
String getEntityId();
String getExchangeFrom();
String getExchangeTo();
boolean isSuccessful();
Expand Down
Expand Up @@ -11,11 +11,10 @@
@DTOStyle
@JsonSerialize(as = PermissionDTO.class)
@JsonDeserialize(as = PermissionDTO.class)
public interface Permission {
long getId();
public interface Permission extends DomainScoped {
String getId();
Instant getCreatedAt();
Instant getLastModified();
String getGroup();
String getName();
String getDomain();
}
Expand Up @@ -11,10 +11,9 @@
@DTOStyle
@JsonDeserialize(as = RoleDTO.class)
@JsonSerialize(as = RoleDTO.class)
public interface Role {
long getId();
public interface Role extends DomainScoped {
String getId();
Instant getCreatedAt();
Instant getLastModified();
String getName();
String getDomain();
}
Expand Up @@ -9,10 +9,9 @@
@DTOStyle
@JsonSerialize(as = UserIdentifierDTO.class)
@JsonDeserialize(as = UserIdentifierDTO.class)
public interface UserIdentifier {
public interface UserIdentifier extends DomainScoped {
Type getType();
String getIdentifier();
String getDomain();

@Value.Default
default boolean isActive() {
Expand Down
Expand Up @@ -14,7 +14,8 @@
public interface ApiKeyRequest {
boolean isForClient();
String getKeyType();
Long getAppId();
String getAppId();
String getName();
Instant getExpiresAt();
DurationRequestDTO getValidFor();
}
Expand Up @@ -2,10 +2,7 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nexblocks.authguard.api.dto.entities.AccountEmailDTO;
import com.nexblocks.authguard.api.dto.entities.PermissionDTO;
import com.nexblocks.authguard.api.dto.entities.PhoneNumberDTO;
import com.nexblocks.authguard.api.dto.entities.UserIdentifierDTO;
import com.nexblocks.authguard.api.dto.entities.*;
import com.nexblocks.authguard.api.dto.style.DTOStyle;
import org.immutables.value.Value;

Expand All @@ -16,14 +13,13 @@
@DTOStyle
@JsonDeserialize(as = CreateAccountRequestDTO.class)
@JsonSerialize(as = CreateAccountRequestDTO.class)
public interface CreateAccountRequest {
public interface CreateAccountRequest extends DomainScoped {
String getExternalId();

String getFirstName();
String getMiddleName();
String getLastName();
String getFullName();
String getDomain();

AccountEmailDTO getEmail();
AccountEmailDTO getBackupEmail();
Expand Down
@@ -1,5 +1,6 @@
package com.nexblocks.authguard.api.dto.requests;

import com.nexblocks.authguard.api.dto.entities.DomainScoped;
import com.nexblocks.authguard.api.dto.entities.PermissionDTO;
import com.nexblocks.authguard.api.dto.style.DTOStyle;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -12,11 +13,10 @@
@DTOStyle
@JsonDeserialize(as = CreateAppRequestDTO.class)
@JsonSerialize(as = CreateAppRequestDTO.class)
public interface CreateAppRequest {
public interface CreateAppRequest extends DomainScoped {
String getExternalId();
String getName();
Long getAccountId();
String getDomain();
String getAccountId();
List<PermissionDTO> getPermissions();
List<String> getScopes();
List<String> getRoles();
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nexblocks.authguard.api.dto.entities.DomainScoped;
import com.nexblocks.authguard.api.dto.style.DTOStyle;
import org.immutables.value.Value;

Expand All @@ -10,11 +11,10 @@
@DTOStyle
@JsonDeserialize(as = CreateClientRequestDTO.class)
@JsonSerialize(as = CreateClientRequestDTO.class)
public interface CreateClientRequest {
public interface CreateClientRequest extends DomainScoped {
String getExternalId();
String getName();
Long getAccountId();
String getDomain();
String getBaseUrl();
ClientType getClientType();

Expand Down
Expand Up @@ -2,15 +2,15 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nexblocks.authguard.api.dto.entities.DomainScoped;
import com.nexblocks.authguard.api.dto.style.DTOStyle;
import org.immutables.value.Value;

@Value.Immutable
@DTOStyle
@JsonSerialize(as = CreatePermissionRequestDTO.class)
@JsonDeserialize(as = CreatePermissionRequestDTO.class)
public interface CreatePermissionRequest {
public interface CreatePermissionRequest extends DomainScoped {
String getGroup();
String getName();
String getDomain();
}
@@ -1,5 +1,6 @@
package com.nexblocks.authguard.api.dto.requests;

import com.nexblocks.authguard.api.dto.entities.DomainScoped;
import com.nexblocks.authguard.api.dto.style.DTOStyle;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand All @@ -9,7 +10,6 @@
@DTOStyle
@JsonDeserialize(as = CreateRoleRequestDTO.class)
@JsonSerialize(as = CreateRoleRequestDTO.class)
public interface CreateRoleRequest {
public interface CreateRoleRequest extends DomainScoped {
String getName();
String getDomain();
}
Expand Up @@ -10,6 +10,6 @@
@JsonDeserialize(as = OtpRequestDTO.class)
@JsonSerialize(as = OtpRequestDTO.class)
public interface OtpRequest {
Long getPasswordId();
String getPasswordId();
String getPassword();
}
Expand Up @@ -2,18 +2,18 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nexblocks.authguard.api.dto.entities.DomainScoped;
import com.nexblocks.authguard.api.dto.style.DTOStyle;
import org.immutables.value.Value;

@Value.Immutable
@DTOStyle
@JsonSerialize(as = PasswordResetRequestDTO.class)
@JsonDeserialize(as = PasswordResetRequestDTO.class)
public interface PasswordResetRequest {
public interface PasswordResetRequest extends DomainScoped {
boolean isByToken();
String getResetToken();
String getIdentifier();
String getOldPassword();
String getNewPassword();
String getDomain();
}
Expand Up @@ -2,14 +2,14 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nexblocks.authguard.api.dto.entities.DomainScoped;
import com.nexblocks.authguard.api.dto.style.DTOStyle;
import org.immutables.value.Value;

@Value.Immutable
@DTOStyle
@JsonSerialize(as = PasswordResetTokenRequestDTO.class)
@JsonDeserialize(as = PasswordResetTokenRequestDTO.class)
public interface PasswordResetTokenRequest {
public interface PasswordResetTokenRequest extends DomainScoped {
String getIdentifier();
String getDomain();
}
@@ -0,0 +1,14 @@
package com.nexblocks.authguard.api.dto.validation;

import com.nexblocks.authguard.service.exceptions.ServiceException;
import com.nexblocks.authguard.service.exceptions.codes.ErrorCode;

public class IdParser {
public static Long from(final String idString) {
try {
return Long.parseLong(idString);
} catch (NumberFormatException ex) {
throw new ServiceException(ErrorCode.INVALID_REQUEST_VALUE, "Value '" + idString + "' is not a valid ID");
}
}
}
Expand Up @@ -13,6 +13,7 @@ public class PasswordResetRequestValidator implements Validator<PasswordResetReq
@Override
public List<Violation> validate(final PasswordResetRequestDTO obj) {
return FluentValidator.begin()
.validate("domain", obj.getDomain(), Constraints.required)
.validate("identifier", obj.getIdentifier(), identifier -> {
if (!obj.isByToken() && identifier == null) {
return Collections.singletonList(
Expand Down
Expand Up @@ -9,7 +9,7 @@ public abstract class AccountsApi implements ApiRoute {

@Override
public String getPath() {
return "accounts";
return "/domains/:domain/accounts";
}

public void addEndpoints() {
Expand All @@ -18,12 +18,12 @@ public void addEndpoints() {
get("/:id", this::getById, ActorRoles.adminClient());
delete("/:id", this::deleteAccount, ActorRoles.adminClient());
patch("/:id", this::patchAccount, ActorRoles.adminClient());
get("/domain/:domain/identifier/:identifier", this::getByIdentifier, ActorRoles.adminClient());
get("/domain/:domain/identifier/:identifier/exists", this::identifierExists, ActorRoles.adminOrAuthClient());
get("/identifier/:identifier", this::getByIdentifier, ActorRoles.adminClient());
get("/identifier/:identifier/exists", this::identifierExists, ActorRoles.adminOrAuthClient());

get("/externalId/:id", this::getByExternalId, ActorRoles.adminClient());
get("/domain/:domain/email/:email", this::getByEmail, ActorRoles.adminClient());
get("/domain/:domain/email/:email/exists", this::emailExists, ActorRoles.adminOrAuthClient());
get("/email/:email", this::getByEmail, ActorRoles.adminClient());
get("/email/:email/exists", this::emailExists, ActorRoles.adminOrAuthClient());

patch("/:id/permissions", this::updatePermissions, ActorRoles.adminClient());
patch("/:id/roles", this::updateRoles, ActorRoles.adminClient());
Expand Down
Expand Up @@ -8,7 +8,7 @@
public abstract class ActionTokensApi implements ApiRoute {
@Override
public String getPath() {
return "actions";
return "/domains/:domain/actions";
}

@Override
Expand Down
Expand Up @@ -9,7 +9,7 @@ public abstract class ApiKeysApi implements ApiRoute {

@Override
public String getPath() {
return "keys";
return "/domains/:domain/keys";
}

@Override
Expand Down
Expand Up @@ -9,7 +9,7 @@ public abstract class ApplicationsApi implements ApiRoute {

@Override
public String getPath() {
return "apps";
return "/domains/:domain/apps";
}

@Override
Expand Down

0 comments on commit 3bc0be6

Please sign in to comment.