Entity for user added

This commit is contained in:
MathewFrancis 2025-05-09 15:56:06 +05:30
parent 095975712f
commit b87c2b6f7b
12 changed files with 246 additions and 0 deletions

View File

@ -0,0 +1,94 @@
USE asterisk_db;
SHOW DATABASES;
SHOW TABLES;
SELECT * FROM `ps_endpoints`;
DELETE FROM `ps_endpoints` WHERE `id` = '1004';
SELECT * FROM `extensions_table`;
DESCRIBE `extensions_table`;
ALTER TABLE `extensions_table`
ADD CONSTRAINT `extension_table_unique_val_two_check` UNIQUE (`exten`, `appdata`);
ALTER TABLE `extensions_table`
DROP INDEX `extension_table_unique_val`;
ALTER TABLE `extensions_table`
ADD CONSTRAINT `extension_table_unique_val` UNIQUE (`exten`, `appdata`, `priority`);
DELETE FROM `extensions_table` WHERE priority = 4 and exten = "1005" ;
DELETE FROM `extensions_table` WHERE exten = "1005" OR exten = "1004";
DELETE FROM `ps_endpoints` WHERE id = "1004" OR id = "1005";
DELETE FROM `extensions_table` WHERE exten = "1004" OR exten = "1005";
DELETE FROM `ps_auths` WHERE id = "1004" OR id = "1005";
DELETE FROM `ps_aors` WHERE id = "1004" OR id = "1005";
SELECT * FROM `extensions_table` WHERE app = "Dial";
SELECT * FROM extensions_table WHERE context = 'default' AND exten = '1005';
SELECT * FROM extensions_table WHERE exten = '1004' AND context = 'default';
SELECT * FROM `ps_endpoints`;
SELECT * FROM `extensions_table`;
--
SELECT * FROM ps_auths;
SELECT * FROM ps_aors;
DESCRIBE `ps_auths`;
DESCRIBE `ps_aors`;
DESCRIBE `extensions_table`;
INSERT INTO `ps_aors`(`id`,`max_contacts`) VALUES ("1004", 1);
INSERT INTO `ps_auths`(`id`, `auth_type`, `username`, `password`, `md5_cred`, `realm`) VALUES("1004", "userpass", "1004", "12345", null, null);
-- USER ROLES ROLE GOES HERE
CREATE TABLE `roles`(
`role_id` INTEGER NOT NULL AUTO_INCREMENT,
`role_name` VARCHAR(20) UNIQUE NOT NULL,
CONSTRAINT `roles_pk` PRIMARY KEY (`role_id`)
)ENGINE = 'Innodb' AUTO_INCREMENT = 1, DEFAULT CHARSET 'latin1';
DESCRIBE `roles`;
CREATE TABLE `user_roles`(
`u_id` INTEGER NOT NULL,
`role_id` INTEGER NOT NULL,
CONSTRAINT `user_roles_pk` PRIMARY KEY(`u_id`,`role_id`)
)ENGINE = 'Innodb' AUTO_INCREMENT = 1, DEFAULT CHARSET 'latin1';
-- foreign key to be added to this table in alter table form
CREATE TABLE `user`(
`u_id` INTEGER NOT NULL AUTO_INCREMENT,
`user_name` VARCHAR(70) UNIQUE NOT NULL,
`password` VARCHAR(68) NOT NULL,
-- fk to uder_account
CONSTRAINT `user_table_pk` PRIMARY KEY(`u_id`)
)ENGINE = 'Innodb', AUTO_INCREMENT = 1, DEFAULT CHARSET 'latin1';
ALTER TABLE `user_roles` ADD CONSTRAINT `user_lones_U_fk_to_user` FOREIGN KEY(`u_id`) REFERENCES `user`(`u_id`);
ALTER TABLE `user_roles` ADD CONSTRAINT `user_lones_R_fk_to_user` FOREIGN KEY(`role_id`) REFERENCES `roles`(`role_id`);
DESC `user_roles`;
INSERT `roles`(`role_name`) VALUES ('ROLE_admin');

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,11 @@
package com.example.cezenPBX.config;
import org.springframework.context.annotation.Configuration;
// this class will handel the routs that are protected and
// allow spring security to accept login details from our custom login page
@Configuration
public class CezenLoginSecurityChain {
}

View File

@ -0,0 +1,64 @@
package com.example.cezenPBX.entity.user;
import jakarta.persistence.*;
import java.util.Collection;
@Entity
@Table(name = "role")
final public class Role {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "role_id")
private int id;
//remember ROLE_
@Column(name = "role_name")
private String role;
//all employees under this role
@ManyToMany(
fetch = FetchType.LAZY,
cascade = {
//The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context.
CascadeType.DETACH,
CascadeType.MERGE,
CascadeType.PERSIST,
CascadeType.REFRESH,
}
//cascade = CascadeType.ALL
)
@JoinTable(
name = "user_roles",
joinColumns = @JoinColumn(name = "u_id"),
inverseJoinColumns = @JoinColumn(name = "role_id")
)
private Collection<UserEntity> employees;
public Role(){}
public Role(String role) {
this.role = role;
}
public int getId() {
return id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public Collection<UserEntity> getEmployees() {
return employees;
}
public void setEmployees(Collection<UserEntity> employees) {
this.employees = employees;
}
}

View File

@ -0,0 +1,77 @@
package com.example.cezenPBX.entity.user;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import java.util.Collection;
import java.util.HashSet;
@Entity
@Table(name = "user")
final public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "u_id")
private int id;
@Column(name = "user_name")
private String userName;
@JsonIgnore
@Column(name = "password")
private String password;
//ROLE
@ManyToMany(
fetch = FetchType.LAZY,
cascade = {
//The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context.
CascadeType.DETACH,
CascadeType.MERGE,
CascadeType.PERSIST,
CascadeType.REFRESH,
}
//cascade = CascadeType.ALL
)
@JoinTable(
name = "user_roles",
joinColumns = @JoinColumn(name = "u_id"),
inverseJoinColumns = @JoinColumn(name = "role_id")
)
private Collection<Role> roles;
public UserEntity(){}
public UserEntity(String userName, String password) {
this.userName = userName;
this.password = password;
}
public int getId() {
return id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Collection<Role> getRoles() {
return roles;
}
public void setARole(Role role){
if(this.roles == null){
this.roles = new HashSet<Role>();
}
this.roles.add(role);
}
}