We are going to implement Admin User Forgot Password functionality where we need to send the Password Reset link to User email address. So let us look at how to configure Email server and send emails. Spring provides support for sending Emails using JavaMailSender. SpringBoot makes it even easier by providing a starter for emailing support. As we need Emailing feature in both Admin and ShoppingCart modules, we will implement the emailing functionality in jcart-core module.
Continue reading »JCart: Configuring Spring Security
Our JCart Administration site should only be accessible to authorized users only. So, we are going to use SpringSecurity to define the security constraints. Let us add the following spring-security dependencies to jcart-admin/pom.xml. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity4</artifactId> </dependency> If we have predefined set of Roles then we can specify the URL patterns and its required Roles something like this: http .authorizeRequests() .antMatchers("/login","/login/form**","/register","/logout").permitAll() .antMatchers("/admin","/admin/**").hasRole("ADMIN") .anyRequest().authenticated() .and() But we need provision to dynamically create new roles as well, hence we can’t statically define constraints using role names.
Continue reading »JCart: Admin UI Layout SetUp
As I am not really a good UI designer I searched for a free good looking UI website Admin templates and I found this fantastic template https://almsaeedstudio.com/preview. We will be using this template for our Administration web application. We are going to use Thymeleaf templates for our View layer. Thymeleaf offers facelets style templating mechanism. Basically we need 2 layout templates, one for unauthorized views like Login/ForgotPassword etc and another for authorized users.
Continue reading »JCart: Create JPA Entities
We are going to create the JPA Entities for the database tables we designed. @Entity @Table(name="users") public class User { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; @Column(nullable=false) @NotEmpty() private String name; @Column(nullable=false, unique=true) @NotEmpty @Email(message="{errors.invalid_email}") private String email; @Column(nullable=false) @NotEmpty @Size(min=4) private String password; private String passwordResetToken; @ManyToMany(cascade=CascadeType.MERGE) @JoinTable( name="user_role", joinColumns={@JoinColumn(name="USER_ID", referencedColumnName="ID")}, inverseJoinColumns={@JoinColumn(name="ROLE_ID", referencedColumnName="ID")}) private List<Role> roles; //setters & getters } @Entity @Table(name="roles") public class Role { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; @Column(nullable=false, unique=true) @NotEmpty private String name; @Column(length=1024) private String description; @ManyToMany(mappedBy="roles") private List<User> users; @ManyToMany @JoinTable( name="role_permission", joinColumns={@JoinColumn(name="ROLE_ID", referencedColumnName="ID")}, inverseJoinColumns={@JoinColumn(name="PERM_ID", referencedColumnName="ID")}) private List<Permission> permissions; //setters & getters } @Entity @Table(name="permissions") public class Permission { @Id @GeneratedValue(strategy=GenerationType.
Continue reading »JCart: Domain Modelling and Database Designing
While developing database driven applications using some ORM framework, some people prefer Object first approach and others follow DB first approach. I prefer DB first approach. So, let us start listing down all the domain entities in our JCart application domain. Product Category Customer Order OrderItem Cart Address User Role Permission Let us create the database tables as follows: Though we identified Cart as a domain entity, we are not creating the table for holding the Cart details.
Continue reading »JCart: Initial Code SetUp
Let us create a root pom type maven project with 3 sub-modules jcart-core, jcart-admin and jcart-site. jcart-core module will contain all the core logic excluding web related stuff. jcart-admin module will contain all the administration related web functionality like Controllers, Security, Validators etc. jcart-site module will contain all the shoppingcart related web functionality like Controllers, Security, Validators etc. All these modules use SpringBoot, but as of now STS/IntellijIdea are not providing option to create multi-module SpringBoot application, we will be creating Maven modules and then configure SpringBoot dependencies manually.
Continue reading »Selecting The Technology Stack for JCart
Selecting the right technology stack is very crucial and plays an important role in project success. Many of the architects (unknowingly??!!) try to make complex designs by trying to use all kinds of latest and greatest stuff. On the other hand some architects try to be in their comfort zone by limiting their technology stack to the technologies with which they are comfortable. Both approaches are dangerous. One should understand the business needs and pick the technologies that are necessary for project.
Continue reading »Developing a simple e-commerce application from scratch to production using SpringBoot
We can find plenty of information on any technical topic, be it Java, .NET, Python or any frameworks like Spring, Hibernate, CDI, JSF etc. You can find hundreds of well written blogs on many of these topics. For example, you can find lot of tutorials on how to use SpringBoot or how to use various mappings in JPA/Hibernate or how to do form validations in JSF etc. Also, there are plenty of books published by well established publishers on most of the technologies.
Continue reading »