文章转自 :http://www.dev26.com/blog/article/113/1 <!--EndFra-->
前端时间一直在研究spring Security3.1这个框架,感觉用着还算不错,包括本站也是使用是了这个框架正好利用这个机会学习一下.特地给大家分享一下,希望对大家有所帮助.对这个框架的介绍就不用多说了,网上都有相关的资料.我要介绍的是如何利用数据库来存储所有的权限,这样的话就直接可以通过在数据库中增加记录来扩展权限,不用每次都要在XML中配置权限.
为了测试更加方便我用的是haldb数据库,比较简单.
首先到spring官网把最新版的spring Security安全框架的压缩文件下载下来:
http://www.springsource.org/spring-community-download
然后在Eclipse中新一个Web工程,在web.xml中加入以下权限过滤器来控制来拦截所有访问
1
2
3
4
5
6
7
8
|
< filter >
< filter-name >springSecurityFilterChain</ filter-name >
< filter-class >org.springframework.web.filter.DelegatingFilterProxy</ filter-class >
</ filter >
< filter-mapping >
< filter-name >springSecurityFilterChain</ filter-name >
< url-pattern >/*</ url-pattern >
</ filter-mapping >
|
然后在listener中引入spring 的bean配置文件:
1
2
3
4
5
6
7
|
< context-param >
< param-name >contextConfigLocation</ param-name >
< param-value >classpath:applicationContext*.xml</ param-value >
</ context-param >
< listener >
< listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class >
</ listener >
|
整工程截图如下:
以下是hqldb的初始化脚本,也不用建库只要把hqldb.jar放到工程中则会自动执行.这就是工程的test.script的脚本sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE MEMORY TABLE RESC(ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL , NAME VARCHAR (50),RES_TYPE VARCHAR (50),RES_STRING VARCHAR (200),PRIORITY INTEGER ,DESCN VARCHAR (200), CONSTRAINT PK_RESC PRIMARY KEY (ID))
CREATE MEMORY TABLE ROLE(ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL , NAME VARCHAR (50),DESCN VARCHAR (200), CONSTRAINT PK_ROLE PRIMARY KEY (ID))
CREATE MEMORY TABLE USER (ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL ,USERNAME VARCHAR (50), PASSWORD VARCHAR (50),STATUS INTEGER ,DESCN VARCHAR (200), CONSTRAINT PK_USER PRIMARY KEY (ID))
CREATE MEMORY TABLE RESC_ROLE(RESC_ID BIGINT NOT NULL ,ROLE_ID BIGINT NOT NULL , CONSTRAINT PK_RESC_ROLE PRIMARY KEY (RESC_ID,ROLE_ID), CONSTRAINT FK_RESC_ROLE_RESC FOREIGN KEY (RESC_ID) REFERENCES RESC(ID), CONSTRAINT FK_RESC_ROLE_ROLE FOREIGN KEY (ROLE_ID) REFERENCES ROLE(ID))
CREATE MEMORY TABLE USER_ROLE(USER_ID BIGINT NOT NULL ,ROLE_ID BIGINT NOT NULL , CONSTRAINT PK_USER_ROLE PRIMARY KEY (USER_ID,ROLE_ID), CONSTRAINT FK_USER_ROLE_USER FOREIGN KEY (USER_ID) REFERENCES USER (ID), CONSTRAINT FK_USER_ROLE_ROLE FOREIGN KEY (ROLE_ID) REFERENCES ROLE(ID))
ALTER TABLE RESC ALTER COLUMN ID RESTART WITH 3
ALTER TABLE ROLE ALTER COLUMN ID RESTART WITH 3
ALTER TABLE USER ALTER COLUMN ID RESTART WITH 3
CREATE USER SA PASSWORD ""
GRANT DBA TO SA
SET WRITE_DELAY 10
SET SCHEMA PUBLIC
INSERT INTO RESC VALUES (1, '' , 'URL' , '/admin.jsp' ,1, '' )
INSERT INTO RESC VALUES (2, '' , 'URL' , '/**' ,2, '' )
INSERT INFO RESC VALUES (3, '' , 'METHOD' , 'com.dev26.springsecuritybook.MessageService.adminMessage' ,3, '' );
INSERT INTO ROLE VALUES (1, 'ROLE_ADMIN' , '\u7ba1\u7406\u5458\u89d2\u8272' )
INSERT INTO ROLE VALUES (2, 'ROLE_USER' , '\u7528\u6237\u89d2\u8272' )
INSERT INTO USER VALUES (1, 'admin' , 'admin' ,1, '\u7ba1\u7406\u5458' )
INSERT INTO USER VALUES (2, 'user' , 'user' ,1, '\u7528\u6237' )
INSERT INTO RESC_ROLE VALUES (1,1)
INSERT INTO RESC_ROLE VALUES (2,1)
INSERT INTO RESC_ROLE VALUES (2,2)
INSERT INTO RESC_ROLE VALUES (3,1)
INSERT INTO USER_ROLE VALUES (1,1)
INSERT INTO USER_ROLE VALUES (1,2)
INSERT INTO USER_ROLE VALUES (2,2)
|
这些是基本配置文件,然后咱在分析一下spring Security的运行基制,然后在在看另一个applicationContext.xml中的配置就比较容易了.
Spring Security是一个基于角色的权限框架(Role Based Access Control,RBAC),它通过一系列可配置的组件构建了基于Spring IOC组件装配模式的安全框架.系统中对用于分配角色,而
角色由被授于相应的权限(增加、浏览、删除、更新..),在校验的时候首先要确定用户所属地的角色,然后根据角色来判断当前用户有哪些权限。这只是Spring Security框架的部分功能,其实它比较丰富的配置和扩展比如:(用户组(Group)的配置、ACL权限配置、CAS集成等)。
首先要配置的是一个org.springframework.web.filter.DelegatingFilterProxy的过滤器在webm.xml中这是Spring Security的一个入口,它内部有一个过滤器链。学过Acegi的朋友可能比较了解,这个例子就不深究了。
以下是Secutirity本应的配置,在applicationContext.xml中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<? xml version = "1.0" encoding = "UTF-8" ?>
xmlns:beans = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security-3.1.xsd">
< http auto-config = "true" >
</ http >
<!--通过SQL语句关联查询当前用户所拥有的权限 -->
< authentication-manager >
< authentication-provider >
< jdbc-user-service data-source-ref = "dataSource"
users-by-username-query="select username,password,status as enabled
from user
where username=?"
authorities-by-username-query="select u.username,r.name as authority
from user u
join user_role ur
on u.id = ur .user_id
join role r
on r.id = ur .role_id
where u.username=?" />
</ authentication-provider >
</ authentication-manager >
< global-method-security />
<!--更新权限缓存,不用每次重启服务 --> < beans:bean id = "resourceDetailsMonitor"
class = "com.dev26.springsecuritybook.ResourceDetailsMonitor2"
autowire = "byType" >
< beans:property name = "dataSource" ref = "dataSource" />
< beans:property name = "accessDecisionManager" ref = "accessDecisionManager" />
</ beans:bean >
<!--数据源 --> < beans:bean id = "dataSource"
class = "org.springframework.jdbc.datasource.DriverManagerDataSource" >
< beans:property name = "driverClassName" value = "org.hsqldb.jdbcDriver" />
< beans:property name = "url" value = "jdbc:hsqldb:res:/hsqldb/test" />
< beans:property name = "username" value = "sa" />
< beans:property name = "password" value = "" />
</ beans:bean >
<!--决策管理器 -->
< beans:bean id = "accessDecisionManager"
class = "org.springframework.security.access.vote.AffirmativeBased" >
< beans:property name = "allowIfAllAbstainDecisions"
value = "false" />
< beans:property name = "decisionVoters" >
< beans:list >
< beans:bean class = "com.dev26.springsecuritybook.MyRoleVoter" />
< beans:bean
class = "org.springframework.security.access.vote.AuthenticatedVoter" />
</ beans:list >
</ beans:property >
</ beans:bean >
< beans:bean id = "messageService"
class = "com.dev26.springsecuritybook.MessageServiceImpl" />
</ beans:beans >
|
权限缓存刷新类代码ResourceDetailsMonitor2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
package com.dev26.springsecuritybook;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor;
import org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource;
import org.springframework.security.access.method.MethodSecurityMetadataSource;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import com.dev26.springsecuritybook.ResourceDetailsBuilder;
public class ResourceDetailsMonitor2 implements InitializingBean {
private String queryUrl = "select re.res_string,r.name" +
" from role r" +
" join resc_role rr" +
" on r.id=rr.role_id" +
" join resc re" +
" on re.id=rr.resc_id" +
" where re.res_type='URL'" +
" order by re.priority" ; private String queryMethod =
"select re.res_string,r.name" + " from role r" +
" join resc_role rr" +
" on r.id=rr.role_id" +
" join resc re" +
" on re.id=rr.resc_id" +
" where re.res_type='METHOD'" +
" order by re.priority" ;
private DataSource dataSource;
private FilterSecurityInterceptor filterSecurityInterceptor;
private org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource delegatingMethodDefinitionSource;
private AccessDecisionManager accessDecisionManager;
private ResourceDetailsBuilder resourceDetailsBuilder;
private MethodSecurityInterceptor methodSecurityInterceptor;
private Collection hasMethodAttribute;
private Collection hasUrlAttribut;
public void setQueryUrl(String queryUrl) {
this .queryUrl = queryUrl;
}
public void setQueryMethod(String queryMethod) {
this .queryMethod = queryMethod;
}
public void setDataSource(DataSource dataSource) {
this .dataSource = dataSource;
}
public FilterSecurityInterceptor getFilterSecurityInterceptor() {
return filterSecurityInterceptor;
}
public void setFilterSecurityInterceptor(
FilterSecurityInterceptor filterSecurityInterceptor) {
this .filterSecurityInterceptor = filterSecurityInterceptor;
}
public org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource getDelegatingMethodDefinitionSource() {
return delegatingMethodDefinitionSource;
}
public void setDelegatingMethodDefinitionSource(
org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource delegatingMethodDefinitionSource) {
this .delegatingMethodDefinitionSource = delegatingMethodDefinitionSource;
}
public ResourceDetailsBuilder getResourceDetailsBuilder() {
return resourceDetailsBuilder;
}
public void setResourceDetailsBuilder(
ResourceDetailsBuilder resourceDetailsBuilder) {
this .resourceDetailsBuilder = resourceDetailsBuilder;
}
public String getQueryUrl() {
return queryUrl;
}
public String getQueryMethod() {
return queryMethod;
}
public DataSource getDataSource() {
return dataSource;
}
public void afterPropertiesSet() {
resourceDetailsBuilder = new ResourceDetailsBuilder(dataSource);
filterSecurityInterceptor
.setAccessDecisionManager(accessDecisionManager);
this .hasMethodAttribute = delegatingMethodDefinitionSource
.getAllConfigAttributes();
this .hasUrlAttribut = filterSecurityInterceptor
.getSecurityMetadataSource().getAllConfigAttributes();
refresh();
}
public void refresh() {
if (filterSecurityInterceptor != null ) {
FilterInvocationSecurityMetadataSource source = resourceDetailsBuilder
.createUrlSource(queryUrl);
source.getAllConfigAttributes().addAll(hasUrlAttribut);
filterSecurityInterceptor.setSecurityMetadataSource(source);
}
if (delegatingMethodDefinitionSource != null ) {
MethodSecurityMetadataSource source = resourceDetailsBuilder
.createMethodSource(queryMethod);
delegatingMethodDefinitionSource.getMethodSecurityMetadataSources()
.clear();
delegatingMethodDefinitionSource.getMethodSecurityMetadataSources()
.add(source);
List<MethodSecurityMetadataSource> list = new ArrayList<MethodSecurityMetadataSource>();
source.getAllConfigAttributes().addAll(hasMethodAttribute);
list.add(source);
delegatingMethodDefinitionSource = new DelegatingMethodSecurityMetadataSource(
list);
;
methodSecurityInterceptor
.setSecurityMetadataSource(delegatingMethodDefinitionSource);
try {
// methodSecurityInterceptor.afterPropertiesSet();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println( "-------------------------refresh" );
}
public AccessDecisionManager getAccessDecisionManager() {
return accessDecisionManager;
}
public void setAccessDecisionManager(
AccessDecisionManager accessDecisionManager) {
this .accessDecisionManager = accessDecisionManager;
}
public MethodSecurityInterceptor getMethodSecurityInterceptor() {
return methodSecurityInterceptor;
}
public void setMethodSecurityInterceptor(
MethodSecurityInterceptor methodSecurityInterceptor) {
this .methodSecurityInterceptor = methodSecurityInterceptor;
}
} |
扩展决策机制,如果用户有多个角色,只要有一个决色拥有权限则通过校验.MyRoleVoter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package com.dev26.springsecuritybook;
import java.util.Collection;
import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
public class MyRoleVoter implements AccessDecisionVoter<Object> {
private String rolePrefix = "ROLE_" ;
public String getRolePrefix() {
return rolePrefix;
}
public void setRolePrefix(String rolePrefix) {
this .rolePrefix = rolePrefix;
}
public boolean supports(ConfigAttribute attribute) {
if ((attribute.getAttribute() != null )
&& attribute.getAttribute().startsWith(getRolePrefix())) {
return true ;
} else {
return false ;
}
}
/**
* This implementation supports any type of class, because it does not query
* the presented secure object.
*
* @param clazz
* the secure object
*
* @return always <code>true</code>
*/
public boolean supports(Class<?> clazz) {
return true ;
}
public int vote(Authentication authentication, Object object,
Collection<ConfigAttribute> attributes) {
int result = ACCESS_ABSTAIN;
Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication);
for (ConfigAttribute attribute : attributes) {
if ( this .supports(attribute)) {
result = ACCESS_DENIED;
// Attempt to find a matching granted authority
for (GrantedAuthority authority : authorities) {
String[] roles = attribute.getAttribute().split( "," );
for (String string : roles) {
if (string.equals(authority.getAuthority())) {
return ACCESS_GRANTED;
}
}
}
}
}
return result;
}
Collection<? extends GrantedAuthority> extractAuthorities(
Authentication authentication) {
return authentication.getAuthorities();
}
} |
以下是业务类,被保护的方法已经在上面的SQL脚本中进行了初始化:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package com.dev26.springsecuritybook;
public class MessageServiceImpl implements MessageService {
public String adminMessage() {
return "admin message" ;
}
public String adminDate() {
return "admin " + System.currentTimeMillis();
}
public String userMessage() {
return "user message" ;
}
public String userDate() {
return "user " + System.currentTimeMillis();
}
} |
让我来验证一下,首先要编写一个登录页面:login.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page pageEncoding="UTF-8" %> < html >
< head >
< title >Login</ title >
</ head >
< body onload = "document.f.j_username.focus();" >
< h1 >Login</ h1 >
< p >Valid users:
< p >
< p >username < b >rod</ b >, password < b >koala</ b >
< p >username < b >dianne</ b >, password < b >emu</ b >
< p >username < b >scott</ b >, password < b >wombat</ b >
< p >username < b >peter</ b >, password < b >opal</ b > (user disabled)
< p >username < b >bill</ b >, password < b >wombat</ b >
< p >username < b >bob</ b >, password < b >wombat</ b >
< p >username < b >jane</ b >, password < b >wombat</ b >
< p >
< p >Locale is: <%= request.getLocale() %></ p >
<%-- this form-login-page form is also used as the
form-error-page to ask for a login again.
--%>
< c:if test = "${not empty param.login_error}" >
< font color = "red" >
Your login attempt was not successful, try again.< br />< br />
Reason: < c:out value = "${SPRING_SECURITY_LAST_EXCEPTION.message}" />.
</ font >
</ c:if >
< form name = "f" action="<c:url value = 'j_spring_security_check' />" method="POST">
< table >
< tr >< td >User:</ td >< td >< input type = 'text' name = 'j_username' value='<c:if test = "${not empty param.login_error}" >< c:out value = "${SPRING_SECURITY_LAST_USERNAME}" /></ c:if >'/></ td ></ tr >
< tr >< td >Password:</ td >< td >< input type = 'password' name = 'j_password' ></ td ></ tr >
< tr >< td >< input type = "checkbox" name = "_spring_security_remember_me" ></ td >< td >Don't ask for my password for two weeks</ td ></ tr >
< tr >< td colspan = '2' >< input name = "submit" type = "submit" ></ td ></ tr >
< tr >< td colspan = '2' >< input name = "reset" type = "reset" ></ td ></ tr >
</ table >
</ form >
</ body >
</ html >
|
如果通过校验则进入idnex.jsp
1
2
3
4
5
6
7
8
9
10
|
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> < div >username :< security:authentication property = "principal.username" /></ div >
< hr >
< a href = "admin.jsp" >admin.jsp</ a >
| < a href = "admin-method.jsp" >admin-method.jsp</ a >
| < a href = "user-method.jsp" >user-method.jsp</ a >
| < a href = "j_spring_security_logout" >logout</ a >
|
如果你是用普通户登录的,如果进行admin-method.jsp则会被拦截,user-method.jsp则可以访问,如果有物是admin的角色由都可以进行访问.
如果点击admin.jsp
相关推荐
1. 集成Spring MVC:Spring Security 3.1与Spring MVC紧密结合,提供了基于注解的便捷安全配置,使开发者能够快速实现Web应用的安全控制。 2. XML与Java配置:3.1版本支持XML配置和基于Java的配置方式,开发者可以...
标题:springsecurity3.1.pdf 描述:springsecurity3.1.pdf 标签:spring security3.1 部分内容:SpringSecurity Reference Documentation by Ben Alex and Luke Taylor 3.1.4.RELEASE **一、Spring Security 3.1...
Spring Security 是一个强大的安全框架,主要用于Java应用的安全管理。在Spring Security 3.1版本中,它提供了多种方式来管理用户认证和授权。本指南将深入讲解如何利用这个框架进行高级开发,通过一个简单的示例和...
总结来说,Spring Security 3.1的配置实例是一个综合性的教程,涵盖了Web安全的多个方面,包括用户认证、权限控制以及与流行MVC框架(如Struts2)的集成。学习并实践这个实例,将有助于你深入理解和掌握Spring ...
在压缩包内的文件,"spring security 3.1 电子书,源代码"表明用户将获得两部分内容:一是Spring Security 3.1的电子书,这是一份详尽的教程或参考指南,涵盖了框架的各个方面;二是源代码,这些代码可以直接查看和...
通过阅读 `_SpringSecurity3_教程及官方参考手册` 中的内容,开发者可以更深入地学习如何配置和定制 Spring Security,以满足特定的安全需求。 总之,Spring Security 3.1 作为 Java 安全框架的杰出代表,提供了...
在 SpringSecurity电子书中,作者Ben Alex和Luke Taylor提供了对Spring Security的全面介绍,涵盖了从基本概念到高级特性以及如何配置和使用Spring Security的详细指南。 知识点一:Spring Security基础 1. Spring ...
- **历史**: 本章节简要回顾了 Spring Security 的发展历程,包括其前身 Acegi 安全框架的历史背景。 - **版本编号**: 明确了 Spring Security 版本的命名规则,例如 `3.2.0.M2` 中的 `.M2` 表示这是一个里程碑版本...
Spring Security 是一个强大的和高度可定制的身份验证和访问控制框架,用于Java应用程序。它为Web应用和企业级应用提供了安全性的解决方案。这个压缩包包含了Spring Security的中文文档和3.1版本的jar包,这对于理解...
Spring Security 3.1 版本带来了一系列重要的更新,包括但不限于对 Spring Framework 3.1 的支持、新的配置选项以及对现有特性的改进。 ##### 2.2 命名空间更新 在 Spring Security 3.1 中,命名空间也得到了增强...
38. Spring Data&Spring安全配置 273 39. @Query中的安全表达式 273 第八部分 附录 274 40.安全数据库模式 274 40.1用户模式 274 40.1.1集团当局 274 40.2持久登录(记得我)架构 275 40.3 ACL模式 275 40.3.1 ...
在本教程中,我们将探讨如何逐步搭建 Spring Security 3.x 环境,特别针对 3.1 及以上版本的 Spring 框架。 **第一步:准备依赖库** 首先,你需要获取所有必要的 JAR 包,包括 Spring Security 的核心库和其他依赖...
5. **教你使用_SpringSecurity_3.0_52页.pdf**: 这可能是一个教程,详细介绍了Spring Security 3.0的基础和使用方法,包括安装、配置、用户认证和授权流程。通过这个教程,开发者可以快速上手Spring Security,并...
### Spring框架知识点详解 #### 一、Spring框架概述 **1.1 什么是Spring框架** Spring框架是一个开源的Java框架,旨在为构建企业级...建议结合官方文档和在线教程进行学习,以便更好地掌握Spring框架的核心知识。
Spring还扩展到了安全领域,`Spring Security教程.chm`则可能包含了关于用户认证、授权、会话管理等安全相关知识。 `Struts2`是基于MVC设计模式的Web应用框架,它整合了多种优秀框架,如`FreeMarker`模板引擎和`...
### Spring Boot 实战教程知识点详解 #### 一、Spring Boot 简介 **1.1 Spring 概述** Spring 是一个开源框架,最初由 Rod Johnson 创建,它为 Java 应用程序提供了一种简化的方式来处理依赖管理和面向切面编程...
通过学习,读者可以理解如何配置Spring Security,保护应用程序的资源,以及如何实现自定义的安全策略。 最后,Spring还提供了对RESTful服务的支持,帮助开发者构建基于HTTP的、无状态的、客户端-服务器架构的服务...
3.2 JWT(JSON Web Token)认证:Spring Security可配合JWT实现用户认证,通过Token进行身份验证,提高安全性。 3.3 Axios库:Vue2常用的数据交互工具,用于发起HTTP请求,与Spring后端进行数据交换。 四、课堂派...
- **基于Java的配置**:完全使用Java代码来配置Spring容器,提高了灵活性和类型安全性。 #### 实例化一个容器 根据不同的需求,可以通过不同的方式来实例化Spring IoC容器。例如,如果使用XML配置文件,可以通过`...