Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
641a84c
Added Index html doc
springframeworkguru Jan 14, 2016
be1575a
added cdn resource
springframeworkguru Jan 14, 2016
c4d5651
Added Grid Example
springframeworkguru Jan 19, 2016
528beb7
added code review example
springframeworkguru Jan 19, 2016
88ed29c
Added html index page
springframeworkguru Jan 19, 2016
67bea74
removed temp text file
springframeworkguru Jan 19, 2016
f0a1394
added product html page
springframeworkguru Jan 20, 2016
dc36e0c
completed code assignment
springframeworkguru Jan 20, 2016
79f1d98
added spring mvc controllers
springframeworkguru Jan 20, 2016
f63d262
updated pages to thymeleaf
springframeworkguru Jan 20, 2016
b7687f5
updated with local static resources
springframeworkguru Jan 22, 2016
fdb6646
adding image resources
springframeworkguru Jan 22, 2016
1cf7d24
adding image resources
springframeworkguru Jan 22, 2016
c8358bc
adding image resources
springframeworkguru Jan 22, 2016
d9eedb4
completed code assignment for using Thymeleaf Image tags
springframeworkguru Jan 25, 2016
d45b8d7
added messages file
springframeworkguru Jan 25, 2016
cc123c6
i18n
springframeworkguru Jan 25, 2016
b787424
i18n
springframeworkguru Jan 25, 2016
24cdbe2
Added Jumbotron fragment
springframeworkguru Jan 26, 2016
0235f9a
added footer
springframeworkguru Jan 26, 2016
1b6cc09
Completed code assignment
springframeworkguru Jan 26, 2016
8bb8a55
added dev tools
springframeworkguru Jan 26, 2016
68afcfe
added spring service layer
springframeworkguru Jan 27, 2016
bd08d2a
changed product controler to return objects
springframeworkguru Jan 27, 2016
ddd6b64
added dynamic content to product page
springframeworkguru Jan 27, 2016
5af97be
updated product page
springframeworkguru Jan 27, 2016
efdc0ca
completed code assignement
springframeworkguru Jan 27, 2016
cf7b17d
Added conditional example
springframeworkguru Jan 27, 2016
68e63ca
added spring mvc config
springframeworkguru Jan 27, 2016
86c544a
added iteration example
springframeworkguru Jan 28, 2016
a85d055
added iteration w/fragments example
springframeworkguru Feb 1, 2016
619b72b
added code assignment example
springframeworkguru Feb 1, 2016
97a60bb
completed code assignment
springframeworkguru Feb 1, 2016
ce29b60
added Spring MVC Config
springframeworkguru Feb 1, 2016
a31e526
added Thymleaf Forms
springframeworkguru Feb 1, 2016
a5c2049
added bootstap validation block
springframeworkguru Feb 1, 2016
37fdbcb
Added field level statements
springframeworkguru Feb 1, 2016
7d2b664
completed code assignment
springframeworkguru Feb 2, 2016
82c4a03
completed code assignment
springframeworkguru Feb 2, 2016
21994e0
added Spring Sec Maven Deps
springframeworkguru Feb 2, 2016
d822e2a
added spring sec config
springframeworkguru Feb 5, 2016
03aa35e
added thymeleaf Spring Sec maven dep
springframeworkguru Feb 9, 2016
082e761
added page for spring sec setup
springframeworkguru Feb 9, 2016
30a3ec1
added logic for logged in users
springframeworkguru Feb 9, 2016
5107f0d
added logic for display of role information
springframeworkguru Feb 10, 2016
fbf5d25
fix
springframeworkguru Feb 10, 2016
83d52a1
added dsp role
springframeworkguru Feb 10, 2016
6677643
added show user info
springframeworkguru Feb 19, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,24 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>

<!--testing deps-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
92 changes: 92 additions & 0 deletions src/main/java/guru/springframework/comands/CheckoutCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package guru.springframework.comands;

import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Size;

/**
* Created by jt on 2/1/16.
*/
public class CheckoutCommand {

@NotEmpty
@Size(min = 2, max = 50)
private String firstName;

@NotEmpty
@Size(min = 2, max = 50)
private String lastName;

@NotEmpty
@Size(min = 2, max = 50)
private String addressLine1;
private String addressLine2;

@NotEmpty
@Size(min = 2, max = 50)
private String city;

@NotEmpty
@Size(min = 2, max = 2)
private String stateCode;

@NotEmpty
@Size(min = 5, max = 10)
private String zipCode;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getAddressLine1() {
return addressLine1;
}

public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}

public String getAddressLine2() {
return addressLine2;
}

public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getStateCode() {
return stateCode;
}

public void setStateCode(String stateCode) {
this.stateCode = stateCode;
}

public String getZipCode() {
return zipCode;
}

public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
}
31 changes: 31 additions & 0 deletions src/main/java/guru/springframework/comands/LoginCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package guru.springframework.comands;

import org.hibernate.validator.constraints.NotEmpty;

/**
* Created by jt on 2/2/16.
*/
public class LoginCommand {

@NotEmpty
private String username;

@NotEmpty
private String password;

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package guru.springframework.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.Locale;

/**
* Created by jt on 1/25/16.
*/
@Configuration
public class SpringMvcConfiguration extends WebMvcConfigurerAdapter {

@Bean
public LocaleResolver localeResolver(){
SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
sessionLocaleResolver.setDefaultLocale(Locale.US);
return sessionLocaleResolver;
}

@Bean
LocaleChangeInterceptor localeChangeInterceptor(){
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
return localeChangeInterceptor;
}

@Override
public void addInterceptors(InterceptorRegistry interceptorRegistry){
interceptorRegistry.addInterceptor(localeChangeInterceptor());
}
}
38 changes: 38 additions & 0 deletions src/main/java/guru/springframework/config/SpringSecConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package guru.springframework.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
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.WebSecurityConfigurerAdapter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

/**
* Created by jt on 2/2/16.
*/
@Configuration
public class SpringSecConfig extends WebSecurityConfigurerAdapter {

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("admin").password("admin").roles("ADMIN", "USER")
.and().withUser("user").password("user").roles( "USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/index/**", "/product/**", "/checkout", "/docheckout").permitAll()
.and().authorizeRequests().antMatchers("/login","logout").permitAll()
.and().authorizeRequests().antMatchers("/static/css/**","/js/**", "/images/**", "/**/favicon.ico").permitAll()
.and().formLogin().loginPage("/login").defaultSuccessUrl("/").permitAll()
.and().logout()
.deleteCookies("remove")
.invalidateHttpSession(true)
.logoutUrl("/logout")
.logoutSuccessUrl("/logout-success")
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package guru.springframework.controllers;

import guru.springframework.comands.CheckoutCommand;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;

/**
* Created by jt on 2/1/16.
*/

@Controller
public class CheckoutController {

@RequestMapping("/checkout")
public String checkoutForm(Model model){

model.addAttribute("checkoutCommand", new CheckoutCommand());

return "checkoutform";
}

@RequestMapping(value = "/docheckout", method = RequestMethod.POST)
public String doCheckout(@Valid CheckoutCommand checkoutCommand, BindingResult bindingResult){

if (bindingResult.hasErrors()) {
return "checkoutform";
}

return "checkoutcomplete";

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package guru.springframework.controllers;

import guru.springframework.services.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* Created by jt on 1/20/16.
*/
@Controller
public class IndexController {

private ProductService productService;

@Autowired
public void setProductService(ProductService productService) {
this.productService = productService;
}

@RequestMapping({"/", "index"})
public String getIndex(Model model){

model.addAttribute("products", productService.listProducts());

return "index";
}

@RequestMapping("secured")
public String secured(){
return "secured";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package guru.springframework.controllers;

import guru.springframework.comands.LoginCommand;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;


/**
* Created by jt on 2/2/16.
*/
@Controller
public class LoginController {

@RequestMapping("/login")
public String showLoginForm(Model model){

model.addAttribute("loginCommand", new LoginCommand());

return "loginform";
}

@RequestMapping("logout-success")
public String yourLoggedOut(){

return "logout-success";
}

// @RequestMapping(value = "/dologin", method = RequestMethod.POST)
public String doLogin(@Valid LoginCommand loginCommand, BindingResult bindingResult){

if(bindingResult.hasErrors()){
return "loginform";
}

return "redirect:index";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package guru.springframework.controllers;

import guru.springframework.services.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
* Created by jt on 1/20/16.
*/
@Controller
public class ProductController {

private ProductService productService;

@Autowired
public void setProductService(ProductService productService) {
this.productService = productService;
}

//@RequestMapping("/product")
public String getProduct(){
return "redirect:/index";
}

@RequestMapping("/product/{id}")
public String getProductById(@PathVariable Integer id, Model model){

model.addAttribute("product", productService.getProduct(id));

return "product";
}
}
Loading