Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.14.0] - 2022-05-05
- User Roles interface

## [2.13.0] - 2022-03-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "2.13.0"
version = "2.14.0"

repositories {
mavenCentral()
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/supertokens/pluginInterface/RECIPE_ID.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
public enum RECIPE_ID {

EMAIL_PASSWORD("emailpassword"), THIRD_PARTY("thirdparty"), SESSION("session"),
EMAIL_VERIFICATION("emailverification"), JWT("jwt"), PASSWORDLESS("passwordless"), USER_METADATA("usermetadata");
EMAIL_VERIFICATION("emailverification"), JWT("jwt"), PASSWORDLESS("passwordless"), USER_METADATA("usermetadata"),
USER_ROLES("userroles");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.userroles;

import com.google.gson.JsonObject;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.userroles.exception.DuplicateUserRoleMappingException;
import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException;

public interface UserRolesStorage extends Storage {

// associate a userId with a role that exists
void addRoleToUser(String userId, String role)
throws StorageQueryException, UnknownRoleException, DuplicateUserRoleMappingException;

// get all roles associated with the input userId
String[] getRolesForUser(String userId) throws StorageQueryException;

// get all users associated with the input role
String[] getUsersForRole(String role) throws StorageQueryException;

// get permissions associated with the input role
String[] getPermissionsForRole(String role) throws StorageQueryException;

// get roles associated with the input permission
String[] getRolesThatHavePermission(String permission) throws StorageQueryException;

// delete a role
boolean deleteRole(String role) throws StorageQueryException;

// get all created roles
String[] getRoles() throws StorageQueryException;

// check if input roles exists
boolean doesRoleExist(String role) throws StorageQueryException;

// delete all roles for the input userId
int deleteAllRolesForUser(String userId) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.userroles.exception;

import java.io.Serial;

public class DuplicateUserRoleMappingException extends UserRolesException {

@Serial
private static final long serialVersionUID = -7619796272179436664L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.userroles.exception;

import java.io.Serial;

public class UnknownRoleException extends UserRolesException {
@Serial
private static final long serialVersionUID = -8116261429148675130L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.userroles.exception;

import java.io.Serial;

public class UserRolesException extends Exception {
@Serial
private static final long serialVersionUID = 5476530661862027675L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.userroles.sqlStorage;

import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.pluginInterface.userroles.UserRolesStorage;
import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException;

public interface UserRolesSQLStorage extends UserRolesStorage, SQLStorage {

// delete role associated with the input userId from the input roles
boolean deleteRoleForUser_Transaction(TransactionConnection con, String userId, String role)
throws StorageQueryException;

// create a new role if it doesnt exist
boolean createNewRoleOrDoNothingIfExists_Transaction(TransactionConnection con, String role)
throws StorageQueryException;

// associate a permission with a role
void addPermissionToRoleOrDoNothingIfExists_Transaction(TransactionConnection con, String role, String permission)
throws StorageQueryException, UnknownRoleException;

// delete a permission associated with the input role
boolean deletePermissionForRole_Transaction(TransactionConnection con, String role, String permission)
throws StorageQueryException;

// delete all permissions associated with the input role
int deleteAllPermissionsForRole_Transaction(TransactionConnection con, String role) throws StorageQueryException;

// check if a role exists
boolean doesRoleExist_Transaction(TransactionConnection con, String role) throws StorageQueryException;
}