Primefaces

Add Hdiv dependencies

Add the following dependencies to your pom.xml file:

<dependency>
    <groupId>org.hdiv.ee</groupId>
    <artifactId>hdiv-ee-jsf</artifactId>
    <version>${org.hdiv-ee-version}</version>
</dependency>
<dependency>
    <groupId>org.hdiv.ee</groupId>
    <artifactId>hdiv-ee-config</artifactId>
    <version>${org.hdiv-ee-version}</version>
</dependency>
<dependency>
    <groupId>com.hdivsecurity</groupId>
    <artifactId>hdiv-primefaces</artifactId>
    <version>${com.hdiv-ee-primefaces}</version>
</dependency>

Note

Replace ${org.hdiv-ee-version} and ${com.hdiv-ee-primefaces} variables with the ones sent by our support team.

Modify web.xml file

Add Hdiv filter, listener, Hdiv faces config and Hdiv configuration to the web.xml file.

<!-- Hdiv initialization listener -->
<listener>
    <listener-class>org.hdiv.listener.InitListener</listener-class>
</listener>
...
<!-- Hdiv Validator Filter -->
<filter>
    <filter-name>ValidatorFilter</filter-name>
    <filter-class>org.hdiv.filter.ValidatorFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ValidatorFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
    <filter-name>ValidatorFilter</filter-name>
    <url-pattern>*.xhtml</url-pattern>
</filter-mapping>
...
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/hdiv-config.xml</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>WEB-INF/config/hdiv-faces-config.xml</param-value>
</context-param>

Create hdiv-faces-config.xml file

Create a new hdiv-faces-config.xml file with this content:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
    <component>
        <component-type>javax.faces.Parameter</component-type>
        <component-class>org.hdiv.components.UIParameterExtension</component-class>
    </component>
    <component>
        <component-type>javax.faces.HtmlInputHidden</component-type>
        <component-class>org.hdiv.components.HtmlInputHiddenExtension</component-class>
    </component>
    <!-- Primefaces components -->
    <component>
        <component-type>org.primefaces.component.PickList</component-type>
        <component-class>com.hdivsecurity.primefaces.component.PickListExt</component-class>
    </component>
    <lifecycle>
        <phase-listener>org.hdiv.phaseListeners.ComponentMessagesPhaseListener</phase-listener>
        <phase-listener>org.hdiv.phaseListeners.ConfigPhaseListener</phase-listener>
        <phase-listener>org.hdiv.phaseListeners.ValidatorPhaseListener</phase-listener>
    </lifecycle>
    <factory>
        <external-context-factory>org.hdiv.ee.context.ExternalContextFactoryWrapper</external-context-factory>
    </factory>
</faces-config>

Hdiv configuration using XML

If Spring is configured using XML file, create a new hdiv-config.xml file inside WEB-INF folder. This is the basic content with the minimum configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:hdiv="http://www.hdiv.org/schema/hdiv-ee"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.hdiv.org/schema/hdiv-ee http://www.hdiv.org/schema/hdiv/hdiv-ee.xsd">

    <hdiv:config confidentiality="false" avoidCookiesConfidentiality="true" maxPagesPerSession="10">
        <hdiv:sessionExpired homePage="/" loginPage="/"/>
        <hdiv:startPages method="get">,/,/javax.faces.resource/.*</hdiv:startPages>
    </hdiv:config>

    <hdiv:editableValidations>
        <hdiv:validationRule url=".*"></hdiv:validationRule>
    </hdiv:editableValidations>

</beans>

Hdiv configuration using Java

If Spring is configured using Java, create an @Configuration file. For example:

import org.hdiv.config.annotation.ExclusionRegistry;
import org.hdiv.config.annotation.RuleRegistry;
import org.hdiv.ee.config.annotation.EnableHdivWebSecurity;
import org.hdiv.ee.config.annotation.ValidationConfigurer;
import org.hdiv.ee.config.annotation.builders.SecurityConfigBuilder;
import org.hdiv.ee.config.annotation.configuration.HdivWebSecurityConfigurerAdapter;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableHdivWebSecurity
public class HdivConfiguration extends HdivWebSecurityConfigurerAdapter {

    @Override
    public void configure(final SecurityConfigBuilder builder) {
        builder.confidentiality(false).
                cookiesConfidentiality(false).
                maxPagesPerSession(10).
                sessionExpired().homePage("/").loginPage("/");
    }

    @Override
    public void addExclusions(final ExclusionRegistry registry) {
        registry.addUrlExclusions("/", "/javax.faces.resource/.*").method("GET");
    }

    @Override
    public void configureEditableValidation(final ValidationConfigurer validationConfigurer) {
        validationConfigurer.addValidation(".*");
    }
}

Now the application is ready to go. Deploy the project to the server and start it.