A centralized dashboard helps manage user roles and permissions efficiently across an organization. Let’s build one using Firebird and Spring Boot.
1. Add Dependencies
In your
pom.xml, include these:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
<artifactId>jaybird</artifactId>
<version>5.0.3</version>
</dependency>
2. Configure Firebird Connection
spring.datasource.url=jdbc:firebirdsql://localhost:3050/D:/data/rolesdb.fdb
spring.datasource.username=sysdba
spring.datasource.password=masterkey
spring.jpa.hibernate.ddl-auto=update
spring.thymeleaf.cache=false
3. Define Entities
@Entity
public class Role {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String description;
}
@Entity
public class User {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
@ManyToMany(fetch = FetchType.EAGER)
private Set<Role> roles;
}
4. Create Repositories
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUsername(String username);
}
public interface RoleRepository extends JpaRepository<Role, Long> {}
5. Build the Dashboard Controller
@Controller
@RequestMapping("/dashboard")
public class DashboardController {
@Autowired private UserRepository userRepo;
@Autowired private RoleRepository roleRepo;
@GetMapping
public String viewDashboard(Model model) {
model.addAttribute("users", userRepo.findAll());
model.addAttribute("roles", roleRepo.findAll());
return "dashboard";
}
@PostMapping("/assign")
public String assignRole(@RequestParam Long userId, @RequestParam Long roleId) {
User user = userRepo.findById(userId).orElseThrow();
Role role = roleRepo.findById(roleId).orElseThrow();
user.getRoles().add(role);
userRepo.save(user);
return "redirect:/dashboard";
}
}
6. Create a Simple HTML Dashboard
dashboard.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Role Management Dashboard</title>
</head>
<body>
<h2>Users</h2>
<table>
<tr><th>Username</th><th>Roles</th><th>Assign</th></tr>
<tr th:each="u : ${users}">
<td th:text="${u.username}"></td>
<td th:text="${#strings.listJoin(u.roles.stream().map(r->r.name).toList(), ', ')}"></td>
<td>
<form th:action="@{/dashboard/assign}" method="post">
<input type="hidden" name="userId" th:value="${u.id}">
<select name="roleId" th:each="r : ${roles}" th:value="${r.id}" th:text="${r.name}"></select>
<button type="submit">Assign</button>
</form>
</td>
</tr>
</table>
</body>
</html>
7. Security Configuration
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.csrf().disable()
.authorizeHttpRequests()
.requestMatchers("/dashboard/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.build();
}
}
8. Run and Manage
Run the app, log in as an admin, and visit
/dashboard.
You can assign roles to users dynamically. All updates are stored in Firebird instantly and displayed on the dashboard in real time.
image quote pre code