Added Role object and started using bootstrap for login page
This commit is contained in:
parent
b1b5f11f18
commit
89c74f4925
|
@ -22,7 +22,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.userDetailsService(this.userDetailsService);
|
auth.userDetailsService(this.userDetailsService)
|
||||||
|
.passwordEncoder(passwordEncoder());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,8 +33,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
.authorizeRequests() // Let anyone view the login and logout pages.
|
.authorizeRequests() // Let anyone view the login and logout pages.
|
||||||
.antMatchers("/login*", "/logout*", "/register*")
|
.antMatchers("/login*", "/logout*", "/register*")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.and()
|
.and()
|
||||||
|
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/css/**")
|
.antMatchers("/css/**")
|
||||||
|
@ -41,8 +42,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
.and()
|
.and()
|
||||||
|
|
||||||
.authorizeRequests() // Only logged in users should be able to see site content.
|
.authorizeRequests() // Only logged in users should be able to see site content.
|
||||||
.antMatchers("/**")
|
.antMatchers("/**").authenticated()
|
||||||
.hasRole("USER")
|
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package nl.andrewlalis.teaching_assistant_assistant.model.security;
|
||||||
|
|
||||||
|
import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a role that a user has, which gives the user access to certain resources.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Role extends BasicEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of this role.
|
||||||
|
*/
|
||||||
|
@Column(nullable = false, unique = true)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of users with this role.
|
||||||
|
*/
|
||||||
|
@ManyToMany(mappedBy = "roles")
|
||||||
|
private List<User> users;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<User> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsers(List<User> users) {
|
||||||
|
this.users = users;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,8 @@ package nl.andrewlalis.teaching_assistant_assistant.model.security;
|
||||||
import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity;
|
import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity;
|
||||||
import nl.andrewlalis.teaching_assistant_assistant.model.people.Person;
|
import nl.andrewlalis.teaching_assistant_assistant.model.people.Person;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
import java.util.List;
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.OneToOne;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a user of the website with some credentials.
|
* Represents a user of the website with some credentials.
|
||||||
|
@ -23,9 +21,31 @@ public class User extends BasicEntity {
|
||||||
/**
|
/**
|
||||||
* The password for this user.
|
* The password for this user.
|
||||||
*/
|
*/
|
||||||
@Column
|
@Column(nullable = false)
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not this user has been activated.
|
||||||
|
*/
|
||||||
|
@Column(nullable = false)
|
||||||
|
private boolean activated = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not this user has been locked (no more access).
|
||||||
|
*/
|
||||||
|
@Column(nullable = false)
|
||||||
|
private boolean locked = false;
|
||||||
|
|
||||||
|
@ManyToMany(
|
||||||
|
fetch = FetchType.EAGER
|
||||||
|
)
|
||||||
|
@JoinTable(
|
||||||
|
name = "user_roles",
|
||||||
|
joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id")
|
||||||
|
)
|
||||||
|
private List<Role> roles;
|
||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(
|
@JoinColumn(
|
||||||
name = "person_id",
|
name = "person_id",
|
||||||
|
@ -46,4 +66,27 @@ public class User extends BasicEntity {
|
||||||
return this.person;
|
return this.person;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isActivated() {
|
||||||
|
return activated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivated(boolean activated) {
|
||||||
|
this.activated = activated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLocked() {
|
||||||
|
return locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocked(boolean locked) {
|
||||||
|
this.locked = locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Role> getRoles() {
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(List<Role> roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,13 @@ package nl.andrewlalis.teaching_assistant_assistant.model.security;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TAA-specific implementation of Spring's UserDetails interface to supply user authentication data.
|
||||||
|
*/
|
||||||
public class UserDetails implements org.springframework.security.core.userdetails.UserDetails {
|
public class UserDetails implements org.springframework.security.core.userdetails.UserDetails {
|
||||||
|
|
||||||
private User user;
|
private User user;
|
||||||
|
@ -20,7 +24,12 @@ public class UserDetails implements org.springframework.security.core.userdetail
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
return Collections.singleton(new SimpleGrantedAuthority("ROLE_USER"));
|
List<Role> roles = this.user.getRoles();
|
||||||
|
List<GrantedAuthority> authorities = new ArrayList<>();
|
||||||
|
for (Role role : roles) {
|
||||||
|
authorities.add(new SimpleGrantedAuthority(role.getName()));
|
||||||
|
}
|
||||||
|
return authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +49,7 @@ public class UserDetails implements org.springframework.security.core.userdetail
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAccountNonLocked() {
|
public boolean isAccountNonLocked() {
|
||||||
return true;
|
return !this.user.isLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,6 +59,6 @@ public class UserDetails implements org.springframework.security.core.userdetail
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return true;
|
return this.user.isActivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Welcome to the Teaching Assistant Assistant, <span th:text="${user.getPerson().getFullName()}"></span>. To find the courses in this application please follow the link to
|
Welcome to the Teaching Assistant Assistant, <span th:text="${user.getPerson().getFullName()}"></span>. To find the courses in this application please follow the link to <a th:href="@{/courses}">courses</a>.
|
||||||
<a th:href="@{/courses}">courses</a>.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -3,61 +3,77 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Login</title>
|
<title>Login</title>
|
||||||
<link rel="stylesheet" th:href="@{/css/style.css}" type="text/css"/>
|
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" type="text/css"/>
|
||||||
<link rel="stylesheet" th:href="@{/css/login.css}" type="text/css"/>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="content_container">
|
<section class="container">
|
||||||
<div class="page_row">
|
<div class="row justify-content-center">
|
||||||
<h1>Teaching Assistant <em>Assistant</em></h1>
|
<h1>Teaching Assistant <em>Assistant</em></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page_row">
|
<div class="row justify-content-center">
|
||||||
<div th:if="${param.error}">
|
<div class="alert alert-danger" th:if="${param.error}">
|
||||||
Invalid username or password!
|
Invalid username or password!
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div th:if="${param.logout}">
|
<div class="alert alert-success" th:if="${param.logout}">
|
||||||
You have been logged out!
|
You have been logged out!
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page_row">
|
<div class="row justify-content-center">
|
||||||
<h2>Login</h2>
|
|
||||||
<p>
|
<p>
|
||||||
Please log in to access this application.
|
Please log in to access to the world's most advanced course organization tool ever created. With the ability to manipulate large groups of students with ease, you might actually enjoy teaching a course.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page_row">
|
<div class="row justify-content-center">
|
||||||
<form class="login_form" th:action="@{/login}" method="post">
|
<form th:action="@{/login}" method="post">
|
||||||
<div class="login_form_row">
|
<div class="form-group">
|
||||||
<label for="username_input">Username</label>
|
<label for="username_input">Username</label>
|
||||||
|
<input id="username_input" class="form-control" type="text" name="username"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="login_form_row">
|
<div class="form-group">
|
||||||
<input id="username_input" type="text" name="username"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="login_form_row">
|
|
||||||
<label for="password_input">Password</label>
|
<label for="password_input">Password</label>
|
||||||
|
<input id="password_input" class="form-control" type="password" name="password"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="login_form_row">
|
<input type="submit" value="Login"/>
|
||||||
<input id="password_input" type="password" name="password"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="login_form_row">
|
<a class="white_link" th:href="@{/register}">Don't have an account? Sign up here!</a>
|
||||||
<input type="submit" value="Login"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="login_form_row">
|
|
||||||
<a class="white_link" th:href="@{/register}">Don't have an account? Sign up here!</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
|
|
||||||
|
<section class="fixed-bottom">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row text-center">
|
||||||
|
<div class="col-xs-12 col-4">
|
||||||
|
<h5>Quick Links</h5>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-4">
|
||||||
|
<h5>More links</h5>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-4">
|
||||||
|
<h5>Yet more links</h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
Social media icons go here.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
<p class="h6">
|
||||||
|
© 2019 Andrew Lalis, all rights reserved.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue