Skip to content

Commit 288c8bf

Browse files
committed
m
1 parent 41e8fd9 commit 288c8bf

File tree

17 files changed

+795
-0
lines changed

17 files changed

+795
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.idea
3+
*.iml
4+
target/

form-login-2/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.5.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>org.javaboy</groupId>
12+
<artifactId>form-login-2</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>form-login-2</name>
15+
<description>公众号:江南一点雨</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-security</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
<exclusions>
36+
<exclusion>
37+
<groupId>org.junit.vintage</groupId>
38+
<artifactId>junit-vintage-engine</artifactId>
39+
</exclusion>
40+
</exclusions>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.security</groupId>
44+
<artifactId>spring-security-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.javaboy.formlogin;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class FormLoginApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(FormLoginApplication.class, args);
11+
}
12+
13+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.javaboy.formlogin;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
/**
8+
* @作者 江南一点雨
9+
* @公众号 江南一点雨
10+
* @微信号 a_java_boy
11+
* @GitHub https://github.com/lenve
12+
* @博客 http://wangsong.blog.csdn.net
13+
* @网站 http://www.javaboy.org
14+
*/
15+
@RestController
16+
public class HelloController {
17+
@GetMapping("/hello")
18+
public String hello() {
19+
return "hello";
20+
}
21+
22+
@RequestMapping("/hello1")
23+
public String hello1() {
24+
return "hello1";
25+
}
26+
@RequestMapping("/hello2")
27+
public String hello2() {
28+
return "hello2";
29+
}
30+
31+
@RequestMapping("/f1")
32+
public String f1() {
33+
return "f1";
34+
}
35+
@RequestMapping("/f2")
36+
public String f2() {
37+
return "f2";
38+
}
39+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.javaboy.formlogin;
2+
3+
import org.springframework.context.annotation.Bean;
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.builders.WebSecurity;
8+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9+
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
10+
import org.springframework.security.crypto.password.PasswordEncoder;
11+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
12+
13+
/**
14+
* @作者 江南一点雨
15+
* @公众号 江南一点雨
16+
* @微信号 a_java_boy
17+
* @GitHub https://github.com/lenve
18+
* @博客 http://wangsong.blog.csdn.net
19+
* @网站 http://www.javaboy.org
20+
*/
21+
@Configuration
22+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
23+
@Bean
24+
PasswordEncoder passwordEncoder() {
25+
return NoOpPasswordEncoder.getInstance();
26+
}
27+
@Override
28+
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
29+
auth.inMemoryAuthentication()
30+
.withUser("javaboy")
31+
.password("123").roles("admin");
32+
}
33+
34+
@Override
35+
public void configure(WebSecurity web) throws Exception {
36+
web.ignoring().antMatchers("/js/**", "/css/**","/images/**");
37+
}
38+
39+
@Override
40+
protected void configure(HttpSecurity http) throws Exception {
41+
http.authorizeRequests()
42+
.anyRequest().authenticated()
43+
.and()
44+
.formLogin()
45+
.loginPage("/login.html")
46+
.loginProcessingUrl("/doLogin")
47+
.usernameParameter("name")
48+
.passwordParameter("passwd")
49+
.defaultSuccessUrl("/index")
50+
.successForwardUrl("/index")
51+
.failureForwardUrl("/f2")
52+
.failureUrl("/f1")
53+
.permitAll()
54+
.and()
55+
.logout()
56+
// .logoutUrl("/logout")
57+
.logoutRequestMatcher(new AntPathRequestMatcher("/logout","POST"))
58+
.logoutSuccessUrl("/index")
59+
.deleteCookies()
60+
.clearAuthentication(true)
61+
.invalidateHttpSession(true)
62+
.permitAll()
63+
.and()
64+
.csrf().disable();
65+
}
66+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spring.security.user.name=javaboy
2+
spring.security.user.password=123

form-login-2/src/main/resources/static/css/font-awesome-4.7.0/css/font-awesome.min.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)