From: prashantgosai11 Date: Fri, 08 Jan 2021 18:05:27 +0530 Subject: login --- login --- --- 'a/pom.xml' +++ b/pom.xml @@ -74,6 +74,23 @@ + + org.springframework.boot + spring-boot-starter-security + compile + + + org.springframework.security + spring-security-taglibs + + + + + org.springframework.security + spring-security-config + + + javax.servlet --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Controller/LoginController.java @@ -0,0 +1,81 @@ +package com.GisSatellite.Server.Controller; + +import java.util.HashSet; +import java.util.Map; + + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +import com.GisSatellite.Server.Entities.Role; +import com.GisSatellite.Server.Entities.User; +import com.GisSatellite.Server.Repository.UserRepository; + +@Controller +public class LoginController { + @Autowired + private BCryptPasswordEncoder passwordEncoder; + + @Autowired + private UserRepository userRepository; + + @RequestMapping("/") + public String Default() { + return "login"; + } + @RequestMapping("/login") + public String login() { + return "login"; + } + @RequestMapping("/logout") + public String logout() { + + return "login"; + } + + @RequestMapping(value = "/register", method = RequestMethod.GET) + public String registerPage(Model model) { + + model.addAttribute("user", new User()); + return "register"; + } + + @RequestMapping(value = "/register", method = RequestMethod.POST) + public String saveRegisterPage(@Validated @ModelAttribute("user") User user, @RequestParam String role, BindingResult result, Model model, + Map map) { + + model.addAttribute("user", user); + if (result.hasErrors()) { + return "register"; + } + else + + { + + + Role r=new Role(); + r.setRole(role); + user.setRoles(new HashSet() {{ + add(r); + }}); + String pwd = user.getPassword(); + String encryptPwd = passwordEncoder.encode(pwd); + user.setPassword(encryptPwd); + map.put("message", "Successful"); + userRepository.save(user); + + } + return "register"; + } + +} \ No newline at end of file --- 'a/src/main/java/com/GisSatellite/Server/Controller/SatelliteController.java' +++ b/src/main/java/com/GisSatellite/Server/Controller/SatelliteController.java @@ -16,11 +16,13 @@ import org.locationtech.jts.geom.Geometr import org.locationtech.jts.io.WKTReader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.repository.query.Param; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -37,7 +39,7 @@ import com.sun.el.parser.ParseException; @Controller - +@PreAuthorize("hasRole('admin')") public class SatelliteController { @@ -55,10 +57,16 @@ public class SatelliteController { public String home1() { return "satelliteform"; } - @RequestMapping("/attributenew") - public String homenew() { + + @GetMapping("/admin") + public String admin() { return "attributenew"; } + + /* + * @RequestMapping("/attributenew") public String homenew() { return + * "attributenew"; } + */ @RequestMapping("/attribute") public String home2() { --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Entities/Role.java @@ -0,0 +1,31 @@ +package com.GisSatellite.Server.Entities; + +import javax.persistence.*; + + + +@Entity + + + +public class Role { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int role_id; + private String role; + public int getRole_id() { + return role_id; + } + public void setRole_id(int role_id) { + this.role_id = role_id; + } + public String getRole() { + return role; + } + public void setRole(String role) { + this.role = role; + } + + + +} --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Entities/User.java @@ -0,0 +1,64 @@ +package com.GisSatellite.Server.Entities; + +import java.util.Set; + +import javax.persistence.*; + + + + + +@Entity + +@Table(name = "login", uniqueConstraints = { @UniqueConstraint(columnNames = "user_id") }) +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int user_id; + private String username; + private String password; + + + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id")) + private Set roles; + + + public int getUser_id() { + return user_id; + } + + public void setUser_id(int user_id) { + this.user_id = user_id; + } + + 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; + } + + + + public Set getRoles() { + return roles; + } + + public void setRoles(Set roles) { + this.roles = roles; + } + + + + +} --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Repository/RoleRepository.java @@ -0,0 +1,10 @@ +package com.GisSatellite.Server.Repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.GisSatellite.Server.Entities.Role; + + +public interface RoleRepository extends JpaRepository { + +} \ No newline at end of file --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Repository/UserRepository.java @@ -0,0 +1,12 @@ +package com.GisSatellite.Server.Repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.GisSatellite.Server.Entities.User; + + +public interface UserRepository extends JpaRepository { + + User findByUsername(String username); + +} \ No newline at end of file --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Security/MyAuthenticationSuccessHandler.java @@ -0,0 +1,51 @@ +package com.GisSatellite.Server.Security; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +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.GrantedAuthority; +import org.springframework.security.web.DefaultRedirectStrategy; +import org.springframework.security.web.RedirectStrategy; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; + +public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler { + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, + Authentication authentication) throws IOException, ServletException { + + String targetUrl = determineTargetUrl(authentication); + + if (response.isCommitted()) { + System.out.println("Response has already been committed. Unable to redirect to " + + targetUrl); + return; + } + RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); + redirectStrategy.sendRedirect(request, response, targetUrl); + System.out.println(""); + } + protected String determineTargetUrl(final Authentication authentication) { + + Map roleTargetUrlMap = new HashMap<>(); + roleTargetUrlMap.put("ROLE_user", "/user"); + roleTargetUrlMap.put("ROLE_admin", "/admin"); + + final Collection authorities = authentication.getAuthorities(); + for (final GrantedAuthority grantedAuthority : authorities) { + String authorityName = grantedAuthority.getAuthority(); + if(roleTargetUrlMap.containsKey(authorityName)) { + return roleTargetUrlMap.get(authorityName); + } + } + + throw new IllegalStateException(); + } +} --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Security/SecurityConfig.java @@ -0,0 +1,52 @@ +package com.GisSatellite.Server.Security; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +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.web.authentication.AuthenticationSuccessHandler; + +import com.GisSatellite.Server.Services.User_DetailsService; + + + +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private User_DetailsService userDetailsService; + + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(encodePwd()); + + } + @Bean + public AuthenticationSuccessHandler myAuthenticationSuccessHandler(){ + return new MyAuthenticationSuccessHandler(); + } + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers("/login","/register","/webjars/**","/**/*.js", "/**/*.css","/**/*.jpg","/**/*.png").permitAll() + .antMatchers("/openlayers").access("hasRole('admin')") + .anyRequest().authenticated().and() + .formLogin().loginPage("/login").successHandler(myAuthenticationSuccessHandler()).and() + .logout() + .logoutSuccessUrl("/login").permitAll().and() + .exceptionHandling().accessDeniedPage("/logout").and() + .headers().frameOptions().disable().and() + .csrf().disable(); + } + @Bean + public BCryptPasswordEncoder encodePwd() { + return new BCryptPasswordEncoder(); + } +} \ No newline at end of file --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Services/User_Details.java @@ -0,0 +1,64 @@ +package com.GisSatellite.Server.Services; + +import java.util.Collection; +import java.util.stream.Collectors; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import com.GisSatellite.Server.Entities.User; + + + +public class User_Details implements UserDetails { + private static final long serialVersionUID = -5584720112233431845L; + + private User user; + + @Override + public Collection getAuthorities() { + return user.getRoles().stream().map(role -> new SimpleGrantedAuthority("ROLE_"+role.getRole())) + .collect(Collectors.toList()); + + } + + @Override + public String getPassword() { + return user.getPassword(); + } + + @Override + public String getUsername() { + return user.getUsername(); + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + +} --- /dev/null +++ b/src/main/java/com/GisSatellite/Server/Services/User_DetailsService.java @@ -0,0 +1,36 @@ +package com.GisSatellite.Server.Services; + +import org.springframework.beans.factory.annotation.Autowired; +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.Component; + +import com.GisSatellite.Server.Entities.User; +import com.GisSatellite.Server.Repository.UserRepository; + + +@Component +public class User_DetailsService implements UserDetailsService{ + + @Autowired + private UserRepository userRepository; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + User user=userRepository.findByUsername(username); + User_Details userDetails=null; + if (user!=null) { + userDetails=new User_Details(); + userDetails.setUser(user); + }else { + throw new UsernameNotFoundException("User not exist with this name : "+username); + } + + + return userDetails; + + + } + +} \ No newline at end of file --- 'a/src/main/resources/static/assets/css/style.css' +++ b/src/main/resources/static/assets/css/style.css @@ -455,7 +455,7 @@ html body .b-all { } .text-muted { - color: #99abb4!important + color: #fff!important } .text-warning { @@ -2141,8 +2141,8 @@ form label { animation-iteration-count: infinite; animation-timing-function: linear; position: absolute; - top: 18px; - left: 18px + top: 11px; + left: 11px } .right-sidebar { @@ -3861,7 +3861,14 @@ table th { } table.dataTable thead .sorting, table.dataTable thead .sorting_asc, table.dataTable thead .sorting_asc_disabled, table.dataTable thead .sorting_desc, table.dataTable thead .sorting_desc_disabled { - background: transparent + /* background: transparent + background-color: #1976d2; + color: #ffffff;*/ +} +.table thead +{ +background-color: #1976d2; +color:#fff; } table.dataTable thead .sorting_asc:after { @@ -8112,8 +8119,8 @@ form p:last-child { [type=checkbox]:checked, [type=checkbox]:not(:checked) { position: absolute; - left: -9999px; - opacity: 0 + /* left: -9999px; + opacity: 0 */ } [type=checkbox] {} @@ -8455,7 +8462,7 @@ input[type=checkbox]:not(:disabled).tabb position: fixed; top: 94px; right: 20px; - padding: 25px; + padding: 18px; z-index: 10; } Binary files /dev/null and b/src/main/resources/static/assets/images/1 differ Binary files /dev/null and b/src/main/resources/static/assets/images/6.jpg differ Binary files /dev/null and b/src/main/resources/static/assets/images/alert/satelite.jpg differ --- 'a/src/main/resources/static/mis/js/customscripts/search.js' +++ b/src/main/resources/static/mis/js/customscripts/search.js @@ -50,4 +50,5 @@ $(document).ready(function () { console.log(data); - } \ No newline at end of file + } + \ No newline at end of file --- /dev/null +++ b/src/main/resources/static/mis/js/customscripts/tables.js @@ -0,0 +1,101 @@ +$(document).ready(function () { +defaultTable(); +}); +function defaultTable() + { + var data=allTableData(); + + loadtable(data); + } + + //for datatable code + + function loadtable(data){ + console.log(data); + if ( $.fn.DataTable.isDataTable( '#getASIReportList' ) ) { + $("#getASIReportList").dataTable().fnDestroy(); + $('#getASIReportList').empty(); + } + + + var table=$('#getASIReportList').DataTable({ + pageLength : 5, + dom: 'Bfrtip', + buttons: [ + 'copy', 'csv', 'excel', 'pdf', 'print' + ], + + 'processing': true, + + 'columnDefs': [{ + 'targets': 0, + 'searchable': false, + 'orderable': false, + 'className': 'dt-body-center', + + 'render': function (data, type, full, meta){ + + var longlat='['+full.center_long+','+full.center_lat+']'; + + var lname='['+full.lllat+']'; + + return ''; + + + + }, + + }], + + + + + + "data":data , + + columns : [{ + title : '', + data : '' + + },{ + title : 'Layer Name', + data : 'layername' + }, { + title : 'Satellite', + data : 'satelite' + }, { + title : 'Sensor', + data : 'sansor' + },{ + title: 'Date Of Pass', + data :'date' + }, { + title : 'Path', + data : 'path' + }, { + title : 'Row', + data : 'row', + + }, { + title : 'Center latitude', + data : 'center_lat', + + },{ + title : 'Center longitude', + data : 'center_long', + + } + + ], + + + + }); + + + + } +//close datatable + + + \ No newline at end of file --- 'a/src/main/resources/static/mis/js/services/misservices.js' +++ b/src/main/resources/static/mis/js/services/misservices.js @@ -48,12 +48,28 @@ function gttdatafromgeom(id) }); return data; - -// let url = `http://localhost:9080/intersectbygeom/${id}`; -// fetch(url).then((response)=>{ -// return response.json(); -// }).then((data)=>{ -// console.log(data); - -// }) +} +function allTableData() +{ + var data=null; + $.ajax({ + url:"findAll", + method:"GET", + dtaType:"json", + async: false, + data:{}, + success:function(j) + { + + console.log(j); + data=j; + + + }, + error:function (error) + { + alert(error); + } + }); + return data; } --- 'a/src/main/webapp/views/attributenew.jsp' +++ b/src/main/webapp/views/attributenew.jsp @@ -11,8 +11,8 @@ - - Admin Press Admin Template - The Ultimate Bootstrap 4 Admin Template + + SDIS @@ -35,6 +35,7 @@ + @@ -426,9 +427,10 @@
-

Sales Difference

-
Check the difference between two site
-
+ +
+
+
@@ -522,6 +524,7 @@ + @@ -580,7 +583,16 @@ - + + + + + + + + + + --- /dev/null +++ b/src/main/webapp/views/login.jsp @@ -0,0 +1,136 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + + + + + + + + + + + SDIS + + + + + + + + + + + + + + + +
+ + +
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null +++ b/src/main/webapp/views/register.jsp @@ -0,0 +1,215 @@ +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + + + + + + + + + + + Material Dashboard PRO by Creative Tim + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +