From 491a4b1f95e1ea117c22fc07b47a678a689fec4f Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 4 Sep 2016 19:18:58 +0300 Subject: [PATCH] BAEL-10 custom model, dao, service, userdetails service, controller and views for register and login, configurations --- ....eclipse.wst.common.project.facet.core.xml | 2 +- spring-jpa/.springBeans | 16 ++++ spring-jpa/pom.xml | 81 +++++++++++++++++ .../org/baeldung/custom/config/MvcConfig.java | 42 +++++++++ .../config/PersistenceDerbyJPAConfig.java | 87 +++++++++++++++++++ .../custom/config/SecSecurityConfig.java | 75 ++++++++++++++++ .../baeldung/persistence/model/MyUser.java | 76 ++++++++++++++++ .../multiple/dao/user/MyUserDAO.java | 40 +++++++++ .../persistence/service/MyUserService.java | 48 ++++++++++ .../security/MyUserDetailsService.java | 36 ++++++++ .../org/baeldung/security/UserController.java | 52 +++++++++++ .../main/java/org/baeldung/web/MyUserDto.java | 41 +++++++++ .../resources/persistence-derby.properties | 10 +++ .../webapp/WEB-INF/mvc-dispatcher-servlet.xml | 86 ++++++++++++++++++ .../src/main/webapp/WEB-INF/views/index.jsp | 35 ++++++++ .../src/main/webapp/WEB-INF/views/login.jsp | 29 +++++++ .../main/webapp/WEB-INF/views/register.jsp | 24 +++++ spring-jpa/src/main/webapp/WEB-INF/web.xml | 50 +++++++++++ 18 files changed, 829 insertions(+), 1 deletion(-) create mode 100644 spring-jpa/.springBeans create mode 100644 spring-jpa/src/main/java/org/baeldung/custom/config/MvcConfig.java create mode 100644 spring-jpa/src/main/java/org/baeldung/custom/config/PersistenceDerbyJPAConfig.java create mode 100644 spring-jpa/src/main/java/org/baeldung/custom/config/SecSecurityConfig.java create mode 100644 spring-jpa/src/main/java/org/baeldung/persistence/model/MyUser.java create mode 100644 spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/MyUserDAO.java create mode 100644 spring-jpa/src/main/java/org/baeldung/persistence/service/MyUserService.java create mode 100644 spring-jpa/src/main/java/org/baeldung/security/MyUserDetailsService.java create mode 100644 spring-jpa/src/main/java/org/baeldung/security/UserController.java create mode 100644 spring-jpa/src/main/java/org/baeldung/web/MyUserDto.java create mode 100644 spring-jpa/src/main/resources/persistence-derby.properties create mode 100644 spring-jpa/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml create mode 100644 spring-jpa/src/main/webapp/WEB-INF/views/index.jsp create mode 100644 spring-jpa/src/main/webapp/WEB-INF/views/login.jsp create mode 100644 spring-jpa/src/main/webapp/WEB-INF/views/register.jsp create mode 100644 spring-jpa/src/main/webapp/WEB-INF/web.xml diff --git a/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml index b1c99d7726..a8a65de481 100644 --- a/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,7 +1,7 @@ - + diff --git a/spring-jpa/.springBeans b/spring-jpa/.springBeans new file mode 100644 index 0000000000..85bcd37cff --- /dev/null +++ b/spring-jpa/.springBeans @@ -0,0 +1,16 @@ + + + 1 + + + + + + + src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml + + + + + + diff --git a/spring-jpa/pom.xml b/spring-jpa/pom.xml index 25dd960435..531cfe3468 100644 --- a/spring-jpa/pom.xml +++ b/spring-jpa/pom.xml @@ -6,6 +6,7 @@ 0.1-SNAPSHOT spring-jpa + war @@ -115,6 +116,78 @@ test + + org.springframework + spring-core + ${org.springframework.version} + + + org.springframework + spring-web + ${org.springframework.version} + + + org.springframework + spring-webmvc + ${org.springframework.version} + + + + javax.servlet + servlet-api + 3.0-alpha-1 + + + org.springframework.security + spring-security-core + ${org.springframework.security.version} + + + org.springframework.security + spring-security-web + ${org.springframework.security.version} + + + org.springframework.security + spring-security-config + ${org.springframework.security.version} + + + + org.apache.derby + derby + 10.12.1.1 + + + org.apache.derby + derbyclient + 10.12.1.1 + + + org.apache.derby + derbynet + 10.12.1.1 + + + org.apache.derby + derbytools + 10.12.1.1 + + + taglibs + standard + 1.1.2 + + + org.springframework.security + spring-security-taglibs + 4.1.3.RELEASE + + + javax.servlet.jsp.jstl + jstl-api + 1.2 + @@ -138,6 +211,12 @@ + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + org.apache.maven.plugins maven-surefire-plugin @@ -180,6 +259,7 @@ 4.2.5.RELEASE + 4.0.4.RELEASE 3.20.0-GA @@ -210,6 +290,7 @@ 3.5.1 + 2.6 2.19.1 2.7 1.4.18 diff --git a/spring-jpa/src/main/java/org/baeldung/custom/config/MvcConfig.java b/spring-jpa/src/main/java/org/baeldung/custom/config/MvcConfig.java new file mode 100644 index 0000000000..4a9e737a92 --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/custom/config/MvcConfig.java @@ -0,0 +1,42 @@ +package org.baeldung.custom.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; + +@EnableWebMvc +@Configuration +@ComponentScan(basePackages = { "org.baeldung.security" }) +public class MvcConfig extends WebMvcConfigurerAdapter { + + public MvcConfig() { + super(); + } + + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + super.addViewControllers(registry); + + registry.addViewController("/"); + registry.addViewController("/index"); + registry.addViewController("/login"); + registry.addViewController("/register"); + } + + @Bean + public ViewResolver viewResolver() { + final InternalResourceViewResolver bean = new InternalResourceViewResolver(); + + bean.setViewClass(JstlView.class); + bean.setPrefix("/WEB-INF/view/"); + bean.setSuffix(".jsp"); + + return bean; + } +} diff --git a/spring-jpa/src/main/java/org/baeldung/custom/config/PersistenceDerbyJPAConfig.java b/spring-jpa/src/main/java/org/baeldung/custom/config/PersistenceDerbyJPAConfig.java new file mode 100644 index 0000000000..19bf952e70 --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/custom/config/PersistenceDerbyJPAConfig.java @@ -0,0 +1,87 @@ +package org.baeldung.custom.config; + +import java.util.Properties; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.baeldung.persistence.multiple.dao.user.MyUserDAO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import com.google.common.base.Preconditions; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-derby.properties" }) +public class PersistenceDerbyJPAConfig { + + @Autowired + private Environment env; + + public PersistenceDerbyJPAConfig() { + super(); + } + + // beans + + @Bean + public LocalContainerEntityManagerFactoryBean myEmf() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" }); + + final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + em.setJpaVendorAdapter(vendorAdapter); + em.setJpaProperties(additionalProperties()); + + return em; + } + + @Bean + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(emf); + return transactionManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + // hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true"); + return hibernateProperties; + } + + @Bean + public MyUserDAO myUserDAO() { + final MyUserDAO myUserDAO = new MyUserDAO(); + return myUserDAO; + } +} \ No newline at end of file diff --git a/spring-jpa/src/main/java/org/baeldung/custom/config/SecSecurityConfig.java b/spring-jpa/src/main/java/org/baeldung/custom/config/SecSecurityConfig.java new file mode 100644 index 0000000000..d20674844a --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/custom/config/SecSecurityConfig.java @@ -0,0 +1,75 @@ +package org.baeldung.custom.config; + +import org.baeldung.persistence.service.MyUserService; +import org.baeldung.security.MyUserDetailsService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + +@Configuration +@EnableWebSecurity +@Profile("!https") +public class SecSecurityConfig extends WebSecurityConfigurerAdapter { + + public SecSecurityConfig() { + super(); + } + + @Override + protected void configure(final AuthenticationManagerBuilder auth) throws Exception { + // @formatter:off + auth.authenticationProvider(authenticationProvider()); + // @formatter:on + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + // @formatter:off + http + .csrf().disable() + .authorizeRequests() + .antMatchers("/*").permitAll() + .and() + .formLogin() + .loginPage("/login") + .loginProcessingUrl("/login") + .defaultSuccessUrl("/",true) + .failureUrl("/login?error=true") + .and() + .logout() + .logoutUrl("/logout") + .deleteCookies("JSESSIONID") + .logoutSuccessUrl("/"); + // @formatter:on + } + + @Bean + public DaoAuthenticationProvider authenticationProvider() { + final DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); + authProvider.setUserDetailsService(myUserDetailsService()); + authProvider.setPasswordEncoder(encoder()); + return authProvider; + } + + @Bean + public PasswordEncoder encoder() { + return new BCryptPasswordEncoder(11); + } + + @Bean + public MyUserDetailsService myUserDetailsService() { + return new MyUserDetailsService(); + } + + @Bean + public MyUserService myUserService() { + return new MyUserService(); + } +} diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/model/MyUser.java b/spring-jpa/src/main/java/org/baeldung/persistence/model/MyUser.java new file mode 100644 index 0000000000..0a097f2782 --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/persistence/model/MyUser.java @@ -0,0 +1,76 @@ +package org.baeldung.persistence.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(schema = "spring_custom_user_service") +public class MyUser { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + private String name; + + @Column(unique = true, nullable = false) + private String username; + + @Column(nullable = false) + private String password; + + private boolean enabled; + + public MyUser() { + } + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getUsername() { + return username; + } + + public void setUsername(final String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(final String password) { + this.password = password; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(final boolean enabled) { + this.enabled = enabled; + } + + @Override + public String toString() { + return "MyUser [name=" + name + ", username=" + username + ", password=" + password + ", enabled=" + enabled + "]"; + } + +} diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/MyUserDAO.java b/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/MyUserDAO.java new file mode 100644 index 0000000000..1de8c61442 --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/MyUserDAO.java @@ -0,0 +1,40 @@ +package org.baeldung.persistence.multiple.dao.user; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +import org.baeldung.persistence.model.MyUser; +import org.springframework.stereotype.Repository; + +@Repository +public class MyUserDAO { + + @PersistenceContext + private EntityManager entityManager; + + public MyUser findByUsername(final String username) { + final Query query = entityManager.createQuery("from MyUser where username=:username", MyUser.class); + query.setParameter("username", username); + final List result = query.getResultList(); + if (result != null && result.size() > 0) { + return result.get(0); + } else + return null; + } + + public MyUser save(final MyUser user) { + entityManager.persist(user); + return user; + } + + public EntityManager getEntityManager() { + return entityManager; + } + + public void setEntityManager(final EntityManager entityManager) { + this.entityManager = entityManager; + } +} diff --git a/spring-jpa/src/main/java/org/baeldung/persistence/service/MyUserService.java b/spring-jpa/src/main/java/org/baeldung/persistence/service/MyUserService.java new file mode 100644 index 0000000000..a382e92664 --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/persistence/service/MyUserService.java @@ -0,0 +1,48 @@ +package org.baeldung.persistence.service; + +import javax.transaction.Transactional; + +import org.baeldung.persistence.model.MyUser; +import org.baeldung.persistence.multiple.dao.user.MyUserDAO; +import org.baeldung.web.MyUserDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class MyUserService { + + @Autowired + private PasswordEncoder passwordEncoder; + + @Autowired + MyUserDAO myUserDAO; + + public MyUser registerNewUserAccount(final MyUserDto accountDto) throws Exception { + if (usernameExists(accountDto.getUsername())) { + throw new Exception("There is an account with that username: " + accountDto.getUsername()); + } + final MyUser user = new MyUser(); + + user.setUsername(accountDto.getUsername()); + user.setPassword(passwordEncoder.encode(accountDto.getPassword())); + user.setName(accountDto.getName()); + user.setEnabled(true); + return myUserDAO.save(user); + } + + public MyUser getUserByUsername(final String username) { + final MyUser user = myUserDAO.findByUsername(username); + return user; + } + + private boolean usernameExists(final String username) { + final MyUser user = myUserDAO.findByUsername(username); + if (user != null) { + return true; + } + return false; + } + +} diff --git a/spring-jpa/src/main/java/org/baeldung/security/MyUserDetailsService.java b/spring-jpa/src/main/java/org/baeldung/security/MyUserDetailsService.java new file mode 100644 index 0000000000..0299d7cdcf --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/security/MyUserDetailsService.java @@ -0,0 +1,36 @@ +package org.baeldung.security; + +import java.util.ArrayList; +import java.util.Collection; + +import org.baeldung.persistence.model.MyUser; +import org.baeldung.persistence.multiple.dao.user.MyUserDAO; +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.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service("userDetailsService") +public class MyUserDetailsService implements UserDetailsService { + + @Autowired + MyUserDAO myUserDAO; + + @Override + public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { + final MyUser user = myUserDAO.findByUsername(username); + + if (user == null) { + throw new UsernameNotFoundException("No user found with username: " + username); + } + else { + final Collection authorities = new ArrayList<>(); + authorities.add(new SimpleGrantedAuthority("ROLE_USER")); + return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), user.isEnabled(), true, true, true, authorities); + } + } + +} diff --git a/spring-jpa/src/main/java/org/baeldung/security/UserController.java b/spring-jpa/src/main/java/org/baeldung/security/UserController.java new file mode 100644 index 0000000000..8664816a32 --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/security/UserController.java @@ -0,0 +1,52 @@ +package org.baeldung.security; + +import javax.annotation.Resource; + +import org.baeldung.persistence.service.MyUserService; +import org.baeldung.web.MyUserDto; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +public class UserController { + + @Resource + MyUserService myUserService; + + @RequestMapping(value = "/register", method = RequestMethod.POST) + public String registerUserAccount(final MyUserDto accountDto, final Model model) { + final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + model.addAttribute("name", auth.getName()); + try { + myUserService.registerNewUserAccount(accountDto); + model.addAttribute("message", "Registration successful"); + return "index"; + } + catch(final Exception exc){ + model.addAttribute("message", "Registration failed"); + + return "index"; + } + } + + @RequestMapping(value = "/", method = RequestMethod.GET) + public String getHomepage(final Model model) { + final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + model.addAttribute("name", auth.getName()); + return "index"; + } + + @RequestMapping(value = "/register", method = RequestMethod.GET) + public String getRegister() { + return "register"; + } + + @RequestMapping(value = "/login", method = RequestMethod.GET) + public String getLogin() { + return "login"; + } +} diff --git a/spring-jpa/src/main/java/org/baeldung/web/MyUserDto.java b/spring-jpa/src/main/java/org/baeldung/web/MyUserDto.java new file mode 100644 index 0000000000..ec95ec43bf --- /dev/null +++ b/spring-jpa/src/main/java/org/baeldung/web/MyUserDto.java @@ -0,0 +1,41 @@ +package org.baeldung.web; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +public class MyUserDto { + @NotNull + @Size(min = 1) + private String username; + + @NotNull + @Size(min = 1) + private String name; + + private String password; + + public String getUsername() { + return username; + } + + public void setUsername(final String username) { + this.username = username; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(final String password) { + this.password = password; + } + +} diff --git a/spring-jpa/src/main/resources/persistence-derby.properties b/spring-jpa/src/main/resources/persistence-derby.properties new file mode 100644 index 0000000000..2e2dee983b --- /dev/null +++ b/spring-jpa/src/main/resources/persistence-derby.properties @@ -0,0 +1,10 @@ +# jdbc.X +jdbc.driverClassName=org.apache.derby.jdbc.EmbeddedDriver +jdbc.url=jdbc:derby:memory:spring_custom_user_service;create=true +jdbc.user=tutorialuser +jdbc.pass=tutorialpass + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.DerbyDialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create \ No newline at end of file diff --git a/spring-jpa/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml b/spring-jpa/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml new file mode 100644 index 0000000000..2b33a1384a --- /dev/null +++ b/spring-jpa/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /WEB-INF/views/ + + + .jsp + + + + + + + + + + + + + + + ${hibernate.hbm2ddl.auto} + ${hibernate.dialect} + + + + + + + + + + + + + + + + + + + diff --git a/spring-jpa/src/main/webapp/WEB-INF/views/index.jsp b/spring-jpa/src/main/webapp/WEB-INF/views/index.jsp new file mode 100644 index 0000000000..0c89257cd2 --- /dev/null +++ b/spring-jpa/src/main/webapp/WEB-INF/views/index.jsp @@ -0,0 +1,35 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="c" + uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> + + + + + +Welcome! + + + + + + + +Register +

+ +Login + +

+${message } +

+ +Hello, ${name }! +
+
+Logout +
+ + + \ No newline at end of file diff --git a/spring-jpa/src/main/webapp/WEB-INF/views/login.jsp b/spring-jpa/src/main/webapp/WEB-INF/views/login.jsp new file mode 100644 index 0000000000..29431f426d --- /dev/null +++ b/spring-jpa/src/main/webapp/WEB-INF/views/login.jsp @@ -0,0 +1,29 @@ +<%@ taglib prefix="c" + uri="http://java.sun.com/jsp/jstl/core" %> + + + + + +

Login

+ +
+ + + + + + + + + + + + + +
User:
Password:
+ +
+ Username or password invalid! + + \ No newline at end of file diff --git a/spring-jpa/src/main/webapp/WEB-INF/views/register.jsp b/spring-jpa/src/main/webapp/WEB-INF/views/register.jsp new file mode 100644 index 0000000000..68b3ac14b0 --- /dev/null +++ b/spring-jpa/src/main/webapp/WEB-INF/views/register.jsp @@ -0,0 +1,24 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="c" + uri="http://java.sun.com/jsp/jstl/core" %> + + + + +Welcome! + + + + + +Register here:

+
+Username:
+Password:
+Name:

+ +
+ + + \ No newline at end of file diff --git a/spring-jpa/src/main/webapp/WEB-INF/web.xml b/spring-jpa/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..2eb6e88c31 --- /dev/null +++ b/spring-jpa/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,50 @@ + + + + Spring MVC Application + + + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + org.baeldung.custom.config + + + + org.springframework.web.context.ContextLoaderListener + + + + + mvc-dispatcher + org.springframework.web.servlet.DispatcherServlet + 1 + + + mvc-dispatcher + / + + + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + springSecurityFilterChain + /* + + + + index.jsp + + + \ No newline at end of file