Skip to content

Commit c3f6e4b

Browse files
committed
Add bootstrap, update security
1 parent 6a7d9a6 commit c3f6e4b

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-0
lines changed

pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,70 @@
2525
</properties>
2626

2727
<dependencies>
28+
2829
<dependency>
2930
<groupId>org.springframework.boot</groupId>
3031
<artifactId>spring-boot-starter-data-jpa</artifactId>
3132
</dependency>
33+
3234
<dependency>
3335
<groupId>org.springframework.boot</groupId>
3436
<artifactId>spring-boot-starter-data-redis</artifactId>
3537
</dependency>
38+
3639
<dependency>
3740
<groupId>org.springframework.boot</groupId>
3841
<artifactId>spring-boot-starter-security</artifactId>
3942
</dependency>
43+
4044
<dependency>
4145
<groupId>org.springframework.boot</groupId>
4246
<artifactId>spring-boot-starter-thymeleaf</artifactId>
4347
</dependency>
48+
4449
<dependency>
4550
<groupId>org.springframework.boot</groupId>
4651
<artifactId>spring-boot-starter-web</artifactId>
4752
</dependency>
53+
4854
<dependency>
4955
<groupId>com.h2database</groupId>
5056
<artifactId>h2</artifactId>
5157
<scope>runtime</scope>
5258
</dependency>
59+
5360
<dependency>
5461
<groupId>mysql</groupId>
5562
<artifactId>mysql-connector-java</artifactId>
5663
<scope>runtime</scope>
5764
</dependency>
65+
5866
<dependency>
5967
<groupId>org.postgresql</groupId>
6068
<artifactId>postgresql</artifactId>
6169
<scope>runtime</scope>
6270
</dependency>
71+
6372
<dependency>
6473
<groupId>org.springframework.boot</groupId>
6574
<artifactId>spring-boot-starter-test</artifactId>
6675
<scope>test</scope>
6776
</dependency>
77+
78+
<!-- hot swapping, disable cache for template, enable live reload -->
79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-devtools</artifactId>
82+
<optional>true</optional>
83+
</dependency>
84+
85+
<!-- Optional, for bootstrap -->
86+
<dependency>
87+
<groupId>org.webjars</groupId>
88+
<artifactId>bootstrap</artifactId>
89+
<version>3.3.7</version>
90+
</dependency>
91+
6892
</dependencies>
6993

7094
<build>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.circleci.demojavaspring;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
6+
7+
@Configuration
8+
public class MvcConfig extends WebMvcConfigurerAdapter {
9+
10+
@Override
11+
public void addViewControllers(ViewControllerRegistry registry) {
12+
registry.addViewController("/home").setViewName("index");
13+
registry.addViewController("/").setViewName("index");
14+
registry.addViewController("/register").setViewName("register");
15+
registry.addViewController("/login").setViewName("login");
16+
}
17+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.circleci.demojavaspring;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
6+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9+
10+
@Configuration
11+
@EnableWebSecurity
12+
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
13+
@Override
14+
protected void configure(HttpSecurity http) throws Exception {
15+
http
16+
.authorizeRequests()
17+
.antMatchers("/", "/home", "/webjars/**").permitAll()
18+
.anyRequest().authenticated()
19+
.and()
20+
.formLogin()
21+
.loginPage("/login")
22+
.permitAll()
23+
.and()
24+
.logout()
25+
.permitAll();
26+
}
27+
28+
@Autowired
29+
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
30+
auth
31+
.inMemoryAuthentication()
32+
.withUser("user").password("password").roles("USER");
33+
}
34+
}

src/main/resources/static/css/style.css

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<title>CircleCI Spring Demo</title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6+
7+
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}" />
8+
9+
<link rel="stylesheet" th:href="@{/css/style.css}" href="../static/css/style.css" />
10+
</head>
11+
<body>
12+
13+
<nav class="navbar">
14+
<div class="container">
15+
<div class="navbar-header">
16+
<a class="navbar-brand" href="#">CircleCI Demo Spring</a>
17+
</div>
18+
<div id="navbar" class="collapse navbar-collapse">
19+
<ul class="nav navbar-nav">
20+
<li class="active"><a href="#">Home</a></li>
21+
<li><a href="#">About</a></li>
22+
</ul>
23+
</div>
24+
</div>
25+
</nav>
26+
27+
<div class="container">
28+
<h1> CircleCI Spring Demo </h1>
29+
</div>
30+
31+
<script th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
32+
</body>
33+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
3+
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
4+
<head>
5+
<title>Spring Security Example </title>
6+
</head>
7+
<body>
8+
<div th:if="${param.error}">
9+
Invalid username and password.
10+
</div>
11+
<div th:if="${param.logout}">
12+
You have been logged out.
13+
</div>
14+
<form th:action="@{/login}" method="post">
15+
<div><label> User Name : <input type="text" name="username"/> </label></div>
16+
<div><label> Password: <input type="password" name="password"/> </label></div>
17+
<div><input type="submit" value="Sign In"/></div>
18+
</form>
19+
</body>
20+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
3+
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
4+
<head>
5+
<title>Spring Security Example </title>
6+
</head>
7+
<body>
8+
<div th:if="${param.error}">
9+
Invalid username and password.
10+
</div>
11+
<div th:if="${param.logout}">
12+
You have been logged out.
13+
</div>
14+
<form th:action="@{/login}" method="post">
15+
<div><label> User Name : <input type="text" name="username"/> </label></div>
16+
<div><label> Password: <input type="password" name="password"/> </label></div>
17+
<div><input type="submit" value="Sign In"/></div>
18+
</form>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)