Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b8592c8

Browse files
Spring security 2 - custom login form
1 parent fa66ec8 commit b8592c8

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

‎src/main/java/com/naturalprogrammer/spring5tutorial/config/MvcConfig.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class MvcConfig implements WebMvcConfigurer {
1010
@Override
1111
public void addViewControllers(ViewControllerRegistry registry) {
1212
registry.addViewController("/").setViewName("home");
13+
registry.addViewController("/login").setViewName("login");
1314
}
1415
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
package com.naturalprogrammer.spring5tutorial.config;
22

33
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
45
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
56

67
@Configuration
78
public class SecurityConfig extends WebSecurityConfigurerAdapter {
89

10+
// @formatter:off
11+
@Override
12+
protected void configure(HttpSecurity http) throws Exception {
13+
14+
http
15+
.authorizeRequests()
16+
.anyRequest().authenticated()
17+
.and()
18+
.formLogin().loginPage("/login").permitAll();
19+
}
20+
// @formatter:on
921
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
2+
<%@include file="includes/header.jsp"%>
3+
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4+
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
5+
6+
<div class="panel panel-primary">
7+
<div class="panel-heading">
8+
<h3 class="panel-title">Please sign in</h3>
9+
</div>
10+
<div class="panel-body">
11+
<form:form>
12+
13+
<div class="form-group">
14+
<label for="email">Email address</label>
15+
<input name="username" id="email" type="email" class="form-control" placeholder="Email" />
16+
<p class="help-block">Enter your email address</p>
17+
</div>
18+
<div class="form-group">
19+
<label for="password">Password</label>
20+
<input name="password" id="password" type="password" class="form-control" placeholder="Password" />
21+
</div>
22+
<button type="submit" class="btn btn-primary">Sign In</button>
23+
</form:form>
24+
</div>
25+
</div>
26+
27+
<%@include file="includes/footer.jsp"%>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /