diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/SSProject/pom.xml b/SSProject/pom.xml index 96728d4..bfb2ef8 100644 --- a/SSProject/pom.xml +++ b/SSProject/pom.xml @@ -1,68 +1,193 @@ - - 4.0.0 + + + 4.0.0 + - org.springframework.boot - spring-boot-starter-parent - 2.7.3 - + + org.springframework.boot + + + spring-boot-starter-parent + + + 2.7.3 + + + - com.example - spring-boot - 0.0.1-SNAPSHOT - spring-boot - Demo project for Spring Boot + + com.example + + + spring-boot + + + 0.0.1-SNAPSHOT + + + spring-boot + + + Demo project for Spring Boot + - 17 + + 17 + - - org.springframework.boot - spring-boot-starter-web + + org.springframework.boot + + + spring-boot-starter-data-jpa + - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - + + org.springframework.boot + + + spring-boot-starter-security + + + + + org.springframework.boot + + + spring-boot-starter-thymeleaf + + + + + org.springframework.boot + + + spring-boot-starter-web + + + + + org.springframework.boot + + + spring-boot-devtools + + + runtime + + + true + + + + + mysql + + + mysql-connector-java + + + runtime + + - org.springframework.boot - spring-boot-starter-security + + org.springframework.boot + + + spring-boot-starter-test + + + test + + + + + org.junit.vintage + + + junit-vintage-engine + + + - org.springframework.boot - spring-boot-starter-test - test + + org.springframework.security + + + spring-security-test + + + test + - org.apache.tomcat - tomcat-jasper - 9.0.65 + + org.webjars + + + jquery + + + 3.4.1 + - org.springframework.boot - spring-boot-devtools + + org.webjars + + + bootstrap + + + 4.3.1 + + + + org.webjars + bootstrap + 3.3.7-1 + + + org.webjars + jquery + 3.1.1 + + + + org.webjars + + + webjars-locator-core + - org.springframework.boot - spring-boot-starter-thymeleaf + + org.apache.tomcat + + + tomcat-jasper + + + 9.0.65 + - - - + - org.springframework.boot - spring-boot-maven-plugin + + org.springframework.boot + + + spring-boot-maven-plugin + - diff --git a/SSProject/src/main/java/com/catalyst/funds/Application.java b/SSProject/src/main/java/com/catalyst/funds/Application.java index 98d1c60..78b8340 100644 --- a/SSProject/src/main/java/com/catalyst/funds/Application.java +++ b/SSProject/src/main/java/com/catalyst/funds/Application.java @@ -11,4 +11,5 @@ public static void main(String[] args) { } -} \ No newline at end of file +} +//same \ No newline at end of file diff --git a/SSProject/src/main/java/com/catalyst/funds/controller/WebController.java b/SSProject/src/main/java/com/catalyst/funds/controller/WebController.java index 7b17f36..5b30e8b 100644 --- a/SSProject/src/main/java/com/catalyst/funds/controller/WebController.java +++ b/SSProject/src/main/java/com/catalyst/funds/controller/WebController.java @@ -1,9 +1,16 @@ package com.catalyst.funds.controller; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.Ordered; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; @@ -12,13 +19,50 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; +import com.catalyst.funds.entity.UserEntity; +import com.catalyst.funds.repositry.UserAuthRepositry; +import com.catalyst.funds.repositry.UserRepositry; + + @Controller @EnableWebMvc public class WebController extends WebMvcConfigurerAdapter { - + @Autowired + private UserRepositry userRepo; + + @GetMapping("") + public String viewHomePage() { + return "index"; + } + + @GetMapping("/register") + public String showRegistrationForm(Model model) { + model.addAttribute("user", new UserEntity()); + + return "signup_form"; + } + + @PostMapping("/process_register") + public String processRegister(UserEntity user) { + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + String encodedPassword = passwordEncoder.encode(user.getPassword()); + user.setPassword(encodedPassword); + + userRepo.save(user); + + return "register_success"; + } - @RequestMapping("/") + @GetMapping("/users") + public String listUsers(Model model) { + Iterable listUsers = userRepo.findAll(); + model.addAttribute("listUsers", listUsers); + + return "users"; + } + + @RequestMapping("/userhome") public String index(){ return "webpage.html"; } @@ -34,7 +78,7 @@ public String loignerror() { public String signup() { return "signup.html"; } - @RequestMapping("/addteam") + @RequestMapping("/createteam") public String addteam() { return "teamadd.html"; } @@ -50,7 +94,10 @@ public String admin() { public String modifyteam() { return "modifyteam.html"; } - + @RequestMapping("/about") + public String about() { + return "about.html"; + } } diff --git a/SSProject/src/main/java/com/catalyst/funds/entity/UserEntity.java b/SSProject/src/main/java/com/catalyst/funds/entity/UserEntity.java index 949f268..f746ee3 100644 --- a/SSProject/src/main/java/com/catalyst/funds/entity/UserEntity.java +++ b/SSProject/src/main/java/com/catalyst/funds/entity/UserEntity.java @@ -2,6 +2,7 @@ import java.util.Set; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -18,13 +19,13 @@ public class UserEntity { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer userId; - + @Column(nullable = false, unique = true, length = 45) private String userName; - + @Column(nullable = false, length = 45) private String email; - + @Column(nullable = false, length = 10) private Long phoneNo; - + @Column(nullable = false, length = 64) private String password; private String role; @@ -103,4 +104,6 @@ public void setPassword(String password) { } -} \ No newline at end of file +} + +//same \ No newline at end of file diff --git a/SSProject/src/main/java/com/catalyst/funds/security/Mvcon.java b/SSProject/src/main/java/com/catalyst/funds/security/Mvcon.java index 6833376..a94a288 100644 --- a/SSProject/src/main/java/com/catalyst/funds/security/Mvcon.java +++ b/SSProject/src/main/java/com/catalyst/funds/security/Mvcon.java @@ -1,20 +1,20 @@ -package com.catalyst.funds.security; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -@EnableWebMvc -@ComponentScan("org.springframework.security.samples.mvc") -public class Mvcon implements WebMvcConfigurer{ - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**") - .addResourceLocations("/resources/"); -} -} +//package com.catalyst.funds.security; +// +//import org.springframework.context.annotation.ComponentScan; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.core.Ordered; +//import org.springframework.web.servlet.config.annotation.EnableWebMvc; +//import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +//import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +// +//@Configuration +//@EnableWebMvc +//@ComponentScan("org.springframework.security.samples.mvc") +//public class Mvcon implements WebMvcConfigurer{ +// @Override +// public void addResourceHandlers(ResourceHandlerRegistry registry) { +// registry.addResourceHandler("/resources/**") +// .addResourceLocations("/resources/"); +//} +//} diff --git a/SSProject/src/main/java/com/catalyst/funds/security/MyUserDetailsService.java b/SSProject/src/main/java/com/catalyst/funds/security/MyUserDetailsService.java index 38daf3f..e6be148 100644 --- a/SSProject/src/main/java/com/catalyst/funds/security/MyUserDetailsService.java +++ b/SSProject/src/main/java/com/catalyst/funds/security/MyUserDetailsService.java @@ -23,11 +23,9 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx UserEntity user = repo.findByUserName(username); if(user==null) throw new UsernameNotFoundException("User 404"); - //return User.withUsername(user.getUsername()).password(user.getPassword()).build(); return new UserPrinciple(user); } - - } +//same \ No newline at end of file diff --git a/SSProject/src/main/java/com/catalyst/funds/security/SecurityConfig.java b/SSProject/src/main/java/com/catalyst/funds/security/SecurityConfig.java index b79c1b1..eca7309 100644 --- a/SSProject/src/main/java/com/catalyst/funds/security/SecurityConfig.java +++ b/SSProject/src/main/java/com/catalyst/funds/security/SecurityConfig.java @@ -1,5 +1,7 @@ package com.catalyst.funds.security; +import javax.sql.DataSource; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,56 +15,80 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration @EnableWebSecurity - -public class SecurityConfig extends WebSecurityConfigurerAdapter +public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Autowired - private UserDetailsService userDetailsService; + @Autowired + private UserDetailsService userDetailsService; + @Autowired + private DataSource dataSource; + @Bean + public UserDetailsService userDetailsService() { + return new MyUserDetailsService(); + } + + @Bean + public PasswordEncoder getPassword() { + return new BCryptPasswordEncoder(); + } + @Bean - public DaoAuthenticationProvider authenticationProvider() { - DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); - authProvider.setUserDetailsService(userDetailsService); - authProvider.setPasswordEncoder(getPassword()); - - return authProvider; + public DaoAuthenticationProvider authenticationProvider() { + DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); + authProvider.setUserDetailsService(userDetailsService); + authProvider.setPasswordEncoder(getPassword()); + + return authProvider; + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.authenticationProvider(authenticationProvider()); } - @Bean - public PasswordEncoder getPassword() - { - return new BCryptPasswordEncoder(); - } - @Override protected void configure(HttpSecurity http) throws Exception { http - .csrf().disable() + + .csrf().disable() .authorizeRequests() +// .antMatchers("/mapping").authenticated() use this to require login for user for each mapping + + .antMatchers("/createteam").authenticated() + .antMatchers("/addtoteam").authenticated() + .antMatchers("/admin").authenticated() + .antMatchers("/modifyteam").authenticated() + .antMatchers("/resources/**","/userdata").permitAll() .antMatchers("/static/**").permitAll() .antMatchers("/js/**").permitAll() + .antMatchers("/webjars/**").permitAll() .antMatchers("/templates/**").permitAll() .antMatchers("/css/**").permitAll() .antMatchers("/signup/**").permitAll() - - .anyRequest().authenticated() + .anyRequest().permitAll() .and() .formLogin() - .loginPage("/login") + .loginPage("/login") .permitAll() .and() - .logout() - .permitAll(); + .logout().logoutSuccessUrl("/").permitAll(); } - + + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**") + .addResourceLocations("/resources/"); + } + public void configure2(WebSecurity web) throws Exception { web.ignoring().antMatchers("/resources/**"); web.ignoring().antMatchers("/static/**"); diff --git a/SSProject/src/main/java/com/catalyst/funds/security/UserPrinciple.java b/SSProject/src/main/java/com/catalyst/funds/security/UserPrinciple.java index 31276ea..aa60ae8 100644 --- a/SSProject/src/main/java/com/catalyst/funds/security/UserPrinciple.java +++ b/SSProject/src/main/java/com/catalyst/funds/security/UserPrinciple.java @@ -24,7 +24,8 @@ public UserPrinciple(UserEntity user) { @Override public Collection getAuthorities() { // TODO Auto-generated method stub - return Collections.singleton(new SimpleGrantedAuthority("USER")); + //return Collections.singleton(new SimpleGrantedAuthority("USER")); + return null; } @Override @@ -68,3 +69,4 @@ public boolean isEnabled() { } } +//same diff --git a/SSProject/src/main/resources/templates/about.html b/SSProject/src/main/resources/templates/about.html new file mode 100644 index 0000000..467e5d7 --- /dev/null +++ b/SSProject/src/main/resources/templates/about.html @@ -0,0 +1,98 @@ + + + + + + +
+
+

Yoru

+

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Magni autem non ut deserunt voluptatem quae officia explicabo animi voluptates maxime odit veritatis, iure aspernatur quod officiis nostrum nulla vitae praesentium?Lorem ipsum, dolor sit amet consectetur adipisicing elit. Vero atque consequuntur praesentium! Natus aperiam dicta illo nemo aspernatur quibusdam sed fuga nostrum obcaecati, laboriosam exercitationem? Doloremque reprehenderit aliquam cupiditate molestiae?

+

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Magni autem non ut deserunt voluptatem quae officia explicabo animi voluptates maxime odit veritatis, iure aspernatur quod officiis nostrum nulla vitae praesentium?Lorem ipsum, dolor sit amet consectetur adipisicing elit. Vero atque consequuntur praesentium! Natus aperiam dicta illo nemo aspernatur quibusdam sed fuga nostrum obcaecati, laboriosam exercitationem? Doloremque reprehenderit aliquam cupiditate molestiae?

+
+ +
+
+

Killua Joy

+

Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil consectetur quos quo error modi totam, dolores necessitatibus itaque, alias eligendi qui impedit nesciunt suscipit aliquam, debitis illo officia nulla option Lorem ipsum dolor sit amet consectetur adipisicing elit. Natus, non. Eligendi dolorem, repellendus debitis non officia eveniet quasi repudiandae quis modi, culpa repellat vel perferendis, voluptas excepturi quod ipsa placeat?

