From 70df5c74ea43b2c34dc4da083ed759654ecd7b35 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 3 Jun 2019 10:08:49 +0200 Subject: [PATCH] Updated student html and made the creation date mandatory for basic entity. --- .../config/WebSecurityConfig.java | 8 ++++-- .../model/BasicEntity.java | 2 +- .../model/security/UserDetailsService.java | 3 +++ .../resources/templates/register/student.html | 27 +++++++++---------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/WebSecurityConfig.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/WebSecurityConfig.java index 4b5e133..2034806 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/WebSecurityConfig.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/WebSecurityConfig.java @@ -51,8 +51,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .and() .authorizeRequests() // Only logged in users should be able to see site content. - .antMatchers("/**").authenticated() - .anyRequest().authenticated() + .antMatchers("/**").hasRole("user") + .anyRequest().hasRole("user") .and() .formLogin() @@ -72,6 +72,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .deleteCookies("JSESSIONID"); } + /** + * Configures Spring Security to use a specific password encoder. + * @return The password encoder to use. + */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java index 72f402c..a834a3d 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/BasicEntity.java @@ -38,7 +38,7 @@ public abstract class BasicEntity { value = TemporalType.TIMESTAMP ) @CreationTimestamp - @Column + @Column(nullable = false) private Date createdOn; protected BasicEntity() {} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/security/UserDetailsService.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/security/UserDetailsService.java index 24ff5d0..5b2bb16 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/security/UserDetailsService.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/security/UserDetailsService.java @@ -7,6 +7,9 @@ import org.springframework.stereotype.Service; import java.util.Optional; +/** + * A custom user details service to supply database persistent user information to Spring Security. + */ @Service public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService { diff --git a/src/main/resources/templates/register/student.html b/src/main/resources/templates/register/student.html index 6804cb8..f4afe7a 100644 --- a/src/main/resources/templates/register/student.html +++ b/src/main/resources/templates/register/student.html @@ -6,28 +6,27 @@

- Here you can register to create a new account to access the information provided by this application, whether you are a professor, teaching assistant, or student. After filling out this submission form, you'll receive an email with a link to verify that you are who you say you are, after which your account will be activated. + To register as a student, please fill out the form below. Make sure to double-check that all information is entered is accurate. +

+

+ Where the form asks for a Registration Code, please provide the code that has been given to you by your lecturers. This code ensures that you'll join the right course.

-

I am a ...

-
- -
-
- Student -
- -
- Administrator +
+
+
+ +
+
-