Skip to content

Fix issues #129, #130, #94, #106, #105, #126 - #137

Open
Snehil208001 wants to merge 3 commits into
jaygajera17:masterfrom
Snehil208001:fix-issues-129-130-94-106-105-126
Open

Snehil208001 wants to merge 3 commits into
jaygajera17:masterfrom
Snehil208001:fix-issues-129-130-94-106-105-126

Conversation

@Snehil208001

@Snehil208001 Snehil208001 commented Mar 9, 2026 •

Copy link
Copy Markdown

Additional: AdminDataLoader for BCrypt admin password, fix SecurityConfiguration UserDetailsService

…a17#106, jaygajera17#105, jaygajera17#126

- jaygajera17#129: Add delete/toggleActive functionality for customers (AdminCustomerController)
- jaygajera17#130: Add isActive boolean flag in User model with soft delete and security checks
- jaygajera17#94: Fix Update Product Details (AdminProductController, productsUpdate.jsp)
- jaygajera17#106: Fix misaligned login button on mobile (adminlogin.jsp CSS)
- jaygajera17#105: Add Dockerfile and docker-compose.yml for easier setup
- jaygajera17#126: Split Admin controller into AdminController, AdminCategoryController, AdminProductController, AdminCustomerController

Additional: AdminDataLoader for BCrypt admin password, fix SecurityConfiguration UserDetailsService
Made-with: Cursor
@Snehil208001
Snehil208001 force-pushed the fix-issues-129-130-94-106-105-126 branch from ec40169 to 2fda2e0 Compare March 9, 2026 08:38
@Snehil208001

Copy link
Copy Markdown
Author

Testing instructions

Setup:

  1. Configure application.properties with your MySQL credentials (db.url, db.username, db.password)
  2. Run basedata.sql on your database, or use insert_admin.sql if the customer table is empty
  3. If admin login fails, run fix_admin_password.sql to set BCrypt hash for admin/123

Admin login: admin / 123
User login: lisa / 765

Docker: docker-compose up from project root (requires MySQL running or use the compose MySQL service)

Verified: All Maven tests pass locally.

@Snehil208001

Copy link
Copy Markdown
Author

Key files changed

Issue Files
#129, #130 AdminCustomerController.java, displayCustomers.jsp, User.java
#94 AdminProductController.java, productsUpdate.jsp
#106 adminlogin.jsp
#105 Dockerfile, docker-compose.yml, .dockerignore
#126 AdminCategoryController.java, AdminProductController.java, AdminCustomerController.java (split from AdminController)
Security SecurityConfiguration.java, AdminDataLoader.java

@jaygajera17

Copy link
Copy Markdown
Owner

Thanks @Snehil208001 , I'll check this

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses several admin-panel and infrastructure issues by introducing customer soft-deactivation (isActive), splitting the monolithic admin controller into focused controllers, fixing product update UI behavior, improving the admin login mobile layout, and adding Docker/Docker Compose setup for easier local deployment.

Changes:

  • Add customer isActive flag with admin toggle/deactivation endpoints and active-account enforcement during authentication.
  • Split admin functionality into AdminController, AdminCategoryController, AdminProductController, and AdminCustomerController.
  • Add Dockerfile + docker-compose for running the app with MySQL, and adjust SQL seed/config to support BCrypt admin login.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 19 comments.

Show a summary per file
File Description
docker-compose.yml Adds MySQL + app services for containerized local runs.
JtProject/Dockerfile Adds multi-stage Maven build and runtime image.
JtProject/.dockerignore Reduces Docker build context size.
JtProject/src/main/resources/application.properties Adjusts Hibernate/db properties and package scanning.
JtProject/basedata.sql Updates schema/seed (DB name, is_active, BCrypt admin password).
JtProject/insert_admin.sql Adds a standalone admin insert script.
JtProject/fix_admin_password.sql Adds a standalone admin BCrypt password fix script.
JtProject/src/main/java/.../models/User.java Introduces isActive column/field.
JtProject/src/main/java/.../dao/userDao.java Adds soft delete/toggle/get-by-id DAO operations.
JtProject/src/main/java/.../services/userService.java Exposes new user management service methods.
JtProject/src/main/java/.../configuration/SecurityConfiguration.java Permits admin login processing URL and blocks inactive users.
JtProject/src/main/java/.../config/AdminDataLoader.java Attempts to enforce BCrypt admin password on startup.
JtProject/src/main/java/.../HibernateConfiguration.java Adds an entityManagerFactory bean for JPA integration.
JtProject/src/main/java/.../controller/AdminController.java Removes direct JDBC usage; uses service + encoder for profile updates.
JtProject/src/main/java/.../controller/AdminCategoryController.java Extracts category admin endpoints.
JtProject/src/main/java/.../controller/AdminProductController.java Extracts product admin endpoints + fixes update flow.
JtProject/src/main/java/.../controller/AdminCustomerController.java Extracts customer admin endpoints (toggle/deactivate).
JtProject/src/main/webapp/views/productsUpdate.jsp Fixes product update form bindings (category select, description, image).
JtProject/src/main/webapp/views/displayCustomers.jsp Adds Active/Inactive display and Activate/Deactivate action.
JtProject/src/main/webapp/views/adminlogin.jsp CSS tweaks to improve mobile layout.
.gitignore Adds cookies.txt to ignored files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +38
@GetMapping("customers/delete")
public String deleteCustomer(@RequestParam("id") int id) {
this.userService.deleteUser(id);
return "redirect:/admin/customers";
}

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This endpoint changes customer state via GET. With CSRF disabled, this is CSRF-able and can be triggered unintentionally (prefetch/crawlers). Prefer POST/DELETE for non-idempotent actions and re-enable CSRF protection.

Copilot uses AI. Check for mistakes.
Comment on lines +56 to 58
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description/issue #129 mentions adding delete functionality for customers, but the UI now only provides Activate/Deactivate and no Delete action. If “delete” is intended to be a soft delete, consider labeling it accordingly (Deactivate) and remove the unused /customers/delete endpoint; otherwise, add the missing Delete action to the table.

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compose doesn’t mount any init SQL into the MySQL container (e.g., /docker-entrypoint-initdb.d). As a result, a fresh Docker run won’t have base tables/admin user unless Hibernate creates them and you seed data manually. Consider mounting basedata.sql (and/or an admin seed) as an init script volume.

Suggested change
- mysql_data:/var/lib/mysql
- mysql_data:/var/lib/mysql
- ./basedata.sql:/docker-entrypoint-initdb.d/basedata.sql:ro

Copilot uses AI. Check for mistakes.
import java.util.Properties;

import javax.sql.DataSource;
import javax.persistence.EntityManagerFactory;

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import javax.persistence.EntityManagerFactory; is added but not used in this class. Removing unused imports keeps the configuration class easier to maintain and avoids confusion about which persistence API is intended here.

Suggested change
import javax.persistence.EntityManagerFactory;

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +43
@GetMapping("customers/toggleActive")
public String toggleCustomerActive(@RequestParam("id") int id) {
this.userService.toggleUserActive(id);
return "redirect:/admin/customers";

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This endpoint changes customer state via GET. With CSRF disabled, this is CSRF-able and can be triggered unintentionally (prefetch/crawlers). Prefer POST/PATCH for non-idempotent actions and re-enable CSRF protection.

Copilot uses AI. Check for mistakes.
Comment thread JtProject/basedata.sql
Comment on lines +37 to +41
# insert default customers (BCrypt: admin=123)
# For lisa=765, register via /register or update password in DB with BCrypt hash
INSERT INTO CUSTOMER(address, email, password, role, username, is_active) VALUES
('123, Albany Street', 'admin@nyan.cat', '$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG', 'ROLE_ADMIN', 'admin', 1),
('765, 5th Avenue', 'lisa@gmail.com', '765', 'ROLE_NORMAL', 'lisa', 1);

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default user lisa is inserted with a plain-text password ('765'), but authentication now uses BCryptPasswordEncoder, which will reject non-BCrypt stored values and break login. Store a BCrypt hash for lisa too (or remove the credential from the default dataset/docs).

Suggested change
# insert default customers (BCrypt: admin=123)
# For lisa=765, register via /register or update password in DB with BCrypt hash
INSERT INTO CUSTOMER(address, email, password, role, username, is_active) VALUES
('123, Albany Street', 'admin@nyan.cat', '$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG', 'ROLE_ADMIN', 'admin', 1),
('765, 5th Avenue', 'lisa@gmail.com', '765', 'ROLE_NORMAL', 'lisa', 1);
# insert default customers (BCrypt: admin=123, lisa=765)
# Both default customer passwords are stored as BCrypt hashes for compatibility with BCryptPasswordEncoder
INSERT INTO CUSTOMER(address, email, password, role, username, is_active) VALUES
('123, Albany Street', 'admin@nyan.cat', '$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG', 'ROLE_ADMIN', 'admin', 1),
('765, 5th Avenue', 'lisa@gmail.com', '$2a$10$7EqJtq98hPqEX7fNZaFWoOHiWqD3oB8LE6wS6vKrrf5wM9vY7Gk8W', 'ROLE_NORMAL', 'lisa', 1);

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +27
User admin = userService.getUserByUsername("admin");
if (admin != null && !passwordEncoder.matches("123", admin.getPassword())) {
admin.setPassword(passwordEncoder.encode("123"));
admin.setActive(true);

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding the admin username/password here (admin / 123) effectively resets credentials at startup and is unsafe outside local/dev usage. Gate this behind an explicit property/profile and source the password from configuration rather than embedding it in code.

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +29
@Override
public void run(String... args) {
try {
User admin = userService.getUserByUsername("admin");
if (admin != null && !passwordEncoder.matches("123", admin.getPassword())) {
admin.setPassword(passwordEncoder.encode("123"));
admin.setActive(true);
userService.updateUser(admin);
System.out.println(">>> Admin password updated. Login with admin/123");

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passwordEncoder.matches("123", admin.getPassword()) can throw if the stored password is not a BCrypt hash (e.g., legacy plain-text), and the catch will skip fixing the admin account. Handle non-BCrypt stored values deterministically (e.g., detect hash prefix and force-encode) rather than relying on matches alone.

Suggested change
@Override
public void run(String... args) {
try {
User admin = userService.getUserByUsername("admin");
if (admin != null && !passwordEncoder.matches("123", admin.getPassword())) {
admin.setPassword(passwordEncoder.encode("123"));
admin.setActive(true);
userService.updateUser(admin);
System.out.println(">>> Admin password updated. Login with admin/123");
private boolean isBcryptHash(String password) {
return password != null
&& (password.startsWith("$2a$")
|| password.startsWith("$2b$")
|| password.startsWith("$2y$"));
}
@Override
public void run(String... args) {
try {
User admin = userService.getUserByUsername("admin");
if (admin != null) {
String storedPassword = admin.getPassword();
boolean passwordMatches = isBcryptHash(storedPassword)
&& passwordEncoder.matches("123", storedPassword);
if (!passwordMatches) {
admin.setPassword(passwordEncoder.encode("123"));
admin.setActive(true);
userService.updateUser(admin);
System.out.println(">>> Admin password updated. Login with admin/123");
}

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +65
model.addAttribute("userid", user.getId());
model.addAttribute("username", user.getUsername());
model.addAttribute("email", user.getEmail());
model.addAttribute("password", user.getPassword());
model.addAttribute("address", user.getAddress());

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

profileDisplay is putting the stored password hash into the model (password), and updateProfile.jsp uses it to pre-fill the password field. Submitting the form will re-encode an already-encoded value and effectively change the password (locking the user out). Don’t send any password (even hashed) to the view; only encode/update when the user explicitly provides a new password.

Copilot uses AI. Check for mistakes.
@jaygajera17

Copy link
Copy Markdown
Owner

@Snehil208001 can you please change the base branch to master

@Snehil208001
Snehil208001 changed the base branch from master2 to master April 21, 2026 11:13
Snehil208001 and others added 2 commits April 21, 2026 16:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants