Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
springBoot
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WitCloud
springBoot
Commits
19043010
Commit
19043010
authored
Dec 27, 2016
by
杨伊博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
is work
parent
c46d59e6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
159 additions
and
0 deletions
+159
-0
.gitignore
.gitignore
+19
-0
pom.xml
pom.xml
+55
-0
Application.java
src/main/java/com/us/example/Application.java
+18
-0
SecurityConfig.java
src/main/java/com/us/example/config/SecurityConfig.java
+43
-0
helloController.java
src/main/java/com/us/example/controller/helloController.java
+24
-0
No files found.
.gitignore
0 → 100644
View file @
19043010
/.settings
/bin
/target
/logs
/out
# filter config files, except .gitignore
.*
!.gitignore
*.iml
*.exe
# eclipse ignore
.project
.classpath
# IDEA ignore
.idea
pom.xml
0 → 100644
View file @
19043010
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.us.Example
</groupId>
<artifactId>
springSecurity
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.3.0.RELEASE
</version>
</parent>
<properties>
<start-class>
com.us.WebApplication
</start-class>
<maven.compiler.target>
1.8
</maven.compiler.target>
<maven.compiler.source>
1.8
</maven.compiler.source>
</properties>
<dependencies>
<!-- 核心模块,包括自动配置支持、日志和YAML -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<!-- 测试模块,包括JUnit、Hamcrest、Mockito -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<!-- 引入Web模块 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<!-- SpringSecurity依赖 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/com/us/example/Application.java
0 → 100644
View file @
19043010
package
com
.
us
.
example
;
/**
* Created by yangyibo on 16/12/27.
*/
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
static
org
.
springframework
.
boot
.
SpringApplication
.*;
@SpringBootApplication
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
ConfigurableApplicationContext
run
=
run
(
Application
.
class
,
args
);
}
}
\ No newline at end of file
src/main/java/com/us/example/config/SecurityConfig.java
0 → 100644
View file @
19043010
package
com
.
us
.
example
.
config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
/**
* Created by yangyibo on 16/12/27.
*/
@Configuration
// 配置文件
@EnableWebSecurity
// 开启Security
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
//AOP
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
//路由策略和访问权限的简单配置
http
.
formLogin
()
//启用默认登陆页面
.
failureUrl
(
"/login/error"
)
//登陆失败返回URL:/login?error
.
defaultSuccessUrl
(
"/home"
)
//登陆成功跳转URL
.
permitAll
();
//登陆页面全部权限可访问
super
.
configure
(
http
);
}
//
// /**
// * 配置内存用户
// */
@Autowired
public
void
configureGlobal
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
inMemoryAuthentication
()
.
withUser
(
"abel"
).
password
(
"123"
).
roles
(
"USER"
);
}
}
src/main/java/com/us/example/controller/helloController.java
0 → 100644
View file @
19043010
package
com
.
us
.
example
.
controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.websocket.server.PathParam
;
/**
* Created by yangyibo on 16/12/27.
*/
@RestController
public
class
helloController
{
// 访问 http://localhost:8080/login 账号 abel 密码 123
@RequestMapping
(
value
=
"/home"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
String
viewHome
()
{
return
"hello SpringSecurity"
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment