Skip to content

Commit

Permalink
feat: init Role, RoleInstancePermission and RoleClassPermission
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlkoch committed Jun 12, 2024
1 parent f8d885f commit 48042db
Show file tree
Hide file tree
Showing 27 changed files with 1,886 additions and 23 deletions.
75 changes: 75 additions & 0 deletions shogun-boot/src/main/resources/db/migration/V0.14.0__Init_Role.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
CREATE TABLE IF NOT EXISTS shogun.roles (
id BIGINT PRIMARY KEY,
created TIMESTAMP WITHOUT TIME ZONE,
modified TIMESTAMP WITHOUT TIME ZONE,
auth_provider_id TEXT UNIQUE NOT NULL
);

CREATE TABLE IF NOT EXISTS shogun.roleclasspermissions (
id BIGINT PRIMARY KEY,
created TIMESTAMP WITHOUT TIME ZONE,
modified TIMESTAMP WITHOUT TIME ZONE,
class_name TEXT,
permission_id BIGINT NOT NULL REFERENCES permissions (id),
role_id BIGINT NOT NULL REFERENCES roles (id)
);

CREATE TABLE IF NOT EXISTS shogun.roleinstancepermissions (
id BIGINT PRIMARY KEY,
created TIMESTAMP WITHOUT TIME ZONE,
modified TIMESTAMP WITHOUT TIME ZONE,
entity_id bigint NOT NULL,
permission_id bigint NOT NULL REFERENCES permissions (id),
role_id BIGINT NOT NULL REFERENCES roles (id)
);

CREATE TABLE IF NOT EXISTS shogun_rev.roles_rev (
id BIGINT,
rev INTEGER REFERENCES shogun_rev.revinfo (rev),
revtype SMALLINT,
created TIMESTAMP WITHOUT TIME ZONE,
modified TIMESTAMP WITHOUT TIME ZONE,
auth_provider_id TEXT,
created_mod BOOLEAN,
modified_mod BOOLEAN,
auth_provider_id_mod BOOLEAN,
PRIMARY KEY (id, rev)
);

CREATE TABLE IF NOT EXISTS shogun_rev.roleclasspermissions_rev (
id BIGINT,
rev INTEGER REFERENCES shogun_rev.revinfo (rev),
revtype SMALLINT,
created TIMESTAMP WITHOUT TIME ZONE,
modified TIMESTAMP WITHOUT TIME ZONE,
class_name TEXT,
permission_id BIGINT,
role_id BIGINT,
created_mod BOOLEAN,
modified_mod BOOLEAN,
class_name_mod BOOLEAN,
permission_id_mod BOOLEAN,
permission_mod BOOLEAN,
role_id_mod BOOLEAN,
role_mod BOOLEAN,
PRIMARY KEY (id, rev)
);

CREATE TABLE IF NOT EXISTS shogun_rev.roleinstancepermissions_rev (
id BIGINT,
rev INTEGER REFERENCES shogun_rev.revinfo (rev),
revtype SMALLINT,
created TIMESTAMP WITHOUT TIME ZONE,
modified TIMESTAMP WITHOUT TIME ZONE,
entity_id BIGINT,
permission_id BIGINT,
role_id bigint,
created_mod BOOLEAN,
modified_mod BOOLEAN,
entity_id_mod BOOLEAN,
permission_id_mod BOOLEAN,
permission_mod BOOLEAN,
role_id_mod BOOLEAN,
role_mod BOOLEAN,
PRIMARY KEY (id, rev)
);
2 changes: 2 additions & 0 deletions shogun-config/src/main/resources/application-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ controller:
enabled: true
resource:
enabled: true
roles:
enabled: true

upload:
file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
@Log4j2
public abstract class BaseFileController<T extends BaseFileService<?, S>, S extends File> extends BasePermissionController<T, S> {

@Value("${upload.basePath}")
protected String uploadBasePath;

@GetMapping
@ResponseStatus(HttpStatus.OK)
public Page<S> findAll(@PageableDefault(Integer.MAX_VALUE) @ParameterObject Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* SHOGun, https://terrestris.github.io/shogun/
*
* Copyright © 2024-present terrestris GmbH & Co. KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* 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 de.terrestris.shogun.lib.controller;

import de.terrestris.shogun.lib.model.Role;
import de.terrestris.shogun.lib.service.RoleService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/roles")
@ConditionalOnExpression("${controller.roles.enabled:true}")
@Tag(
name = "Roles",
description = "The endpoints to manage roles"
)
@SecurityRequirement(name = "bearer-key")
public class RoleController extends BaseController<RoleService, Role> { }
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ public void handleKeyCloakEvent(@RequestBody KeycloakEventDto event) {
));
}
}
case "REALM_ROLE" -> {
if (StringUtils.equals(eventType, "CREATE")) {
applicationEventPublisher.publishEvent(new KeycloakEvent(
this,
KeycloakEventType.REALM_ROLE_CREATED,
split[1]
));
} else if (StringUtils.equals(eventType, "DELETE")) {
applicationEventPublisher.publishEvent(new KeycloakEvent(
this,
KeycloakEventType.REALM_ROLE_DELETED,
split[1]
));
}
}
case "REALM_ROLE_MAPPING", "CLIENT_ROLE_MAPPING" -> {
if (split[0].equals("users")) {
applicationEventPublisher.publishEvent(new KeycloakEvent(
Expand Down
Loading

0 comments on commit 48042db

Please sign in to comment.