diff --git a/apis/com.dbeaver.datadam.sso.api/src/main/java/com/dbeaver/datadam/sso/api/DDSsoScopes.java b/apis/com.dbeaver.datadam.sso.api/src/main/java/com/dbeaver/datadam/sso/api/DDSsoScopes.java index 55038ab..1f79cff 100644 --- a/apis/com.dbeaver.datadam.sso.api/src/main/java/com/dbeaver/datadam/sso/api/DDSsoScopes.java +++ b/apis/com.dbeaver.datadam.sso.api/src/main/java/com/dbeaver/datadam/sso/api/DDSsoScopes.java @@ -18,6 +18,7 @@ import org.jkiss.code.NotNull; import org.jkiss.code.Nullable; +import org.jkiss.dbeaver.DBException; import java.util.Collection; import java.util.Set; @@ -32,14 +33,14 @@ private DDSsoScopes() { } @NotNull - public static Set parse(@Nullable String scope) { + public static Set parse(@Nullable String scope) throws DBException { if (scope == null || scope.isEmpty() || scope.length() > 4096) { - throw new IllegalArgumentException("OAuth scopes are required"); + throw new DBException("OAuth scopes are required"); } Set scopes = new TreeSet<>(); for (String value : scope.split(" ", -1)) { if (!TOKEN.matcher(value).matches()) { - throw new IllegalArgumentException("Invalid OAuth scope"); + throw new DBException("Invalid OAuth scope"); } scopes.add(value); } @@ -47,7 +48,7 @@ public static Set parse(@Nullable String scope) { } @NotNull - public static String format(@NotNull Collection scopes) { + public static String format(@NotNull Collection scopes) throws DBException { String value = String.join(" ", new TreeSet<>(scopes)); parse(value); return value; diff --git a/apis/com.dbeaver.datadam.sso.api/src/test/java/com/dbeaver/datadam/sso/api/DDSsoScopesTest.java b/apis/com.dbeaver.datadam.sso.api/src/test/java/com/dbeaver/datadam/sso/api/DDSsoScopesTest.java index f61d43d..51356b1 100644 --- a/apis/com.dbeaver.datadam.sso.api/src/test/java/com/dbeaver/datadam/sso/api/DDSsoScopesTest.java +++ b/apis/com.dbeaver.datadam.sso.api/src/test/java/com/dbeaver/datadam/sso/api/DDSsoScopesTest.java @@ -18,6 +18,7 @@ import org.assertj.core.api.Assertions; import org.jkiss.code.Nullable; +import org.jkiss.dbeaver.DBException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; @@ -27,7 +28,7 @@ class DDSsoScopesTest { @Test - void scopesAreCaseSensitiveAndHaveAStableRepresentation() { + void scopesAreCaseSensitiveAndHaveAStableRepresentation() throws DBException { var scopes = DDSsoScopes.parse("dbeaver-storage:access account:access account:access"); Assertions.assertThat(scopes).isEqualTo(Set.of("dbeaver-storage:access", "account:access")); Assertions.assertThat(DDSsoScopes.format(scopes)).isEqualTo("account:access dbeaver-storage:access"); @@ -39,6 +40,6 @@ void scopesAreCaseSensitiveAndHaveAStableRepresentation() { @ValueSource(strings = {" ", " account:access", "account:access ", "account:access dbeaver-storage:access", "account:access\tdbeaver-storage:access", "account:access\n", "a\"b", "a\\b", "права"}) void rejectsInvalidWireScopes(@Nullable String scope) { - Assertions.assertThatThrownBy(() -> DDSsoScopes.parse(scope)).isInstanceOf(IllegalArgumentException.class); + Assertions.assertThatThrownBy(() -> DDSsoScopes.parse(scope)).isInstanceOf(DBException.class); } }