Skip to content

Commit

Permalink
security module improvements (#19)
Browse files Browse the repository at this point in the history
* security module improvements

* improve names of food products categories

---------

Co-authored-by: Myller Sakaguchi Lobo <myller.lobo@omni.com.br>
  • Loading branch information
msakaguchi and Myller Sakaguchi Lobo authored Jul 31, 2024
1 parent 3efbfa9 commit da11458
Show file tree
Hide file tree
Showing 39 changed files with 506 additions and 610 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fiap.tc.adapter.repository;

import com.fiap.tc.adapter.repository.entity.core.UserEntity;
import com.fiap.tc.adapter.repository.entity.security.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
Expand All @@ -14,7 +14,7 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {

Optional<UserEntity> findByLogin(String login);

@Query(nativeQuery = true, value = "SELECT p.id FROM seguranca.usuario u JOIN seguranca.usuario_perfil up ON u.id = up.id_usuario JOIN seguranca.perfil pa ON up.id_perfil = pa.id JOIN seguranca.perfil_permissao pp ON up.id_perfil = pp.id_perfil JOIN seguranca.permissao p ON pp.id_permissao = p.id WHERE u.id = :id ORDER BY p.id")
@Query(nativeQuery = true, value = "select p.id from security.user_system u join security.user_profile up on u.id = up.id_user join security.profile pf on up.id_profile = pf.id join security.roles_profile rp on up.id_profile = rp.id_profile join security.role p on rp.id_role = p.id where u.id = :id order by p.id")
Collection<String> getRoles(Long id);

}

This file was deleted.

This file was deleted.

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/com/fiap/tc/adapter/repository/entity/core/Role.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fiap.tc.adapter.repository.entity.security;

import lombok.Data;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "feature", schema = "security")
@Data
public class FeatureEntity {

@Id
private String id;

@Column(name = "name")
private String name;

@Column(name = "description")
private String description;

@Column(name = "active", columnDefinition = "boolean default true")
private boolean active;

@ManyToOne
@JoinColumn(name = "id_system_module")
private ModuleEntity module;

@OneToMany(mappedBy = "feature")
private List<RoleEntity> roles;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.fiap.tc.adapter.repository.entity.security;

import lombok.Data;

import javax.persistence.*;

@Entity
@Table(name = "system_module", schema = "security")
@Data
public class ModuleEntity {

@Id
private String id;

@Column(name = "name")
private String name;

@Column(name = "description")
private String description;

@ManyToOne
@JoinColumn(name = "id_system")
private SystemEntity system;

@Column(name = "active", columnDefinition = "boolean default true")
private boolean active;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.fiap.tc.adapter.repository.entity.security;

import com.fiap.tc.core.domain.enums.ProfileSystem;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

import static java.lang.String.format;

@Entity
@Data
@Table(name = "profile", schema = "security")
public class ProfileEntity implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@Enumerated(EnumType.STRING)
private ProfileSystem id;

@Column(name = "name")
private String name;

@Column(name = "description")
private String description;

@Column(name = "active", columnDefinition = "boolean default true")
private boolean active;

@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "roles_profile", schema = "security",
joinColumns = {@JoinColumn(name = "id_profile")},
inverseJoinColumns = {@JoinColumn(name = "id_role")}
)
private Set<RoleEntity> roles;

@Override
public String toString() {
return format("Profile{id:%s, nome:%s}", id, name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.fiap.tc.adapter.repository.entity.security;

import lombok.Data;

import javax.persistence.*;

@Entity
@Table(name = "role", schema = "security")
@Data
public class RoleEntity {

@Id
private String id;

@Column(name = "name")
private String name;

@Column(name = "description")
private String description;

@Column(name = "active", columnDefinition = "boolean default true")
private boolean active;

@ManyToOne
@JoinColumn(name = "id_feature")
private FeatureEntity feature;

}
Loading

0 comments on commit da11458

Please sign in to comment.