+

Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil consectetur quos quo error modi totam, dolores necessitatibus itaque, alias eligendi qui impedit nesciunt suscipit aliquam, debitis illo officia nulla option Lorem ipsum dolor sit amet consectetur adipisicing elit. Natus, non. Eligendi dolorem, repellendus debitis non officia eveniet quasi repudiandae quis modi, culpa repellat vel perferendis, voluptas excepturi quod ipsa placeat?

+
+ + + \ No newline at end of file diff --git a/SSProject/src/main/resources/templates/dfemo.ts b/SSProject/src/main/resources/templates/dfemo.ts deleted file mode 100644 index e69de29..0000000 diff --git a/SSProject/src/main/resources/templates/index.html b/SSProject/src/main/resources/templates/index.html new file mode 100644 index 0000000..48e01f9 --- /dev/null +++ b/SSProject/src/main/resources/templates/index.html @@ -0,0 +1,76 @@ + + + + + Welcome to CodeJava Home + + + + + + + +
+ + +
+
+
+

SS Project

+

+ Lorem ipsum dolor sit amet consectetur, adipisicing elit. Asperiores amet quia veniam delectus magni perspiciatis harum. Alias quae iste fugiat sint animi, autem tenetur dolores saepe inventore fugit? Modi, delectus.Lorem ipsum dolor sit amet consectetur adipisicing elit. Explicabo recusandae corrupti debitis iste at distinctio omnis sit adipisci saepe ducimus maxime repellat quas, doloribus, perspiciatis voluptate! Rem totam rerum architecto? + Lorem ipsum dolor, sit amet consectetur adipisicing elit. Corporis odio iste nesciunt asperiores omnis minus quia doloribus aspernatur nostrum consequatur aperia

+ Signup + + Login +
+
+ An illustration +
+
+
+ +
+ All content © SS Project. All rights reserved. +
+
+ + \ No newline at end of file diff --git a/SSProject/src/main/resources/templates/login.html b/SSProject/src/main/resources/templates/login.html index 0c023e0..ccc2f2d 100644 --- a/SSProject/src/main/resources/templates/login.html +++ b/SSProject/src/main/resources/templates/login.html @@ -1,102 +1,178 @@ Login | SSProject + + - - + + +
+ +
+ Invalid username and password. +
+
+ You have been logged out. +
+ +
\ No newline at end of file diff --git a/SSProject/src/main/resources/templates/register_success.html b/SSProject/src/main/resources/templates/register_success.html new file mode 100644 index 0000000..76b35ef --- /dev/null +++ b/SSProject/src/main/resources/templates/register_success.html @@ -0,0 +1,17 @@ + + + + + Registration Success + + + + + +
+

You have signed up successfully!

+

Click here to Login

+
+ + + \ No newline at end of file diff --git a/SSProject/src/main/resources/templates/signup_form.html b/SSProject/src/main/resources/templates/signup_form.html new file mode 100644 index 0000000..068b604 --- /dev/null +++ b/SSProject/src/main/resources/templates/signup_form.html @@ -0,0 +1,189 @@ + + + + Login | SSProject + + + + + + + + + + +
+ + +
+ + + diff --git a/SSProject/src/main/resources/templates/temp.html b/SSProject/src/main/resources/templates/temp.html index e69de29..dd42588 100644 --- a/SSProject/src/main/resources/templates/temp.html +++ b/SSProject/src/main/resources/templates/temp.html @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/SSProject/src/main/resources/templates/users.html b/SSProject/src/main/resources/templates/users.html new file mode 100644 index 0000000..2ad5134 --- /dev/null +++ b/SSProject/src/main/resources/templates/users.html @@ -0,0 +1,46 @@ + + + + + List Users + + + + + +
+
+
+

+ Welcome [[${#request.userPrincipal.principal.fullName}]] +

+ +
+
+
+

List of Users

+
+ +
+ + + + + + + + + + + + + + + + + +
User IDE-mailFirst NameLast Name
User IDE-mailFirst NameLast Name
+
+
+ + \ No newline at end of file