SpringSecurity4,Primefaces5,SpringDataJPA
and Hibernate4 CRUD Application Using Netbeans8.2 IDE and MySQL Database
Server
This simple
application is a Create, Retrieve, Update and Delete (CRUD) application
operating on an ‘employee’ table in ‘springdatacruddb’ database in MySQL
Database Server. It is a SpringSecurity, Spring, SpringDataJPA and
Hibernate-annotation based application.It is of XML based configuration.
Project can also be developed using Eclipse.
For Java Based Configuration Please look at the blog post at below URL
https://raichand-java.blogspot.in/2017/02/springsecurity4primefaces5springdatajpa.html
For Integrating maven pom.xml of this project is available at the end of this post.
Project can also be developed using Eclipse.
For
SpringSecurity4,Primefaces5,SpringDataJPA and Hibernate4 User Registration
Application Please look at the blog post at below URL
https://raichand-java.blogspot.in/2017/06/springsecurity4primefaces5springdatajpa.html
For Java Based Configuration Please look at the blog post at below URL
https://raichand-java.blogspot.in/2017/02/springsecurity4primefaces5springdatajpa.html
For Integrating maven pom.xml of this project is available at the end of this post.
Security is of critical importance to all web applications. Vulnerable applications are easy prey for hackers. Spring Security is a Java/Java EE framework that provides authentication, authorization and other security features for java language based enterprise applications. It is operating system independent, works on various kinds of operating system. On 1st September 2016 the latest stable version of spring -Security is 4.1.3.Spring- Security version 4.1.1 is used in this application.
·
Spring Security Features
1. Comprehensive and extensible support
for both Authentication and Authorization.
2. Protection against attacks like
session fixation, clickjacking, cross site request forgery (CSRF), etc.
3. Servlet API integration.
4. Optional integration with Spring MVC
and supports more frameworks.
This is a web
security (Login Logout and Remember me) CRUD application operating on employee,
users and user_roles tables in ‘springdatacruddb’ database in MySQL Database Server.
It is a Hibernate-Annotation
and Spring
Xml based application. Different persons with different authorisation
(e.g. user or admin) view different web pages according to authorisation after logging in.
Steps of Authentication mechanism
1. User
submits his credentials to the system; that is, a username and password.
2.
org.springframework.security.authentication.
UsernamePasswordAuthenticationToken
accepts the credentials and passes them
to org.springframework.security.authentication.AuthenticationManager for
validation.
3. System
authenticates the user.
4.
Credential flows as follows: UsernamePasswordAuthenticationTokenà
AuthenticationManager
à
Authentication.
5. Finally
a fully loaded authentication instance is returned.
6.
SecurityContextHolder accepts the authentication instance.
7. The
system also checks for authorization of roles or groups.
8. Finally, the user is allowed to
access the system based on his authorization.
Remember-me
functionality enables a user to keep logged-in.
Basically
remember me functionality does 2 things
1.In Remember-me or persistent-login authentication, Applications remember the identity of user between sessions. In our
application we provide an option, usually checkbox, to the user to select
remember-me and if the user checks it then after successful login, spring
application sends a remember-me browser cookie to the browser in addition to
session cookie.This cookie will be stored at browser side and will remain there for certain period(defined by cookie lifetime).
"rememeber-me"
browser cookie is created with a token based on username,password ( token can
be computed and persisted in database if needed or it can be on the fly computed hash
of user’s password).
2.When the
user tries to access the secured page without any session (session is expired
because of timeout), then Remember-Me service will try to autoLogin the user by
retrieving the user details from the remember-me cookie and can verify user
details if needed.User will be automatically logged in, without providing userid/password. Spring performs remember-me functionality by creating token
using authentication details.
Software
Used
1.JDK8u25
2.Netbeans
8.2
3.MySQL 5.*
Database Server(or XAMPP-For easy MySQL Management)
4.MySQL
Connector 5.*
5.Hibernate
4.3.** and Primefaces 5.0(Bundled with Netbeans)
6.Spring4.3.2
7.Spring
Security 4.1.1
Steps
1.Install
JDK8 or Jdk7 if not installed
2.Install
Netbeans and associated ApacheTomcat Server
3.Install MySQL Database server or XAMPP(For easy
management of MySQL ) .
After
Installing Netbeans click the services tab on the left.Expand Database node.
Expand Drivers node. Right click MySQL(Connector/Jdriver) then connect. Put
springdatacruddb as the database. As shown below. Put password if you have
given password at the time of installation of MySQL database server. For XAMPP no password is required. Then test connection.
If successful click finish button.
Create user
table by running below SQL in ‘springdatacruddb’ database
CREATE TABLE
IF NOT EXISTS `employee` (
`EmpId` int(15) NOT NULL,
`FirstName` varchar(25) NOT NULL,
`LastName` varchar(25) NOT NULL,
`Salary` int(20) NOT NULL,
`Sex` varchar(15) NOT NULL,
`DOB` date NOT NULL,
`Remark` varchar(50) NOT NULL
)
ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE
`employee` ADD PRIMARY KEY (`EmpId`);
INSERT INTO `employee` (`EmpId`, `FirstName`, `LastName`,
`Salary`, `Sex`, `DOB`, `Remark`) VALUES
(1, 'Andrei', 'Agassi', 1000000, 'Male', '1976-06-15', 'Very
Good Tennis Player'),
(2, 'Martina', 'Navratilova', 60000000, 'Female',
'1978-12-15', 'Very Good Tennis Player'),
(3, 'Venus', 'Williams', 7000000, 'Female', '1975-12-21',
'Very Goog Tennis Player'),
(4, 'Roger', 'Fedrer', 600000, 'Male', '1987-12-20', 'Very
Good Tennis Player'),
(5, 'Lindsay', 'Devonport', 600000, 'Female', '1974-12-14',
'Very good Tennis Player '),
(6, 'Serena', 'Williams', 600000, 'Female', '1988-12-16',
'Very Good Tennis Player'),
(7, 'Barak', 'Obama', 5463216, 'Male', '1961-12-18',
'Ex-President USA'),
(8, 'Mary', 'Pierce', 8654321, 'Female', '1993-06-14', 'Very
Good Tennis Player'),
(9, 'Rafel', 'Nadal', 754321, 'Male', '1991-04-12', 'Very
Goog Tennis Player'),
(10, 'Sir Donald', 'Bradman', 650000, 'Male', '1942-05-06',
'Very Good Cricket Bowler'),
(11, 'Usin', 'Bolt', 690700, 'Male', '1998-12-16',
'Olympics Gold Medalist in Athletics'),
(12, 'Micheal', 'Phelps', 765000, 'Male', '1992-12-22',
'Olympics Gold Medalist in Swimming.USA
Citizen.'),
(13, 'Andy', 'Moore', 750000, 'Male', '1991-05-09', 'Very
Goog Tennis Player'),
(14, 'Tom', 'Cruise', 7000000, 'Male', '1975-01-15', 'Good
Actor'),
(15, 'Maria', 'Sharpova', 950000, 'Female', '1978-11-21',
'Very good beautiful Tennis Player'),
(16, 'Martina',
'Hingis', 850000, 'Female', '1982-02-18', 'Very Good Tennis Player'),
(17, 'Vin', 'Diesel', 840000, 'Male', '1985-01-17', 'Very
Good Actor'),
(18, 'Angelina', 'Jolie', 7500000, 'Female', '1987-11-14',
'Very Good Actress'),
(19, 'Brad', 'Pitt', 765000, 'Male', '1979-01-24', 'Very Good
Actor');
CREATE TABLE
IF NOT EXISTS `users` (
`username` varchar(255) NOT NULL,
`password` varchar(255) DEFAULT NULL,
`enabled` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=latin1;
ALTER TABLE
`users` ADD PRIMARY KEY (`username`);
INSERT INTO
`users` (`username`, `password`, `enabled`) VALUES
('admin',
'admin123', 1),
('alex',
'alex123', 1),
('deepak',
'deepak123', 2),
('raichand70',
'jaishriram', 1);
CREATE TABLE
IF NOT EXISTS `user_roles` (
`user_role_id` int(15) NOT NULL,
`username` varchar(255) DEFAULT NULL,
`role` varchar(50) DEFAULT NULL
)
ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
ALTER TABLE
`user_roles` ADD PRIMARY KEY (`user_role_id`),
ADD KEY `FK_USERNAME` (`username`);
ALTER TABLE
`user_roles` MODIFY `user_role_id`
int(15) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5;
ALTER TABLE
`user_roles`ADD CONSTRAINT `FK_USERNAME` FOREIGN KEY (`username`) REFERENCES
`users` (`username`);
Insert these
Records below by executing below insert statement
INSERT INTO
`user_roles` (`user_role_id`, `username`, `role`) VALUES
(1, 'admin',
'ROLE_ADMIN'),
(2, 'alex',
'ROLE_USER'),
(3,
'raichand70', 'ROLE_ADMIN'),
(4,
'deepak', 'ROLE_USER');
JARS required to be added
to Libraries Folder
Right click on the Libraries folderà addJAR/Folder then add below mentioned JAR Files .
1.aopalliance-1.0.jar
2.javax.inject-1.jar
3.commons-logging-1.2.jar
4.mysql-connector-java-bin.jar
5. Jandex-2.0.3
6. spring-aop-4.3.2
7. spring-beans-4.3.2
8. spring-context-4.3.2
9. spring-core-4.3.2
10. spring-tx-4.3.2
11. spring-web-4.3.2
12. spring-expression-4.3.2
13. spring-jdbc-4.3.2
14. spring-orm-4.3.2
15. spring-security-config-4.1.1
16. spring-security-core-4.1.1
17. spring-security-web-4.1.1
18. Spring-data-commons-1.12.5
19. Spring-data-jpa-1.10.5
Creating Project SpringSecurity4SpringDataJPA
Primefaces5Hibernate4 RememberMeExample
File-àNew
ProjectàCategories-àChoose JavaWeb--àChoose WebApplicationàClick Next-àGive Project Name SpringSecurity4SpringDataJPAPrimefaces5Hibernate4RememberMeExampleà
Click NextàClick
NextàChoose Framework
First Hibernate then Java Server Faces--àClick
Component Tab-àChoose
Primefacesà Click
Finish
In the above figure Database Connection should be with ‘springdatacruddb’
database.
In the above figure Database Connection should be with ‘springdatacruddb’
database.
Download
mysql- connector-java-bin.jar add to libraries folder by right click
addJAR/Folderàadd the mysql-java-bin.jar.
Create a folder named View under Web
pages Folder.Delete welcomePrimefaces.xhtml .Create Two Folders named Secured
and UnSecured under View Folder. Create two folders named User and Admin under
Secured Folder.Admin Folder would contain crud.xhtml File. User folder would
contain add.xhtml file. UnSecured Folder would contain one file login.xhtml.
Project Structure
Creating Packages and Classes
Right click Source
Package folder and create six packages
1. com.ray.jsfbean.controller-->This
would contain JSF Managed Bean Class LoginController.java
and EmployeeBBean.java
2.
com.ray.springdatajpa.dao.repositories-àThis would contain DAO(Data Access
Object) Repositories EmployeeRepository.java and
UserRepository.java
3.com.ray.springdatajpa.exceptionàThis would contain one file EmployeeNotFoundException.java
4. com.ray.springsecurity.pojos.modelàThis would contain entity (POJO) class files Employee.java,User.java and UserRole.java. POJO Stands for Plain Old
Java Objects
5.
com.ray.springsecurity.serviceàThis would contain Spring Service class files
CustomUserDetailsService.java
,EmployeeService.java and EmployeeServiceImpl.Java.
6.
com.ray.security.custom.auth.handleràThis would contain Spring authorization
class file CustomAuthenticationHandler.java
This Class
directs the person logging in after authentication with username and password to
the authorized web page depending on authority like User or Admin.
Following Files would be created using Netbeans
1. hibernate.cfg,xml
File-Automatically generated. (It will be
used to create User.java,UserRole .java and Employee.java and then would be deleted.)
2. Reverse
Engineering File-hibernate.reveng.xml. (It will be used to create User.java,UserRole.java
and Employee.java and then would be deleted.)
3.Entity(POJO)
File-Employee.java and User.java
and UserRole.java(POJO stands for Plain Old Java Objects)
4.JSF Managed Bean File-LoginContoller.java
5.JSF Managed Bean File-EmployeeBBean.java
6.SpringService FileàCustomUserDetailsService.java,
7.EmployeeService Interface FileEmployeeService .java
8.EmployeeService Implementation FileEmployeeServiceImpl.java
5.JSF Managed Bean File-EmployeeBBean.java
6.SpringService FileàCustomUserDetailsService.java,
7.EmployeeService Interface FileEmployeeService .java
8.EmployeeService Implementation FileEmployeeServiceImpl.java
9. SpringSecurityAuthorisationHandler File CustomAuthenticationHandler.java
10.Employee
Repository File EmployeeRepository.java
11.User
Repository File UserRepository.java
12.Exception
handling File EmployeeNotFoundException.java
13. login.xhtmlàPerson
writes his/her username and password with remember me facility
14. crud.xhtml This
is displayed if the person logging in is having admin authorization.
15. add.xhtml This
is displayed if the person logging in is having user authorization. This
displays the profile of user.
16.faces-config.xml It is
to be added after creating under WEB-INF folder if not there.
17. web.xml (Automatically generated)
18. spring-security.xml This
contains Security credentials.
19. spring-database.xml This
contains database access credentials.
Add mysql- connector-java-bin.jar
to libraries if not done.
COPY
AND PASTE CODE OF THE FILE GIVEN BELOW
WHOSE CODE IS NOT GENERATED
1.Hibernate.cfg.xml File(It would be deleted after used for
creating User.java and User_Role entity
class)
As
XAMPP is used so there is no password in
the file only username is given that
is root in Hibernate.cfg.xml File.
Code:-
<?xml
version="1.0" encoding="UTF-8"?>
<!DOCTYPE
hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD
3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property
name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property
name="hibernate.connection.url">jdbc:mysql://localhost:3306/ springdatacruddb?zeroDateTimeBehavior=convertToNull</property>
<property
name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">
</property>
<property
name="hibernate.connection.pool_size">10</property>
<property
name="show_sql">true</property>
<property
name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property
name="hibernate.hbm2ddl.auto">update</property>
<mapping class="com.ray.springsecurity.pojos.model.User"/>
<mapping class="com.ray.pojos.springsecurity.model.UserRole"/>
<mapping class="com.ray.pojos.springsecurity.model.Employee"/>
<mapping class="com.ray.pojos.springsecurity.model.Employee"/>
</session-factory>
</hibernate-configuration>
2. Creating Reverse
Engineering File-àhibernate.reveng.xml(It would be deleted after used for
creating entity classes).
Right Click default package in the Source Package-ànewàchoose Hibernate Reverse
Engineering Wizardàclick
nextàchoose employee,User
and UserRole tableàAdd àclick finish.
CODE:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC
"-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection
match-catalog=" springdatacruddb "/>
<table-filter
match-name="user"/>
<table-filter
match-name="user_role"/>
<table-filter match-name="employee"/>
</hibernate-reverse-engineering>
3.
Creating Hibernate Entity (pojo) File:-Employee.java
and User.java and
UserRole.java
Important:To create this file MySQL
database springsecurity most be connected through Netbeans.
Right click
com.model package--ànew-àHibernate Mappling Files and pojos from databaseàDonot select mapping file &
select EJB3.0 Pattern and Domain Code(java) àAlso select JDK5
Language Features tough not displayedàClick Finish
Please Modify both entity
classes as Given Below. Generated code may differ a little.
Employee.java CODE:
package
com.ray.springsecurity.pojos.model;
import
java.util.Date;
import
javax.persistence.Column;
import
javax.persistence.Entity;
import
javax.persistence.Id;
import
javax.persistence.Table;
import
javax.persistence.Temporal;
import
javax.persistence.TemporalType;
/**
*
* @author Raichand
*/
@Entity
@Table(name="employee"
,catalog="springdatacruddb"
)
public
class Employee implements
java.io.Serializable {
private int empId;
private String firstName;
private String lastName;
private int salary;
private String sex;
private Date dob;
private String remark;
@Id
@Column(name="EmpId", unique=true,
nullable=false)
public int getEmpId() {
return this.empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
@Column(name="FirstName",
nullable=false, length=25)
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
@Column(name="LastName",
nullable=false, length=25)
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name="Salary",
nullable=false)
public int getSalary() {
return this.salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
@Column(name="Sex",
nullable=false, length=15)
public String getSex() {
return this.sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Temporal(TemporalType.DATE)
@Column(name="DOB",
nullable=false, length=10)
public Date getDob() {
return this.dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
@Column(name="Remark",
nullable=false, length=50)
public String getRemark() {
return this.remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public
void reset() {
this.setEmpId(0);
this.setFirstName("");
this.setLastName("");
this.setSex("");
this.setSalary(0);
this.setDob(null);
this.setRemark("");
}
//This method writes the values of contact
object with System.out.println(employee.toString()) code
@Override
public String toString() {
return "employee"
+ "\n\t Id: " + this.empId
+ "\n\t FirstName: " +
this.firstName
+ "\n\t LastName: " +
this.lastName
+ "\n\t Sex: " + this.sex
+ "\n\t Salary: " +
this.salary
+ "\n\t Date of Birth: " +
this.dob
+ "\n\t Remark: " + this.remark;
}
}
User.java CODE:
package
com.ray.springsecurity.pojos.model;
import
java.io.Serializable;
import
java.util.HashSet;
import
java.util.Set;
import
javax.persistence.Column;
import
javax.persistence.Entity;
import
javax.persistence.FetchType;
import
javax.persistence.Id;
import
javax.persistence.OneToMany;
import
javax.persistence.Table;
@Entity
@Table(name
= "users", catalog = "springdatacruddb")
public class
User implements Serializable{
private String username;
private String password;
private boolean enabled;
private Set<UserRole> userRole
= new HashSet<UserRole>(0);
@Id
@Column(name = "username",
unique = true,
nullable = false, length
= 45)
public String getUsername() {
return this.username;
}
public void setUsername(String
username) {
this.username =
username;
}
@Column(name = "password",
nullable = false, length
= 60)
public String getPassword() {
return this.password;
}
public void setPassword(String
password) {
this.password =
password;
}
@Column(name = "enabled",
nullable = false)
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean
enabled) {
this.enabled = enabled;
}
@OneToMany(fetch = FetchType.LAZY,
mappedBy = "user")
public Set<UserRole>
getUserRole() {
return this.userRole;
}
public void setUserRole(Set<UserRole>
userRole) {
this.userRole =
userRole;
}
}
UserRole.Java CODE:-
package
com.ray.springsecurity.pojos.model;
import
java.io.Serializable;
import
static javax.persistence.GenerationType.IDENTITY;
import
javax.persistence.Column;
import
javax.persistence.Entity;
import
javax.persistence.FetchType;
import
javax.persistence.GeneratedValue;
import
javax.persistence.Id;
import
javax.persistence.JoinColumn;
import
javax.persistence.ManyToOne;
import
javax.persistence.Table;
import
javax.persistence.UniqueConstraint;
@Entity
@Table(name
= "user_roles", catalog = "springdatacruddb",
uniqueConstraints = @UniqueConstraint(
columnNames = {
"role", "username" }))
public class
UserRole implements Serializable{
private Integer userRoleId;
private User user;
private String role;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name =
"user_role_id",
unique = true, nullable =
false)
public Integer getUserRoleId() {
return this.userRoleId;
}
public void setUserRoleId(Integer
userRoleId) {
this.userRoleId = userRoleId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name =
"username", nullable = false)
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
@Column(name = "role",
nullable = false, length = 45)
public String getRole() {
return this.role;
}
public void setRole(String role) {
this.role = role;
}
}
4.
Creating JSF Managed Bean File
LoginController.java File
Right
click com.controller package--new-JSF Managed Bean-Give class name LoginController- click finish.
package com.ray.jsfbean.controller;
import java.io.IOException;
import java.io.Serializable;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
*
* @author Raichand
*/
@Named()
@SessionScoped()
public class LoginController implements Serializable {
private
String username;
private
String password;
public void
login() throws ServletException, IOException {
System.out.println("Login controller password is :-" +
password);
ExternalContext context =
FacesContext.getCurrentInstance().getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest)
context.getRequest()).getRequestDispatcher("/login");
dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
}
public String
logout() throws IOException, ServletException
{
ExternalContext context =
FacesContext.getCurrentInstance().getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest)
context.getRequest()).getRequestDispatcher("/logout");
dispatcher.forward((ServletRequest)
context.getRequest(),(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
return
null;
}
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;
}
}
5.EmployeeBBean.java-JSF Managed Bean File
Right click com.ray.jsfbean.controller package--new-JSF Managed Bean-Give class name EmployeeBBean- click finish.
package com.ray.jsfbean.controller;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.stereotype.Component;
import org.springframework.dao.DataAccessException;
import com.ray.springsecurity.pojos.model.Employee;
import com.ray.springsecurity.service.EmployeeService;
import org.primefaces.context.RequestContext;
import com.ray.springdatajpa.exception.EmployeeNotFoundException;
import javax.faces.context.FacesContext;
/**
*
* @author Raichand
*/
//@Named(value = "employeeBBean")
@Component//with it spring can scan this class as a bean.@Named also does same thing
@ManagedBean(name="employeeBBean")
@SessionScoped
public class EmployeeBBean {
private static final long serialVersionUID = 1L;
@Inject//@ Autowired or #(ManagedProperty) can also be used
private EmployeeService employeeService;
private List<Employee> employeeList;
private Employee employee = new Employee();
private List<Employee> selectedEmployees;
private Employee selectedEmployee;
/**
* Creates a new instance of EmployeeBean
*/
public EmployeeBBean() {
}
public void addEmployee() {
try {
Employee newemployee = new Employee();
int newId = getEmployeeService().CreateNewEmpId();//Retrieving Id of last Employee in Employee Table and adding 1 to it for next record id
System.out.println(newId);
newemployee.setEmpId(newId);
newemployee.setFirstName(employee.getFirstName());
newemployee.setLastName(employee.getLastName());
newemployee.setDob(employee.getDob());
newemployee.setSex(employee.getSex());
newemployee.setSalary(employee.getSalary());
newemployee.setRemark(employee.getRemark());
getEmployeeService().create(newemployee);
newemployee.reset();
employee.reset();
FacesMessage message= new FacesMessage(FacesMessage.SEVERITY_INFO, "Save ","Employee Information saved successfully.");
RequestContext.getCurrentInstance().showMessageInDialog(message);
} catch (DataAccessException e) {
e.printStackTrace();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "D'oh!", "Message: "));
}
}
public void changeEmployee(Employee employee) {
this.employee= employee;
}
public void updateEmployee()throws Exception{
getEmployeeService().update(employee);
FacesMessage message= new FacesMessage(FacesMessage.SEVERITY_INFO, "Update","Employee Information updated successfully .");
RequestContext.getCurrentInstance().showMessageInDialog(message);
this.reset();
}
public void deleteEmployee()throws Exception {
for (Iterator iterator = selectedEmployees.iterator(); iterator.hasNext();) {
Employee employee = (Employee) iterator.next();
getEmployeeService().delete(employee.getEmpId());
}
FacesMessage message= new FacesMessage(FacesMessage.SEVERITY_INFO, "Delete","Employee Records deleted successfully");
RequestContext.getCurrentInstance().showMessageInDialog(message);
}
public void reset() {
this.employee.reset();
}
public List<Employee> getEmployeeList() {
employeeList = new ArrayList<Employee>();
employeeList.addAll(getEmployeeService().findAll());
return employeeList;
}
public EmployeeService getEmployeeService() {
return employeeService;
}
public void setEmployeeService(EmployeeService employeeService) {
this.employeeService = employeeService;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public List<Employee> getSelectedEmployees() {
return selectedEmployees;
}
public void setSelectedEmployees(List<Employee> selectedEmployees) {
this.selectedEmployees = selectedEmployees;
}
public Employee getSelectedEmployee() {
return selectedEmployee;
}
public void setSelectedEmployee(Employee selectedEmployee) {
this.selectedEmployee = selectedEmployee;
}
}
Right click com.ray.jsfbean.controller package--new-JSF Managed Bean-Give class name EmployeeBBean- click finish.
package com.ray.jsfbean.controller;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.stereotype.Component;
import org.springframework.dao.DataAccessException;
import com.ray.springsecurity.pojos.model.Employee;
import com.ray.springsecurity.service.EmployeeService;
import org.primefaces.context.RequestContext;
import com.ray.springdatajpa.exception.EmployeeNotFoundException;
import javax.faces.context.FacesContext;
/**
*
* @author Raichand
*/
//@Named(value = "employeeBBean")
@Component//with it spring can scan this class as a bean.@Named also does same thing
@ManagedBean(name="employeeBBean")
@SessionScoped
public class EmployeeBBean {
private static final long serialVersionUID = 1L;
@Inject//@ Autowired or #(ManagedProperty) can also be used
private EmployeeService employeeService;
private List<Employee> employeeList;
private Employee employee = new Employee();
private List<Employee> selectedEmployees;
private Employee selectedEmployee;
/**
* Creates a new instance of EmployeeBean
*/
public EmployeeBBean() {
}
public void addEmployee() {
try {
Employee newemployee = new Employee();
int newId = getEmployeeService().CreateNewEmpId();//Retrieving Id of last Employee in Employee Table and adding 1 to it for next record id
System.out.println(newId);
newemployee.setEmpId(newId);
newemployee.setFirstName(employee.getFirstName());
newemployee.setLastName(employee.getLastName());
newemployee.setDob(employee.getDob());
newemployee.setSex(employee.getSex());
newemployee.setSalary(employee.getSalary());
newemployee.setRemark(employee.getRemark());
getEmployeeService().create(newemployee);
newemployee.reset();
employee.reset();
FacesMessage message= new FacesMessage(FacesMessage.SEVERITY_INFO, "Save ","Employee Information saved successfully.");
RequestContext.getCurrentInstance().showMessageInDialog(message);
} catch (DataAccessException e) {
e.printStackTrace();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "D'oh!", "Message: "));
}
}
public void changeEmployee(Employee employee) {
this.employee= employee;
}
public void updateEmployee()throws Exception{
getEmployeeService().update(employee);
FacesMessage message= new FacesMessage(FacesMessage.SEVERITY_INFO, "Update","Employee Information updated successfully .");
RequestContext.getCurrentInstance().showMessageInDialog(message);
this.reset();
}
public void deleteEmployee()throws Exception {
for (Iterator iterator = selectedEmployees.iterator(); iterator.hasNext();) {
Employee employee = (Employee) iterator.next();
getEmployeeService().delete(employee.getEmpId());
}
FacesMessage message= new FacesMessage(FacesMessage.SEVERITY_INFO, "Delete","Employee Records deleted successfully");
RequestContext.getCurrentInstance().showMessageInDialog(message);
}
public void reset() {
this.employee.reset();
}
public List<Employee> getEmployeeList() {
employeeList = new ArrayList<Employee>();
employeeList.addAll(getEmployeeService().findAll());
return employeeList;
}
public EmployeeService getEmployeeService() {
return employeeService;
}
public void setEmployeeService(EmployeeService employeeService) {
this.employeeService = employeeService;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public List<Employee> getSelectedEmployees() {
return selectedEmployees;
}
public void setSelectedEmployees(List<Employee> selectedEmployees) {
this.selectedEmployees = selectedEmployees;
}
public Employee getSelectedEmployee() {
return selectedEmployee;
}
public void setSelectedEmployee(Employee selectedEmployee) {
this.selectedEmployee = selectedEmployee;
}
}
6. CustomUserDetailsService.java
Service File
Right click
com.ray.springsecurity.service package-new-javaclassàClass name Give name CustomUserDetailsServiceClick Finish
CustomUserDetailsService.java CODE:
package
com.ray.springsecurity.service;
import
java.util.ArrayList;
import
java.util.HashSet;
import
java.util.List;
import
java.util.Set;
import
com.ray.springdatajpa.dao.repositories.UserRepository;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.security.core.GrantedAuthority;
import
org.springframework.security.core.authority.SimpleGrantedAuthority;
import
org.springframework.security.core.userdetails.User;
import
org.springframework.security.core.userdetails.UserDetails;
import
org.springframework.security.core.userdetails.UserDetailsService;
import
org.springframework.security.core.userdetails.UsernameNotFoundException;
import
org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional;
import
javax.persistence.EntityManager;
import
javax.persistence.PersistenceContext;
import
com.ray.springsecurity.pojos.model.UserRole;
/* UserDetailsService is a Spring Security Interface, CustomUserDetailsService is it's Implementation */
@Service("CustomUserDetailsService")
@Transactional(readOnly=true)
public class
CustomUserDetailsService implements UserDetailsService {
@Autowired
private UserRepository
userRepository ;
@Override
public UserDetails loadUserByUsername(final
String username) throws UsernameNotFoundException {
System.out.println("username
is:-" + username);
com.ray.springsecurity.pojos.model.User
user = userRepository.findByUsername(username);
System.out.println("Password
From Detailservice is:-" + user.getPassword().toString());
System.out.println(user.toString());
if (user==null){throw new
UsernameNotFoundException("No such user: " + username);
}else if(user.getUserRole().isEmpty()){
throw new
UsernameNotFoundException("User" + username + "has no
authorities");
}
System.out.println("password is:-" +
user.getPassword().toString());
List<GrantedAuthority>
authorities = buildUserAuthority(user.getUserRole());
return
buildUserForAuthentication(user, authorities); }
// Converts
com.ray.springsecurity.pojos.model.User user to
//
org.springframework.security.core.userdetails.User
private User
buildUserForAuthentication(com.ray.springsecurity.pojos.model.User user,
List<GrantedAuthority> authorities) {
return new
User(user.getUsername(), user.getPassword(), user.isEnabled(), true, true,
true, authorities);
}
private
List<GrantedAuthority> buildUserAuthority(Set<UserRole> userRoles)
{
Set<GrantedAuthority> setAuths
= new HashSet<GrantedAuthority>();
// Build user's
authorities
for (UserRole userRole :
userRoles) {
setAuths.add(new
SimpleGrantedAuthority(userRole.getRole()));
}
List<GrantedAuthority>
Result = new ArrayList<GrantedAuthority>(setAuths);
return Result;
}
}
7.Employee
Service Interface File:-EmloyeeService.java
package com.ray.springsecurity.service;
import java.util.List;
import com.ray.springsecurity.pojos.model.Employee;
import com.ray.springdatajpa.exception.EmployeeNotFoundException;
/**
*
* @author Raichand
*/
public interface
EmployeeService {
public Employee
create(Employee employee);
public void
delete(int empid) throws EmployeeNotFoundException;
public
List<Employee> findAll();
public Employee
update(Employee employee) throws EmployeeNotFoundException;
public Employee
findById(int empid);
public int CreateNewEmpId();
}
8.Employee
Service Implementation File:-EmployeeServiceImpl.java
package com.ray.springsecurity.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional;
import com.ray.springsecurity.pojos.model.Employee;
import com.ray.springsecurity.service.EmployeeService;
import
com.ray.springdatajpa.dao.repositories.EmployeeRepository;
import
com.ray.springdatajpa.exception.EmployeeNotFoundException;
/**
*
* @author Raichand
*/
@Service
public class EmployeeServiceImpl implements
EmployeeService {
@Resource
private
EmployeeRepository employeeRepository;
@Override
@Transactional
public Employee
create(Employee employee) {
Employee
createdEmployee = employee;
return
employeeRepository.save(createdEmployee);
}
@Override
@Transactional
public int
CreateNewEmpId() {
int maxEmpId
= employeeRepository.getMaxEmpId();
// maxEmpId
=(maxEmpId==null)?"0":maxEmpId;
return
maxEmpId+1;
}
@Override
@Transactional
public Employee
findById(int empid) {
return
employeeRepository.findOne(empid);
}
@Override
@Transactional(rollbackFor=EmployeeNotFoundException.class)
public void
delete(int empid) throws EmployeeNotFoundException {
Employee
deletedEmployee = employeeRepository.findOne(empid);
if
(deletedEmployee == null)
throw
new EmployeeNotFoundException("Employee Not Found");
employeeRepository.delete(deletedEmployee);
}
@Override
@Transactional
public
List<Employee> findAll() {
return
employeeRepository.findAll();
}
@Override
@Transactional(rollbackFor=EmployeeNotFoundException.class)
public Employee
update(Employee employee) throws EmployeeNotFoundException {
Employee
updatedEmployee = employeeRepository.findOne(employee.getEmpId());
if
(updatedEmployee == null)
throw
new EmployeeNotFoundException("Employee not Found");
updatedEmployee.setFirstName(employee.getFirstName());
updatedEmployee.setLastName(employee.getLastName());
updatedEmployee.setSalary(employee.getSalary());
updatedEmployee.setSex(employee.getSex());
updatedEmployee.setDob(employee.getDob());
updatedEmployee.setRemark(employee.getRemark());
return
updatedEmployee;
}
}
9.CustomAuthenticationHandler.java Class File
Right click
com.ray.security.custom.auth.handler package-ànew-àjavaclassàClass name àGive name CustomAuthenticationHandleràClick Finish
CustomAuthenticationHandler.java
CODE:
package
com.ray.security.custom.auth.handler;
import
java.io.IOException;
import
java.util.Set;
import
javax.servlet.ServletException;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
import
org.springframework.security.core.Authentication;
import
org.springframework.security.core.authority.AuthorityUtils;
import
static org.springframework.security.crypto.keygen.KeyGenerators.string;
import
org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
/**
*
* @author Raichand
*/
/*
* This Class Redirects to authorised page
according to role of the person logging in.
*/
public class
CustomAuthenticationHandler extends SimpleUrlAuthenticationSuccessHandler {
@Override
public void
onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse
response,
Authentication
authentication) throws ServletException, IOException {
String userTargetUrl =
"/View/Secured/User/add.xhtml";
String adminTargetUrl =
"/View/Secured/Admin/crud.xhtml";
Set<String> roles =
AuthorityUtils.authorityListToSet(authentication.getAuthorities());
if (roles.contains("ROLE_ADMIN"))
{
getRedirectStrategy().sendRedirect(request, response, adminTargetUrl);
} else if
(roles.contains("ROLE_USER")) {
getRedirectStrategy().sendRedirect(request, response, userTargetUrl);
} else {
super.onAuthenticationSuccess(request,
response, authentication);
}
}
}
10.Employee Repository Class File
package
com.ray.springdatajpa.dao.repositories;
import
org.springframework.data.jpa.repository.JpaRepository;
import
org.springframework.data.jpa.repository.Query;
import
com.ray.springsecurity.pojos.model.Employee;
/**
*
* @author Raichand
*/
public
interface EmployeeRepository extends JpaRepository<Employee,Integer> {
@Query("SELECT max(e.empId) FROM
Employee e")
int getMaxEmpId();
}
11. User Repository Class File
11. User Repository Class File
package
com.ray.springdatajpa.dao.repositories;
import
com.ray.springsecurity.pojos.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
/**
*
* @author Raichand
*/
public
interface UserRepository extends JpaRepository<User,Integer>{
User findByUsername(String username);
}
12.EmployeeNotFoundException
File
package com.ray.springdatajpa.exception;
/**
*
* @author Raichand
*/
public class EmployeeNotFoundException extends Exception{
public
EmployeeNotFoundException(String message){
super(message);
}
}
13. login.xhtml code
<!DOCTYPE
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Login</title>
</h:head>
<body>
<center><h2>Login</h2></center>
<c:if test="${'fail' eq param.auth}">
<div
style="color:red">
Login
Failed!!!<br/>
Reason
: Bad Credentials!Please Try Again.
</div>
</c:if>
<center><h:form prependId="false"
id="form">
<p:panelGrid columns="2" style="border-bottom-width:
0px;">
<h:outputText value="UserName:"/>
<p:inputText value="#{loginController.username}"
id="username" required="true"
requiredMessage="UserName is required"/>
<h:outputText value="Password:"/>
<p:password value="#{loginController.password}"
id="password" required="true" requiredMessage="Password
is required"/>
</p:panelGrid>
<p:spacer height="20px" width="10px"> </p:spacer>
<p:row ><p:selectBooleanCheckbox label="Remember Me"
id="remember-me" >Remember Me
</p:selectBooleanCheckbox>
<h:outputText value=" " />
</p:row><br></br>
<p:row> <p:commandButton
action="#{loginController.login()}" value="Login"
ajax="false"/> </p:row>
</h:form>
</center>
</body>
</html>
14. crud.xhtml code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Employee Manager</title>
</h:head>
<h:body>
<h:form>
<p:outputLabel value="Welcome Admin
"></p:outputLabel>
<p:outputLabel
value="#{loginController.username}"></p:outputLabel>
<h:commandLink
action="#{loginController.logout()}">logout</h:commandLink>
</h:form>
<p:spacer height="1px"></p:spacer>
<center><h2>Employee Manager</h2></center>
<p:dialog id="employeeDetail1" widgetVar="$employeeDetail1"
header="Add Employee"
hideEffect="explode" appendTo="@(body)"
resizable="false" draggable="false"
closeOnEscape="true">
<h:form>
<p:panelGrid columns="2">
<h:outputLabel
for="employeefirstname" value="Employee FirstName: *" />
<p:inputText
id="employeefirstname"
value="#{employeeBBean.employee.firstName}"
label="Employee FirstName" placeholder="Employee FirstName"
/>
<h:outputLabel
for="employeelastname" value="Employee LastName:"/>
<p:inputText
id="employeelastname" label="Employee LastName"
value="#{employeeBBean.employee.lastName}" placeholder="Employee
LastName"/>
<h:outputLabel for="sex" value="Choose Sex"/>
<p:selectOneMenu id="sex" label="Choose Sex"
value="#{employeeBBean.employee.sex}" effect="fold">
<f:selectItem itemLabel="Select One" itemValue=""
/>
<f:selectItem itemLabel="Male" itemValue="Male"/>
<f:selectItem itemLabel="Female"
itemValue="Female"/>
</p:selectOneMenu>
<p:outputLabel for="dob" value="Employee Date of
Birth"/>
<p:calendar id="dob"
value="#{employeeBBean.employee.dob}" label="DatePosted:"
required="true" pattern="dd/MM/yyyy"
effect="slideDown" requiredMessage="Please Enter Date of
Birth!"
navigator="true"
showButtonPanel="true" yearRange="c-60:c+60"
placeholder="Date of Birth" />
<h:outputLabel for="employeesalary"
value="Employee Salary:"/>
<p:inputText
id="employeesalary" label="Employee Salary"
value="#{employeeBBean.employee.salary}" placeholder="Employee
Salary"/>
<p:outputLabel for="remark" value="Remark"/>
<p:inputTextarea id="remark" label="Remark"
value="#{employeeBBean.employee.remark}"
placeholder="Remark"/>
<p:commandButton value="add" process="@form"
id="AddButtonId" ajax="true" icon="ui-icon-plus"
update=":form1:employeeTable"
actionListener="#{employeeBBean.addEmployee()}"
oncomplete="updateTable(),PF('$employeeDetail1').hide()"
/>
<p:commandButton id="cancelAddButtonId" value="Cancel"
onclick="handleComplete(xhr, status, args)"/>
</p:panelGrid>
</h:form>
</p:dialog>
<h:outputScript id="handleCompleteScript"
target="body">
/* <![CDATA[ */
function handleComplete(xhr, status, args) {
if(args && args.validName) {
$userDetail1.hide();
}
}
/* ]]> */
</h:outputScript>
<p:dialog id="employeeDetail2"
widgetVar="$employeeDetail2"
header="Edit Employee"
hideEffect="explode" appendTo="@(body)"
resizable="false" draggable="false"
closeOnEscape="true">
<h:form>
<p:panelGrid columns="2">
<h:outputLabel
for="employeefirstname" value="Employee FirstName: *" />
<p:inputText
id="employeefirstname"
value="#{employeeBBean.employee.firstName}"
label="Employee FirstName" placeholder="Employee FirstName"
/>
<h:outputLabel for="employeelastname" value="Employee
LastName:"/>
<p:inputText
id="employeelastname" label="Employee LastName"
value="#{employeeBBean.employee.lastName}" placeholder="Employee
LirstName"/>
<h:outputLabel for="sex" value="Choose Sex"/>
<p:selectOneMenu id="sex" label="Choose Sex"
value="#{employeeBBean.employee.sex}" effect="fold">
<f:selectItem itemLabel="Select One" itemValue=""
/>
<f:selectItem itemLabel="Male"
itemValue="Male"/>
<f:selectItem itemLabel="Female"
itemValue="Female"/>
</p:selectOneMenu>
<p:outputLabel for="dob" value="Employee Date of
Birth"/> <p:calendar
id="dob" value="#{employeeBBean.employee.dob}"
label="DatePosted:"
required="true" pattern="dd/MM/yyyy"
effect="slideDown" requiredMessage="Please Enter Date of
Birth!"
navigator="true"
showButtonPanel="true" yearRange="c-60:c+60"
placeholder="Date of Birth" />
<h:outputLabel for="employeesalary" value="Employee
Salary:"/>
<p:inputText
id="employeesalary" label="Employee Salary"
value="#{employeeBBean.employee.salary}" placeholder="Employee
Salary"/>
<p:outputLabel for="remark" value="Remark"/>
<p:inputTextarea id="remark" label="Remark"
value="#{employeeBBean.employee.remark}"
placeholder="Remark"/>
<p:commandButton value="Update" process="@form"
id="EditButtonId" ajax="true" icon="ui-icon-disk"
update=":form1:employeeTable"
actionListener="#{employeeBBean.updateEmployee()}"
oncomplete="updateTable(),PF('$employeeDetail2').hide()"
/>
<p:commandButton id="cancelEditButtonId" value="Cancel"
onclick="handleComplete(xhr, status, args)"/>
</p:panelGrid>
</h:form>
</p:dialog>
<h:outputScript>
</h:outputScript>
<h:outputScript id="handleCompleteScript"
target="body">
/* <![CDATA[ */
function handleComplete(xhr, status, args) {
if(args && args.validName) {
$userDetail2.hide();
}
}
/* ]]> */
</h:outputScript>
<h:form id="form1">
<center><h3>Employees</h3></center>
<p:toolbar>
<p:toolbarGroup align="left">
<p:commandButton icon="ui-icon-plusthick" type="button" id="addEmployeeBtn" value="Add Employee" update=":employeeDetail1" ajax="true" onclick="PF('$employeeDetail1').show()"/>
<p:commandButton value="Delete" icon="ui-icon-trash" type="button" onclick="PF('confirmDialog').show()" />
</p:toolbarGroup>
</p:toolbar>
<p:confirmDialog message="Are you sure you want to delete this record?Record once deleted can not be retrieved."
<p:confirmDialog message="Are you sure you want to delete this record?Record once deleted can not be retrieved."
header="Deleting"
severity="alert" widgetVar="confirmDialog">
<p:commandButton
value="Yes Sure" update=":form1:employeeTable" action="#{employeeBBean.deleteEmployee()}"
oncomplete="PF('confirmDialog').hide()"/>
<p:commandButton
value="Not Yet" onclick="PF('confirmDialog').hide();"
type="button" />
</p:confirmDialog>
<p:spacer height="1px"> </p:spacer>
<center><h3>Employees</h3></center>
<p:remoteCommand name="updateTable"
update="employeeTable" />
<p:dataTable
value="#{employeeBBean.employeeList}" var="employee"
editable="true" rowKey="#{employee.empId}" selection="#{employeeBBean.selectedEmployees}"
paginator="true" rows="5" id="employeeTable">
<p:column
selectionMode="multiple" headerText="Select"
style="width:6%" />
<p:column headerText="EmployeeId" style="text-align:
left;">
<h:outputText value="#{employee.empId}"/>
</p:column>
<p:column
filterBy="#{employee.firstName}"
filterOptions=""
filterMatchMode="startsWith" headerText="First
Name">
<h:outputText value="#{employee.firstName}"/>
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{employee.lastName}"/>
</p:column>
<p:column headerText="Sex">
<h:outputText
value="#{employee.sex}"/>
</p:column>
<p:column headerText="Salary">
<h:outputText value="#{employee.salary}"/>
</p:column>
<p:column headerText="Date of Birth" >
<h:outputText value="#{employee.dob}">
<f:convertDateTime type="date"
pattern="dd-MMM-yyyy"/>
</h:outputText>
</p:column>
<p:column headerText="Remark">
<h:outputText value="#{employee.remark}"/>
</p:column>
<p:column headerText="Edit" style="text-align:
center">
<p:commandButton
icon="ui-icon-pencil" id="editEmployeeBtn"
value="Edit" ajax="true"
actionListener="#{employeeBBean.changeEmployee(employee)}"
update=":employeeDetail2"
oncomplete="PF('$employeeDetail2').show()"/>
</p:column>
<p:rowExpansion>
<h:outputText value="#{employee.remark}"
styleClass="rowExpansion"/>
</p:rowExpansion>
</p:dataTable>
</h:form>
</h:body>
</html>
15.add.xhtml Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Welcome
to Employee Manager</title>
</h:head>
<h:body>
<h:form>
<p:outputLabel value="Welcome User
"></p:outputLabel>
<p:outputLabel
value="#{loginController.username}"></p:outputLabel>
<h:commandLink
action="#{loginController.logout()}">logout</h:commandLink>
</h:form>
<p:spacer height="1px"></p:spacer>
<p:messages></p:messages>
<h:form
id="form1">
<table>
<tr>
<td><h:outputLabel
for="firstname" value="FirstName : " /></td>
<td><p:inputText
id="firstname"
value="#{employeeBBean.employee.firstName}">
<f:validateLength
minimum="2" />
<p:ajax
event="blur" update="firstnameMsg" />
</p:inputText>
<p:message id="firstnameMsg" for="firstname" display="icon"
/></td>
</tr>
<tr>
<td><h:outputLabel
for="lastname" value="LastName : " /></td>
<td><p:inputText
id="lastname"
value="#{employeeBBean.employee.lastName}">
<f:validateLength
minimum="2" />
<p:ajax
event="blur" update="lastnameMsg" />
</p:inputText>
<p:message id="lastnameMsg" for="lastname"
display="icon" /></td>
</tr>
<tr>
<td><h:outputLabel
for="sex" value="Choose Sex : " /></td>
<td><p:selectOneMenu label="Sex:"
value="#{employeeBBean.employee.sex}" id="sex">
<f:selectItem itemLabel="Select One" itemValue=""
/>
<f:selectItem itemLabel="Male"
itemValue="Male"/>
<f:selectItem itemLabel="Female"
itemValue="Female"/>
<f:validateLength minimum="2"/>
<p:ajax event="blur" update="sexMsg" />
</p:selectOneMenu> <p:message id="sexMsg"
for="sex" display="icon" />
</td>
</tr>
<tr>
<td><h:outputLabel
for="salary" value="Salary: " /></td>
<td><p:inputText id="salary"
value="#{employeeBBean.employee.salary}">
<f:validateLength
minimum="2" />
<p:ajax
event="blur" update="salaryMsg" />
</p:inputText>
<p:message id="salaryMsg" for="salary"
display="icon" /></td>
</tr>
<tr>
<td><h:outputLabel
for="dob" value="Date of Birth : " /></td>
<td><p>
<p:calendar id="dop"
value="#{employeeBBean.employee.dob}" label="DatePosted:"
required="true" pattern="dd/MMM/yyyy"
effect="slideDown" requiredMessage="Please Enter Date of Birth!"
navigator="true"
showButtonPanel="true" yearRange="c-60:c+60" />
</p></td>
</tr>
<tr>
<td><h:outputLabel
for="remark" value="Remark : " /></td>
<td><p:inputTextarea
id="remark"
value="#{employeeBBean.employee.remark}">
<f:validateLength
minimum="2" />
<p:ajax
event="blur" update="remarkMsg" />
</p:inputTextarea> <p:message
id="remarkMsg" for="remark" display="icon"
/></td>
</tr>
<tr>
<td><p:commandButton
icon="ui-icon-plusthick" id="addEmployeeBtn"
value="AddEmployee" type="submit" ajax="true"
update=":form1:employeetable"
actionListener="#{employeeBBean.addEmployee()}"
/></td>
<td><p:commandButton
id="reset" value="Reset"
actionListener="#{employeeBBean.reset()}"
ajax="false" /></td>
</tr>
</table>
<center><h3>Employees</h3></center>
<p:dataTable id="employeetable" var="employee"
paginator="true" rows="5"
value="#{employeeBBean.employeeList}"
style="width:
100%">
<p:column headerText="Id">
<h:outputText value="#{employee.empId}"/>
</p:column>
<p:column
headerText="First Name">
<h:outputText value="#{employee.firstName}"/>
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{employee.lastName}"/>
</p:column>
<p:column headerText="Sex">
<h:outputText value="#{employee.sex}"/>
</p:column>
<p:column headerText="Salary">
<h:outputText
value="#{employee.salary}"/>
</p:column>
<p:column headerText="Date of Birth" >
<h:outputText value="#{employee.dob}">
<f:convertDateTime type="date"
pattern="dd-MMM-yyyy"/>
</h:outputText>
</p:column>
<p:column headerText="Remark">
<h:outputText value="#{employee.remark}"/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
16. faces-config.xml
It is
created using notepad and below provided code is added to .save as
faces-config.xml.Then copy it and paste to WEB-INF Folder.
CODE:-
<?xml
version="1.0" encoding="UTF-8"?>
<faces-config
version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<!--
JSF and Spring are integrated -->
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>
17. web.xml (Automatically
generated and modified later )
<?xml version="1.0"
encoding="UTF-8"?>
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Employee Management</display-name>
<!--
Declare Spring configuration file location -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
/WEB-INF/spring-database.xml
</param-value>
</context-param>
<!--
Spring -->
<!--
The Bootstrap listener to start up and shut down Spring's root
WebApplicationContext.
It
is registered to Servlet Container -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher><!-- mandatory to allow
the managed bean to forward the request to the filter -->
</filter-mapping>
<!--
Project Stage Level -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!--
JSF Servlet is defined to container -->
<!-- JSF
mapping -->
<servlet>
<servlet-name>Faces
Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!--
Mapping with servlet and url for the http requests. -->
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!--
Welcome Page -->
<welcome-file-list>
<welcome-file>View/UnSecured/login.xhtml</welcome-file>
</welcome-file-list>
</web-app>
18.spring-security.xml(Add
if not automatically generated and modified later)
<?xml version="1.0"
encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true"
use-expressions="true" disable-url-rewriting="false">
<intercept-url pattern="/View/UnSecured/**"
access="permitAll" />
<intercept-url pattern="/View/UnSecured/login"
access="permitAll"/>
<intercept-url pattern="/View/Secured/Admin/**"
access="hasRole('ROLE_ADMIN')"/>
<intercept-url pattern="/View/Secured/User/**"
access="hasRole('ROLE_USER')"/>
<!-- Page level Spring Security : Enable Primefaces -->
<intercept-url pattern="/javax.faces.resource/**"
access="permitAll"/>
<form-login
login-page="/View/UnSecured/login.xhtml"
authentication-success-handler-ref="authenticationSuccessRedirecthandler"
authentication-failure-url="/View/UnSecured/login.xhtml?auth=fail"
username-parameter="username"
password-parameter="password"/>
<csrf disabled="true"/>
<logout
logout-success-url="/View/UnSecured/login.xhtml" />
<logout
invalidate-session="true"
delete-cookies="JSESSIONID,SPRING_SECURITY_REMEMBER_ME_COOKIE"
logout-success-url="/View/UnSecured/login.xhtml"
/>
<remember-me
key="springRocks" services-ref="rememberMeServices"
/>
</http>
<beans:bean
id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService"
ref="customUserDetailsService"/>
</beans:bean>
<beans:bean
id="authenticationManager" class="org.springframework.security.authentication.ProviderManager">
<beans:constructor-arg>
<beans:list>
<beans:ref
bean="daoAuthenticationProvider"/>
</beans:list>
</beans:constructor-arg>
</beans:bean>
<!--
Authentication-manager Bean -->
<!-- Set customUserDetailsService
class as the authentication Manager for Spring Security-->
<authentication-manager id="authenticationManager">
<authentication-provider
user-service-ref="customUserDetailsService">
<password-encoder hash="plaintext"></password-encoder>
</authentication-provider>
</authentication-manager>
<beans:bean
id ="authenticationFilter"
class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
<beans:property name ="authenticationManager"
ref="authenticationManager"/>
<beans:property name="filterProcessesUrl"
value="/login"/>
<beans:property name="usernameParameter"
value="username"/>
<beans:property name="passwordParameter"
value="password"/>
</beans:bean>
<beans:bean
class="com.ray.springsecurity.service.CustomUserDetailsService"
id="customUserDetailsService">
</beans:bean>
<beans:bean
class="com.ray.security.custom.auth.handler.CustomAuthenticationHandler"
id="authenticationSuccessRedirecthandler"></beans:bean>
<!--
DataSource Bean -->
<!-- Bean
remember me -->
<beans:bean
id="rememberMeServices"
class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
<beans:constructor-arg value
="springRocks"/>
<beans:constructor-arg ref ="customUserDetailsService"/>
<beans:property
name="cookieName" value ="remember-me"/>
<beans:property
name="useSecureCookie" value ="true"/>
<beans:property name="tokenValiditySeconds"
value="1209600" />
<beans:property name="alwaysRemember"
value="false" />
</beans:bean>
<beans:bean
id="rememberMeAuthenticationProvider"
class="org.springframework.security.authentication.RememberMeAuthenticationProvider">
<beans:constructor-arg value ="springRocks"/>
</beans:bean>
<beans:bean
id="rememberMeFilter"
class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
<beans:constructor-arg
ref="rememberMeServices" />
<beans:constructor-arg
ref="authenticationManager" />
</beans:bean>
</beans:beans>
19. spring-database.xml (Add
if not aomatically generated and modified later)
<?xml version="1.0"
encoding="UTF-8"?>
<beans
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--
Package needed to be scanned for annotation -->
<context:component-scan
base-package="com.ray" />
<!--
Configure Spring Data JPA and set the base package of the repository interfaces
-->
<jpa:repositories base-package
="com.ray.springdatajpa.dao.repositories"/>
<!-- Simple
implementation of the standard JDBC DataSource interface,
configuring
the plain old JDBC DriverManager via bean properties -->
<!--
Data Source Declaration -->
<bean
id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property
name="driverClassName" value="com.mysql.jdbc.Driver" />
<property
name="url" value="jdbc:mysql://localhost:3306/springdatacruddb"
/>
<property
name="username" value="root" />
<property
name="password" value="" />
</bean>
<!-- <bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource"> -->
<!-- <property name="driverClassName"
value="org.postgresql.Driver" /> -->
<!-- <property name="url"
value="jdbc:postgresql://localhost:5432/ims" /> -->
<!--
<property name="username" value="postgres" /> -->
<!--
<property name="password" value="admin" /> -->
<!--
</bean> -->
<!--
EntityManagerFactory -->
<!-- This
produces a container-managed EntityManagerFactory;
rather
than application-managed EntityManagerFactory as in case of
LocalEntityManagerFactoryBean-->
<bean
id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property
name="dataSource" ref="dataSource" />
<!-- This
makes /META-INF/persistence.xml is no longer necessary -->
<property
name="packagesToScan" value="com.ray.springsecurity.pojos.model"
/>
<!--
JpaVendorAdapter implementation for Hibernate EntityManager.
Exposes
Hibernate's persistence provider and EntityManager extension interface -->
<property
name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
/>
</property>
<property
name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- This
transaction manager is appropriate for applications that use a single JPA
EntityManagerFactory for transactional data access.
JTA
(usually through JtaTransactionManager) is necessary for accessing multiple
transactional resources within the same transaction. -->
<bean
id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property
name="entityManagerFactory" ref="entityManagerFactory"
/>
</bean>
<!--
responsible for registering the necessary Spring components that power
annotation-driven transaction management;
such as
when @Transactional methods are invoked -->
<tx:annotation-driven />
</beans>
Login.xhtml page
When user tries to log in with wrong
username or password below page is displayed.
User alex is logging in
add.xhtml
is displayed after user alex has logged
Admin
raichand70 is logging in
Admin
raichand70 has successfully logged in so
crud.xhtml is displayed.
======================================================================
pom.xml
pom.xml
<?xml
version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.raywebsites</groupId>
<artifactId>PrimefacesSpringsecurityMavenCRUD</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>PrimefacesSpringsecurityMavenCRUD</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!--Javax inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!--Java Annotation Indexer -->
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.0.3.Final</version>
</dependency>
<!-- aopalliance -->
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<!--Spring Framework-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!--spring-data-commons -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.13.1.RELEASE</version>
</dependency>
<!-- Spring Data JPA dependencies
-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.0.RELEASE</version>
</dependency>
<!-- aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency>
<!-- querydsl-apt -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.4</version>
</dependency>
<!-- Spring Security Libraries
-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>4.1.3.RELEASE
</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
<version>4.1.3.RELEASE
</version>
</dependency>
<!-- aspectjrt -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.10</version>
</dependency>
<!--Web Dependencies-->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.2</version>
</dependency>
<!--Java Server Faces-->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.7</version>
</dependency>
<!--Primefaces-->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<!--Hibernate-->
<!-- hibernate-entitymanager
-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.10.Final</version>
</dependency>
<!--hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.10.Final</version>
</dependency>
<!-- Database dependencies -->
<!-- MySql Connector -->
<dependency>
<groupId> mysql
</groupId>
<artifactId>
mysql-connector-java </artifactId>
<version> 5.1.35
</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<url>http://repository.primefaces.org/</url>
<id>PrimeFaces-maven-lib</id>
<layout>default</layout>
<name>Repository for library
PrimeFaces-maven-lib</name>
</repository>
</repositories>
</project>
---------------------------------------------------------------------------------------------------------
For downloading project files the URL is
https://www.dropbox.com/s/tshpm3gkdoezw6m/SpringSecurityPrimeFacesCRUD-XML-Configuration.rar?dl=0
---------------------------------------------------------------------------------------------------------
For downloading project files the URL is
https://www.dropbox.com/s/tshpm3gkdoezw6m/SpringSecurityPrimeFacesCRUD-XML-Configuration.rar?dl=0