搜档网
当前位置:搜档网 › Spring_Security-3.0.1_中文自学教程

Spring_Security-3.0.1_中文自学教程

Spring_Security-3.0.1_中文自学教程
Spring_Security-3.0.1_中文自学教程

Spring Security-3.0.1 中文官方文档(翻译版)

这次发布的Spring Security-3.0.1 是一个bug fix 版,主要是对3.0 中存在的一些问题进行修

正。文档中没有添加新功能的介绍,但是将之前拼写错误的一些类名进行了修正,建议开发者以这一版本的文档为参考。

另:Spring Security 从2010-01-01 以后,版本控制从SVN 换成了GIT,我们在翻译文档的时候,主要是根据SVN 的变化来进行文档内容的比对,这次换成GIT 后,感觉缺少了之前那种文本比对工具,如果有对GIT 熟悉的朋友,还请推荐一下文本比对的工具,谢谢。

序言

I. 入门

1. 介绍

1.1. Spring Security 是什么?

1.2. 历史

1.3. 发行版本号

1.4. 获得Spring Security

1.4.1. 项目模块

1.4.1.1. Core - spring-security-core.jar

1.4.1.

2. Web - spring-security-web.jar

1.4.1.3. Config - spring-security-config.jar

1.4.1.4. LDAP - spring-security-ldap.jar

1.4.1.5. ACL - spring-security-acl.jar

1.4.1.6. CAS - spring-security-cas-client.jar

1.4.1.7. OpenID - spring-security-openid.jar

1.4.

2. 获得源代码

2. Security 命名空间配置

2.1. 介绍

2.1.1. 命名空间的设计

2.2. 开始使用安全命名空间配置

2.2.1. 配置web.xml

2.2.2. 最小 配置

2.2.2.1. auto-config 包含了什么?

2.2.2.2. 表单和基本登录选项

2.2.

3. 使用其他认证提供器

2.2.

3.1. 添加一个密码编码器

2.3. 高级web 特性

2.3.1. Remember-Me 认证

2.3.2. 添加HTTP/HTTPS 信道安全

2.3.3. 会话管理

2.3.3.1. 检测超时

2.3.3.2. 同步会话控制

2.3.3.3. 防止Session 固定攻击

2.3.4. 对OpenID 的支持

2.3.4.1. 属性交换

2.3.5. 添加你自己的filter

2.3.5.1. 设置自定义AuthenticationEntryPoint

2.4. 保护方法

2.4.1. 元素

2.4.1.1. 使用protect-pointcut 添加安全切点

2.5. 默认的AccessDecisionManager

2.5.1. 自定义AccessDecisionManager

2.6. 验证管理器和命名空间

3. 示例程序

3.1. Tutorial 示例

3.2. Contacts

3.3. LDAP 例子

3.4. CAS 例子

3.5. Pre-Authentication 例子

4. Spring Security 社区

4.1. 任务跟踪

4.2. 成为参与者

4.3. 更多信息

II. 结构和实现

5. 技术概述

5.1. 运行环境

5.2. 核心组件

5.2.1. SecurityContextHolder, SecurityContext 和Authentication 对象5.2.1.1. 获得当前用户的信息

5.2.2. UserDetailsService

5.2.3. GrantedAuthority

5.2.4. 小结

5.3. 验证

5.3.1. 什么是Spring Security 的验证呢?

5.3.2. 直接设置SecurityContextHolder 的内容

5.4. 在web 应用中验证

5.4.1. ExceptionTranslationFilter

5.4.2. AuthenticationEntryPoint

5.4.3. 验证机制

5.4.4. 在请求之间保存SecurityContext 。

5.5. Spring Security 中的访问控制(验证)

5.5.1. 安全和AOP 建议

5.5.2. 安全对象和AbstractSecurityInterceptor

5.5.2.1. 配置属性是什么?

5.5.2.2. RunAsManager

5.5.2.3. AfterInvocationManager

5.5.2.4. 扩展安全对象模型

5.6. 国际化

6. 核心服务

6.1. The AuthenticationManager , ProviderManager 和AuthenticationProvider s 6.1.1. DaoAuthenticationProvider

6.2. UserDetailsService 实现

6.2.1. 内存认证

6.2.2. JdbcDaoImpl

6.2.2.1. 权限分组

6.3. 密码加密

6.3.1. 什么是散列加密?

6.3.2. 为散列加点儿盐

6.3.3. 散列和认证

III. web 应用安全

7. 安全过滤器链

7.1. DelegatingFilterProxy

7.2. FilterChainProxy

7.2.1. 绕过过滤器链

7.3. 过滤器顺序

7.4. 使用其他过滤器——基于框架

8. 核心安全过滤器

8.1. FilterSecurityInterceptor

8.2. ExceptionTranslationFilter

8.2.1. AuthenticationEntryPoint

8.2.2. AccessDeniedHandler

8.3. SecurityContextPersistenceFilter

8.3.1. SecurityContextRepository

8.4. UsernamePasswordAuthenticationFilter

8.4.1. 认证成功和失败的应用流程

9. Basic(基本)和Digest(摘要)验证

9.1. BasicAuthenticationFilter

9.1.1. 配置

9.2. DigestAuthenticationFilter

9.2.1. Configuration

10. Remember-Me 认证

10.1. 概述

10.2. 简单基于散列标记的方法

10.3. 持久化标记方法

10.4. Remember-Me 接口和实现

10.4.1. TokenBasedRememberMeServices

10.4.2. PersistentTokenBasedRememberMeServices

11. 会话管理

11.1. SessionManagementFilter

11.2. SessionAuthenticationStrategy

11.3. 同步会话

12. 匿名认证

12.1. 概述

12.2. 配置

12.3. AuthenticationTrustResolver

IV. 授权

13. 验证架构

13.1. 验证

13.2. 处理预调用

13.2.1. AccessDecisionManager

13.2.2. 基于投票的AccessDecisionManager 实现

13.2.2.1. RoleVoter

13.2.2.2. AuthenticatedVoter

13.2.2.3. Custom Voters

13.3. 处理后决定

14. 安全对象实现

14.1. AOP 联盟(MethodInvocation) 安全拦截器

14.1.1. 精确的MethodSecurityIterceptor 配置

14.2. AspectJ (JoinPoint) 安全拦截器

15. 基于表达式的权限控制

15.1. 概述

15.1.1. 常用内建表达式

15.2. Web 安全表达式

15.3. 方法安全表达式

15.3.1. @Pre 和@Post 注解

15.3.1.1. 访问控制使用@PreAuthorize 和@PostAuthorize

15.3.1.2. 过滤使用@PreFilter 和@PostFilter

16. acegi 到spring security 的转换方式

16.1. Spring Security 是什么

16.2. 目标

16.3. 步骤

16.4. 总结

V. 高级话题

17. 领域对象安全(ACLs)

17.1. 概述

17.2. 关键概念

17.3. 开始

18. 预认证场景

18.1. 预认证框架类

18.1.1. AbstractPreAuthenticatedProcessingFilter

18.1.2. AbstractPreAuthenticatedAuthenticationDetailsSource

18.1.2.1. J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource 18.1.3. PreAuthenticatedAuthenticationProvider

18.1.4. Http403ForbiddenEntryPoint

18.2. 具体实现

18.2.1. 请求头认证(Siteminder)

18.2.1.1. Siteminder 示例配置

18.2.2. J2EE 容器认证

19. LDAP 认证

19.1. 综述

19.2. 在Spring Security 里使用LDAP

19.3. 配置LDAP 服务器

19.3.1. 使用嵌入测试服务器

19.3.2. 使用绑定认证

19.3.3. 读取授权

19.4. 实现类

19.4.1. LdapAuthenticator 实现

19.4.1.1. 常用功能

19.4.1.2. BindAuthenticator

19.4.1.3. PasswordComparisonAuthenticator 19.4.1.4. 活动目录认证

19.4.2. 链接到LDAP 服务器

19.4.3. LDAP 搜索对象

19.4.3.1. FilterBasedLdapUserSearch

19.4.4. LdapAuthoritiesPopulator

19.4.5. Spring Bean 配置

19.4.6. LDAP 属性和自定义UserDetails

20. JSP 标签库

20.1. 声明Taglib

20.2. authorize 标签

20.3. authentication 标签

20.4. accesscontrollist 标签

21. Java 认证和授权服务(JAAS)供应器

21.1. 概述

21.2. 配置

21.2.1. JAAS CallbackHandler

21.2.2. JAAS AuthorityGranter

22. CAS 认证

22.1. 概述

22.2. CAS 是如何工作的

22.3. 配置CAS 客户端

23. X.509 认证

23.1. 概述

23.2. 把X.509 认证添加到你的web 系统中

23.3. 为tomcat 配置SSL

24. 替换验证身份

24.1. 概述

24.2. 配置

A. 安全数据库表结构

A.1. User 表

A.1.1. 组权限

A.2. 持久登陆(Remember-Me)表

A.3. ACL 表

A.3.1. Hypersonic SQL

A.3.1.1. PostgreSQL

B. 安全命名空间

B.1. Web 应用安全- 元素

B.1.1. 属性

B.1.1.1. servlet-api-provision

B.1.1.2. path-type

B.1.1.3. lowercase-comparisons

B.1.1.4. realm

B.1.1.5. entry-point-ref

B.1.1.6. access-decision-manager-ref

B.1.1.7. access-denied-page

B.1.1.8. once-per-request

B.1.1.9. create-session

B.1.2.

B.1.3. 元素

B.1.3.1. pattern

B.1.3.2. method

B.1.3.3. access

B.1.3.4. requires-channel

B.1.3.5. filters

B.1.4. 元素

B.1.5. 元素

B.1.5.1. login-page

B.1.5.2. login-processing-url

B.1.5.3. default-target-url

B.1.5.4. always-use-default-target

B.1.5.5. authentication-failure-url

B.1.5.6. authentication-success-handler-ref B.1.5.7. authentication-failure-handler-ref B.1.6. 元素

B.1.7. 元素

B.1.7.1. data-source-ref

B.1.7.2. token-repository-ref

B.1.7.3. services-ref

B.1.7.4. token-repository-ref

B.1.7.5. key 属性

B.1.7.6. token-validity-seconds

B.1.7.7. user-service-ref

B.1.8. 元素

B.1.8.1. session-fixation-protection

B.1.9. 元素

B.1.9.1. max-sessions 属性

B.1.9.2. expired-url 属性

B.1.9.3. error-if-maximum-exceeded 属性

B.1.9.4. session-registry-alias 和session-registry-ref 属性

B.1.10. 元素

B.1.11. 元素

B.1.11.1. subject-principal-regex 属性

B.1.11.2. user-service-ref 属性

B.1.12. 元素

B.1.13. 元素

B.1.13.1. logout-url 属性

B.1.13.2. logout-success-url 属性

B.1.13.3. invalidate-session 属性

B.1.14. 元素

B.2. 认证服务

B.2.1. 元素

B.2.1.1. 元素

B.2.1.2. 使用 来引用一个AuthenticationProvider Bean B.3. 方法安全

B.3.1. 元素

B.3.1.1. secured-annotations 和jsr250-annotations 属性

B.3.1.2. 安全方法使用

B.3.1.3. 元素

B.3.2. LDAP 命名空间选项

B.3.2.1. 使用 元素定义LDAP 服务器

B.3.2.2. 元素

B.3.2.3. 元素

Part I. 入门

本指南的后面部分提供对框架结构和实现类的深入讨论,了解它们,对你进行复杂的定制是十分重要的。在这部分,我们将介绍Spring Security 3.0,简要介绍该项目的历史,然后看看如何开始在程序中使用框架。特别是,我们将看看命名控件配置提供了一个更加简单的方式,在使用传统的spring bean 配置时,你不得不实现所有类。

我们也会看看可用的范例程序。它们值得试着运行,实验,在你阅读后面的章节之前- 你可以在对框架有了更多连接之后再回来看这些例子。也请参考项目网站获得构建项目有用

的信息,另外链接到网站,视频和教程。

Chapter 1. 介绍

1.1. Spring Security是什么?

Spring Security 为基于J2EE 企业应用软件提供了全面安全服务。特别是使用领先的

J2EE 解决方案-spring 框架开发的企业软件项目。如果你没有使用Spring 开发企业软件,我们热情的推荐你仔细研究一下。熟悉Spring-尤其是依赖注入原理-将帮助你更快的掌握Spring Security。

人们使用Spring Security 有很多种原因,不过通常吸引他们的是在J2EE Servlet 规范或EJB 规范中找不到典型企业应用场景的解决方案。提到这些规范,特别要指出的是它们不能在WAR 或EAR 级别进行移植。这样,如果你更换服务器环境,就要,在新的目标环

境进行大量的工作,对你的应用系统进行重新配置安全。使用Spring Security 解决了这些问题,也为你提供了很多有用的,可定制的其他安全特性。

你可能知道,安全包括两个主要操作,“认证”和“验证”(或权限控制)。这就是Spring Security 面向的两个主要方向。“认证”是为用户建立一个他所声明的主体的过程,(“主体”一般是指用户,设备或可以在你系统中执行行动的其他系统)。“验证”指的一个用户能

否在你的应用中执行某个操作。在到达授权判断之前,身份的主体已经由身份验证过程建立了。这些概念是通用的,不是Spring Security 特有的。

在身份验证层面,Spring Security 广泛支持各种身份验证模式。这些验证模型绝大多数都由第三方提供,或正在开发的有关标准机构提供的,例如Internet Engineering Task Force。作为补充,Spring Security 也提供了自己的一套验证功能。Spring Security

目前支持认证一体化和如下认证技术:

HTTP BASIC authentication headers (一个基于IEFT RFC 的标准)

HTTP Digest authentication headers (一个基于IEFT RFC 的标准)

HTTP X.509 client certificate exchange (一个基于IEFT RFC 的标准)

LDAP (一个非常常见的跨平台认证需要做法,特别是在大环境)

Form-based authentication (提供简单用户接口的需求)

OpenID authentication

基于预先建立的请求头进行认证(比如Computer Associates Siteminder)

JA-SIG Central Authentication Service (也被称为CAS,这是一个流行的开源单点登

录系统)

Transparent authentication context propagation for Remote Method Invocation (RMI) and HttpInvoker (一个Spring 远程调用协议)

Automatic "remember-me" authentication (这样你可以设置一段时间,避免在一段时

间内还需要重新验证)

Anonymous authentication (允许任何调用,自动假设一个特定的安全主体)

Run-as authentication (这在一个会话内使用不同安全身份的时候是非常有用的)

Java Authentication and Authorization Service (JAAS)

JEE Container autentication (这样,你可以继续使用容器管理认证,如果想的话) Kerberos

Java Open Source Single Sign On (JOSSO) *

OpenNMS Network Management Platform *

AppFuse *

AndroMDA *

Mule ESB *

Direct Web Request (DWR) *

Grails *

Tapestry *

JTrac *

Jasypt *

Roller *

Elastic Plath *

Atlassian Crowd *

你自己的认证系统(向下看)

(* 是指由第三方提供,查看我们的整合网页,获得最新详情的链接。)

许多独立软件供应商(ISVs, independent software vendors)采用Spring Security,

是因为它拥有丰富灵活的验证模型。这样,无论终端用户需要什么,他们都可以快速集成到系统中,不用花很多功夫,也不用让用户改变运行环境。如果上述的验证机制都没有满足你的需要,Spring Security 是一个开放的平台,编写自己的验证机制是十分简单的。Spring Security 的许多企业用户需要整合不遵循任何特定安全标准的“遗留”系统,Spring Security 在这类系统上也表现的很好。

有时基本的认证是不够的。有时你需要根据在主体和应用交互的方式来应用不同的安全措施。比如,你可能,为了保护密码,不被窃听或受到中间人攻击,希望确保请求只通过HTTPS 到达。这在防止暴力攻击保护密码恢复过程特别有帮助,或者简单的,让人难以复制你的系统的关键字内容。为了帮助你实现这些目标,Spring Security 完全支持自动“信道安全”,整合jcaptcha 一体化进行人类用户检测。

Spring Security 不仅提供认证功能,也提供了完备的授权功能。在授权方面主要有三个领域,授权web 请求,授权被调用方法,授权访问单个对象的实例。为了帮你了解它们之间的区别,对照考虑授在Servlet 规范web 模式安全,EJB 容器管理安全,和文件系统安全方面的授权方式。Spring Security 在所有这些重要领域都提供了完备的能力,我们将在这份参考指南的后面进行探讨。

1.2. 历史

Spring Security 开始于2003年年底,““spring 的acegi 安全系统”。起因是Spring 开发者邮件列表中的一个问题,有人提问是否考虑提供一个基于spring 的安全实现。在当

时Spring 的社区相对较小(尤其是和今天的规模比!),其实Spring 本身是从2003年初才作为一个sourceforge 的项目出现的。对这个问题的回应是,这的确是一个值得研究的领域,虽然限于时间问题阻碍了对它的继续研究。

有鉴于此,一个简单的安全实现建立起来了,但没有发布。几周之后,spring 社区的其他成员询问安全问题,代码就被提供给了他们。随后又有人请求,在2004年一月左右,有

20人在使用这些代码。另外一些人加入到这些先行者中来,并建议在sourceforge 上建

立一个项目,项目在2004年3月正式建立起来。

在早期,项目本身没有自己的认证模块。认证过程都是依赖容器管理安全的,而acegi 则注重授权。这在一开始是合适的,但随着越来越多用户要求提供额外的容器支持,基于容器认证的限制就显现出来了。还有一个有关的问题,向容器的classpath 中添加新jar,

常常让最终用户感到困惑,又容易出现配置错误。

随后acegi 加入了认证服务。大约一年后,acegi 成为spring 的官方子项目。经过了两

年半在许多生产软件项目中的活跃使用和数以万计的改善和社区的贡献,1.0.0最终版本发布于2006年5月。

acegi 在2007年年底,正式成为spring 组合项目,被更名为“Spring Security”。

现在,Spring Security 成为了一个强大而又活跃的开源社区。在Spring Security 支持论坛上有成千上万的信息。有一个积极的核心开发团队专职开发,一个积极的社区定期共享补丁并支持他们的同伴。

1.3. 发行版本号

了解spring Security 发行版本号是非常有用的。它可以帮助你判断升级到新的版本是否需要花费很大的精力。我们使用apache 便携式运行项目版本指南,可以在以下网址查看https://www.sodocs.net/doc/0f1184545.html,/versioning.html。为了方便大家,我们引用页面上的一段介绍:“版本号是一个包含三个整数的组合:主要版本号.次要版本号.补丁。基本思路是主要版本是不兼容的,大规模升级API。次要版本号在源代码和二进制要与老版本保持兼容,补丁

则意味着向前向后的完全兼容。”

1.4. 获得Spring Security

你可以通过多种方式获得Spring Security。你可以下载打包好的发行包,从Spring 的网站下载页,下载单独的jar(和实例WAR 文件)从Maven 中央资源库(或者SpringSource Maven 资源库,获得快照和里程碑发布)。可选的,你可以通过源代码创建项目。参考项目网站获得更多细节。

1.4.1. 项目模块

在Spring Security 3.0中,项目已经分割成单独的jar,这更清楚的按照功能进行分割模块和第三方依赖。如果你在使用Maven 来构建你的项目,你需要把这些模块添加到你的pom.xml 中。即使你没有使用Maven,我们也推荐你参考这个pom.xml 文件,来了

解第三方依赖和对应的版本。可选的,一个好办法是参考实例应用中包含的依赖库。

1.4.1.1. Core - spring-security-core.jar

包含了核心认证和权限控制类和接口,运程支持和基本供应API。使用Spring Security 所必须的。支持单独运行的应用,远程客户端,方法(服务层)安全和JDBC 用户供应。包含顶级包:

org.springframework.security.core

org.springframework.security.access

org.springframework.security.authentication

org.springframework.security.provisioning

org.springframework.security.remoting

1.4.1.

2. Web - spring-security-web.jar

包含过滤器和对应的web 安全架构代码。任何需要依赖servlet API 的。你将需要它,如果你需要Spring Security Web 认证服务和基于URL 的权限控制。主包是

org.springframework.security.web。

1.4.1.3. Config - spring-security-config.jar

包含安全命名控制解析代码(因此我们不能直接把它用在你的应用中)。你需要它,如果使

用了Spring Security XML 命名控制来进行配置。主包是

org.springframework.security.config。

1.4.1.4. LDAP - spring-security-ldap.jar

LDAP 认证和实现代码,如果你需要使用LDAP 认证或管理LDAP 用户实体就是必须的。顶级包是org.springframework.security.ldap。

1.4.1.5. ACL - spring-security-acl.jar

处理领域对象ACL 实现。用来提供安全给特定的领域对象实例,在你的应用中。顶级包是org.springframework.security.acls。

1.4.1.6. CAS - spring-security-cas-client.jar

Spring Security 的CAs 客户端集成。如果你希望使用Spring Security web 认证整合

一个CAS 单点登录服务器。顶级包是org.springframework.security.cas。

1.4.1.7. OpenID - spring-security-openid.jar

OpenID web 认证支持。用来认证用户,通过一个外部的OpenID 服务。

org.springframework.security.openid。需要OpenID4Java。

1.4.

2. 获得源代码

Spring Security 是一个开源项目,我们大力推荐你从subversion 获得源代码。这样你可以获得所有的示例,你可以很容易的建立目前最新的项目。获得项目的源代码对调试也

有很大的帮助。异常堆栈不再是模糊的黑盒问题,你可以直接找到发生问题的那一行,查找发生了什么额外难题。源代码也是项目的最终文档,常常是最简单的方法,找出这些事情是如何工作的。

要像获得项目最新的源代码,使用如下subversion 命令:

svn checkout

https://www.sodocs.net/doc/0f1184545.html,/svnroot/acegisecurity/spring-security/ trunk/

你可以获得特定版本的源代码

https://www.sodocs.net/doc/0f1184545.html,/svnroot/acegisecurity/spring-security /tags/.

Security 命名空间配置

2.1. 介绍

从Spring-2.0开始可以使用命名空间的配置方式。使用它呢,可以通过附加xml 架构,

为传统的spring beans 应用环境语法做补充。你可以在spring 参考文档得到更多信息。命名空间元素可以简单的配置单个bean,或使用更强大的,定义一个备用配置语法,这可以更加紧密的匹配问题域,隐藏用户背后的复杂性。简单元素可能隐藏事实,多种bean 和

处理步骤添加到应用环境中。比如,把下面的security 命名元素添加到应用环境中,将会为测试用途,在应用内部启动一个内嵌LDAP 服务器:

这比配置一个Apache 目录服务器bean 要简单得多。最常见的替代配置需求都可以使用ldap-server 元素的属性进行配置,这样用户就不用担心他们需要设置什么,不用担心bean 里的各种属性。[1]。使用一个良好的XML 编辑器来编辑应用环境文件,应该提供可用的属性和元素信息。我们推荐你尝试一下SpringSource 工具套件因为它具有处理spring 组合

命名空间的特殊功能。

要开始在你的应用环境里使用security 命名空间,你所需要的就是把架构声明添加到你的应用环境文件里:

xmlns:security="https://www.sodocs.net/doc/0f1184545.html,/schema/security"

xmlns:xsi="https://www.sodocs.net/doc/0f1184545.html,/2001/XMLSchema-instance"

xsi:schemaLocation="https://www.sodocs.net/doc/0f1184545.html,/schema/beans

https://www.sodocs.net/doc/0f1184545.html,/schema/beans/spring-beans-3.0.xsd

https://www.sodocs.net/doc/0f1184545.html,/schema/security

https://www.sodocs.net/doc/0f1184545.html,/schema/security/spring-security-3.0.xsd">

...

在许多例子里,你会看到(在示例中)应用,我们通常使用"security"作为默认的命名空间,而不是"beans",这意味着我们可以省略所有security 命名空间元素的前缀,使上下文更容易阅读。如果你把应用上下文分割成单独的文件,让你的安全配置都放到其中一个文件里,这样更容易使用这种配置方法。你的安全应用上下文应该像这样开头

xmlns:beans="https://www.sodocs.net/doc/0f1184545.html,/schema/beans"

xmlns:xsi="https://www.sodocs.net/doc/0f1184545.html,/2001/XMLSchema-instance"

xsi:schemaLocation="https://www.sodocs.net/doc/0f1184545.html,/schema/beans

https://www.sodocs.net/doc/0f1184545.html,/schema/beans/spring-beans-3.0.xsd

https://www.sodocs.net/doc/0f1184545.html,/schema/security

https://www.sodocs.net/doc/0f1184545.html,/schema/security/spring-security-3.0.xsd"> ...

就在这一章里,我们都将假设使用这种语法。

2.1.1. 命名空间的设计

命名空间被用来设计成,处理框架内最常见的功能,提供一个简化和简洁的语法,使他们在一个应用程序里。这种设计是基于框架内的大型依赖,可以分割成下面这些部分:

Web/HTTP 安全- 最复杂的部分。设置过滤器和相关的服务bean 来应用框架验证机制,

保护URL,渲染登录和错误页面还有更多。

业务类(方法)安全- 可选的安全服务层。

AuthenticationManager - 通过框架的其它部分,处理认证请求。AccessDecisionManager - 提供访问的决定,适用于web 以及方法的安全。一个默认的

主体会被注册,但是你也可以选择自定义一个,使用正常的spring bean 语法进行声明。AuthenticationProviders - 验证管理器验证用户的机制。该命名空间提供几种标准选项,意味着使用传统语法添加自定义bean。

UserDetailsService - 密切相关的认证供应器,但往往也需要由其他bean 需要。

下一章中,我们将看到如何把这些放到一起工作。

2.2. 开始使用安全命名空间配置

在本节中,我们来看看如何使用一些框架里的主要配置,建立一个命名空间配置。我们假设你最初想要尽快的启动运行,为已有的web 应用添加认证支持和权限控制,使用一些测试登录。然后我们看一下如何修改一下,使用数据库或其他安全信息参数。在以后的章节里我们将引入更多高级的命名空间配置选项。

2.2.1. 配置web.xml

我们要做的第一件事是把下面的filter 声明添加到web.xml 文件中:

springSecurityFilterChain

org.springframework.web.filter.DelegatingFilterProxy

springSecurityFilterChain

/*

这是为Spring Security 的web 机制提供了一个调用钩子。DelegatingFilterProxy 是

一个Spring Framework 的类,它可以代理一个application context 中定义的Spring bean 所实现的filter。这种情况下,bean 的名字是"springSecurityFilterChain",这是由命名空间创建的用于处理web 安全的一个内部的机制。注意,你不应该自己使用这个bean 的名字。一旦你把这个添加到你的web.xml 中,你就准备好开始编辑呢的application context 文件了。web 安全服务是使用元素配置的。

2.2.2. 最小配置

只需要进行如下配置就可以实现安全配置:

这表示,我们要保护应用程序中的所有URL,只有拥有ROLE_USER 角色的用户才能访问。元素是所有web 相关的命名空间功能的上级元素。元素定义了pattern,用来匹配进入的请求URL,使用一个ant 路径语法。access 属性定义了请求

匹配了指定模式时的需求。使用默认的配置,这个一般是一个逗号分隔的角色队列,一个用户中的一个必须被允许访问请求。前缀“ROLE_”表示的是一个用户应该拥有的权限比对。换句话说,一个普通的基于角色的约束应该被使用。Spring Security 中的访问控制不限于简单角色的应用(因此,我们使用不同的前缀来区分不同的安全属性).我们会在后面看到这些解释是可变的[2]

Note

你可以使用多个元素为不同URL 的集合定义不同的访问需求,它们会被归入一个有序队列中,每次取出最先匹配的一个元素使用。所以你必须把期望使用的匹配条件放到最上边。你也可以添加一个method 属性来限制匹配一个特定的HTTP

method(GET, POST, PUT 等等)。对于一个模式同时定义在定义了method 和未定义method 的情况,指定method 的匹配会无视顺序优先被使用。

要是想添加一些用户,你可以直接使用下面的命名空间直接定义一些测试数据:

如果你熟悉以前的版本,你很可能已经猜到了这里是怎么回事。元素会创建一个FilterChainProxy 和filter 使用的bean。以前常常出现的,因为filter 顺序不正确产生的问题,不会再出现了,现在这些过滤器的位置都是预定义好的。

元素创建了一个DaoAuthenticationProvider bean ,

元素创建了一个InMemoryDaoImpl。所有authentication-provider

元素必须作为 的子元素,它创建了一个ProviderManager,并把authentication provider 注册到它里面。你可以在命名空间附

录中找到关于创建这个bean 的更新信息。很值得去交叉检查一下这里,如果你希望开始

理解框架中哪些是重要的类以及它们是如何使用的,特别是如果你希望以后做一些自定义工作。

上面的配置定义了两个用户,他们在应用程序中的密码和角色(用在权限控制上)。也可以从一个标准properties 文件中读取这些信息,使用user-service 的properties 属性。参考in-memory authentication 获得更多信息。使用元素意味

着用户信息将被认证管理用作处理认证请求。你可以拥有多个

元素来定义不同的认证数据,每个会被需要时使用。

现在,你可以启动程序,然后就会进入登录流程了。试试这个,或者试试工程里的“tutorial”例子。上述配置实际上把很多服务添加到了程序里,因为我们使用了auto-config 属性。比如,表单登录和"remember-me"服务自动启动了。

2.2.2.1. auto-config包含了什么?

我们在上面用到的auto-config 属性,其实是下面这些配置的缩写:

这些元素分别与form-login,基本认证和注销处理对应。[3] 他们拥有各自的属性,来改

变他们的具体行为。

2.2.2.2. 表单和基本登录选项

你也许想知道,在需要登录的时候,去哪里找这个登录页面,到现在为止我们都没有提到任何的HTML 或JSP 文件。实际上,如果我们没有确切的指定一个页面用来登录,Spring Security 会自动生成一个,基于可用的功能,为这个URL 使用标准的数据,处理提交的登录,然后在登陆后发送到默认的目标URL。然而,命名空间提供了许多支持,让你可以自定义这些选项。比如,如果你想实现自己的登录页面,你可以使用:

注意,你依旧可以使用auto-config。这个form-login 元素会覆盖默认的设置。也要注

意我们需要添加额外的intercept-url 元素,指定用来做登录的页面的URL,这些URL 应该可以被匿名访问。[4] 否则,这些请求会被/**部分拦截,它没法访问到登录页面。这是一个很常见的配置错误,它会导致系统出现无限循环。Spring Security 会在日志中发出一个警告,如果你的登录页面是被保护的。也可能让所有的请求都匹配特定的模式,通过完全的安全过滤器链:

主要的是意识到这些请求会被完全忽略,对任何Spring Security 中web 相关的配置,或额外的属性,比如requires-channel,所以你会不能访问当前用户信息,或调用被保护方法,在请求过程中。使用access='IS_AUTHENTICATED_ANONYMOUSLY'作为一个

选择方式如果你还想要安全过滤器链起作用。

如果你希望使用基本认证,代替表单登录,可以把配置改为:

基本身份认证会被优先用到,在用户尝试访问一个受保护的资源时,用来提示用户登录。在这种配置中,表单登录依然是可用的,如果你还想用的话,比如,把一个登录表单内嵌到其他页面里。

2.2.2.2.1. 设置一个默认的提交登陆目标

如果在进行表单登陆之前,没有试图去访问一个被保护的资源,default-target-url 就会起

作用。这是用户登陆后会跳转到的URL ,默认是"/" 。你也可以把

always-use-default-target 属性配置成"true",这样用户就会一直跳转到这一页(无论登陆是“跳转过来的”还是用户特定进行登陆)。如果你的系统一直需要用户从首页进入,就

可以使用它了,比如:

always-use-default-target='true' />

2.2.

3. 使用其他认证提供器

现实中,你会需要更大型的用户信息源,而不是写在application context 里的几个名字。多数情况下,你会想把用户信息保存到数据库或者是LDAP 服务器里。LDAP 命名空间会

在LDAP 章里详细讨论,所以我们这里不会讲它。如果你自定义了一个Spring Security

的UserDetailsService 实现,在你的application context 中名叫"myUserDetailsService",然后你可以使用下面的验证。

如果你想用数据库,可以使用下面的方式

这里的“securityDataSource”就是DataSource bean 在application context 里的名字,它指向了包含着Spring Security 用户信息的表。另外,你可以配置一个Spring Security JdbcDaoImpl bean,使用user-service-ref 属性指定:

class="https://www.sodocs.net/doc/0f1184545.html,erdetails.jdbc.JdbcDaoImpl">

你也可以使用标准的AuthenticationProvider 类,像下面

这里myAuthenticationProvider 是你的application context 中的一个bean 的名字,

它实现了AuthenticationProvider。查看Section 2.6, “验证管理器和命名空间”了解更多信

息, AuthenticationManager 使用命名空间在Spring Security 中是如何配置的。

2.2.

3.1. 添加一个密码编码器

你的密码数据通常要使用一种散列算法进行编码。使用元素支持

这个功能。使用SHA 加密密码,原始的认证供应器配置,看起来就像这样:

authorities="ROLE_USER" />

在使用散列密码时,用盐值防止字典攻击是个好主意,Spring Security 也支持这个功能。理想情况下,你可能想为每个用户随机生成一个盐值,不过,你可以使用从UserDetailsService 读取出来的UserDetails 对象中的属性。比如,使用username 属性,你可以这样用:

你可以通过password-encoder 的ref 属性,指定一个自定义的密码编码器bean。这应

该包含application context 中一个bean 的名字,它应该是Spring Security 的PasswordEncoder 接口的一个实例。

2.3. 高级web特性

2.3.1. Remember-Me认证

参考Remember-Me 章获得remember-me 命名空间配置的详细信息。

2.3.2. 添加HTTP/HTTPS信道安全

如果你的同时支持HTTP 和HTTPS 协议,然后你要求特定的URL 只能使用HTTPS,这时

可以直接使用的requires-channel 属性:

requires-channel="https"/>

...

使用了这个配置以后,如果用户通过HTTP 尝试访问"/secure/**"匹配的网址,他们会先

被重定向到HTTPS 网址下。可用的选项有"http", "https" 或"any"。使用"any"意味

着使用HTTP 或HTTPS 都可以。

如果你的程序使用的不是HTTP 或HTTPS 的标准端口,你可以用下面的方式指定端口对应

关系:

...

你可以在???找到更详细的讨论。

2.3.3. 会话管理

2.3.3.1. 检测超时

你可以配置Spring Security 检测失效的session ID,并把用户转发到对应的URL。这

可以通过session-management 元素配置: ...

invalid-session-url="/sessionTimeout.htm" />

2.3.3.2. 同步会话控制

如果你希望限制单个用户只能登录到你的程序一次,Spring Security 通过添加下面简单的部分支持这个功能。首先,你需要把下面的监听器添加到你的web.xml 文件里,让Spring Security 获得session 生存周期事件:

org.springframework.security.web.session.HttpSessionEventPublisher

然后,在你的application context 加入如下部分:

...

这将防止一个用户重复登录好几次-第二次登录会让第一次登录失效。通常我们更想防止第二次登录,这时候我们可以使用

...

第二次登录将被阻止,通过“注入”,我们的意思是用户会被转发到

authentication-failure-url,如果使用了form-based 登录。如果第二次验证使用了其

他非内置的机制,比如“remember-me”,一个“未认证”(402)错误就会发送给客户端。如果你希望使用一个错误页面替代,你可以在session-management 中添加

session-authentication-error-url 属性。

如果你为form-based 登录使用了自定义认证,你就必须特别配置同步会话控制。更多的细节可以在会话管理章节找到。

2.3.3.3. 防止Session固定攻击

Session 固定攻击是一个潜在危险,当一个恶意攻击者可以创建一个session 访问一个网站的时候,然后说服另一个用户登录到同一个会话上(比如,发送给他们一个包含了session 标识参数的链接)。Spring Security 通过在用户登录时,创建一个新session 来防止这个问题。如果你不需要保护,或者它与其他一些需求冲突,你可以通过使用中的session-fixation-protection 属性来配置它的行为,它有三个选项

migrateSession - 创建一个新session,把原来session 中所有属性复制到新session

中。这是默认值。

none - 什么也不做,继续使用原来的session。

newSession - 创建一个新的“干净的”session,不会复制session 中的数据。

2.3.4. 对OpenID的支持

命名空间支持OpenID 登录,替代普通的表单登录,或作为一种附加功能,只需要进行简单的修改:

你应该注册一个OpenID 供应器(比如https://www.sodocs.net/doc/0f1184545.html,),然后把用户信息添加到你的内

中:

你应该可以使用https://www.sodocs.net/doc/0f1184545.html, 网站登录来进行验证了。也可能选择一个特定的UserDetailsService bean 来使用OpenID,通过设置元素。查看上一节认证提供器获得

更多信息。请注意,上面用户配置中我们省略了密码属性,因为这里的用户数据只用来为数据读取数据。内部会生成一个随机密码,放置我们使用用户数据时出现问题,无论在你的配置的地方使用认证信息。

2.3.4.1. 属性交换

支持OpenID 的属性交换。作为一个例子,下面的配置会尝试从OpenID 提供器中获得

email 和全名,这些会被应用程序使用到:

/>

每个OpenID 的“type”属性是一个URI,这是由特定的schema 决定的,在这个例子中

是https://www.sodocs.net/doc/0f1184545.html,/。如果一个属性必须为了成功认证而获取,可以设置required。

确切的schema 和对属性的支持会依赖于你使用的OpenID 提供器。属性值作为认证过程

的一部分返回,可以使用下面的代码在后面的过程中获得:OpenIDAuthenticationToken token = (OpenIDAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

List attributes = token.getAttributes();

OpenIDAttribute 包含的属性类型和获取的值(或者在多属性情况下是多个值)。我们将看到更多关于SecurityContextHolder 如何使用的信息,只要我们在技术概述章节浏览核心Spring Security 组件。

2.3.5. 添加你自己的filter

如果你以前使用过Spring Security,你就应该知道这个框架里维护了一个过滤器链,来提供服务。你也许想把你自己的过滤器添加到链条的特定位置,或者使用一个Spring Security 的过滤器,这个过滤器现在还没有在命名空间配置中进行支持(比如CAS)。或者你想要使用一个特定版本的标准命名空间过滤器,比如 创建的

UsernamePasswordAuthenticationFilter,从而获得一些额外的配置选项的优势,这些

可以通过直接配置bean 获得。你如何在命名空间配置里实现这些功能呢?过滤器链现在已经不能直接看到了。

过滤器顺序在使用命名空间的时候是被严格执行的。当application context 创建时,过滤器bean 通过namespace 的处理代码进行排序,标准的spring security 过滤器都有

自己的假名和一个容易记忆的位置。

Note

在之前的版本中,排序是在过滤器实例创建后执行的,在application context 的执行后的过程中。在3.0+版本中,执行会在bean 元元素级别被执行,在bean 实例化之前。这

会影响到你如何添加自己的过滤器,实体过滤器列表必须在解析元素的过程中了

解这些,所以3.0中的语法变化的很明显。

有关创建过滤器的过滤器,假名和命名空间元素,属性可以在Table 2.1, “标准过滤器假名和顺

序”中找到。过滤器按照次序排列在过滤器链中。

Table 2.1. 标准过滤器假名和顺序

假名过滤器累命名空间元素或属性

CHANNEL_FILTER ChannelProcessingFilter

http/intercept-url@requir

es-channel

CONCURRENT_SESSI

ON_FILTER

ConcurrentSessionFilter

session-management/con

currency-control

SECURITY_CONTEXT

_FILTER

SecurityContextPersistenceFil

ter

http

LOGOUT_FILTER LogoutFilter http/logout

X509_FILTER X509AuthenticationFilter http/x509

PRE_AUTH_FILTER

AstractPreAuthenticatedProce

ssingFilterSubclasses

N/A

CAS_FILTER CasAuthenticationFilter N/A

FORM_LOGIN_FILTER

UsernamePasswordAuthentic

ationFilter

http/form-login

BASIC_AUTH_FILTER BasicAuthenticationFilter http/http-basic

SERVLET_API_SUPPO

RT_FILTER

SecurityContextHolderAware

Filter

http/@servlet-api-provisi

on

REMEMBER_ME_FILT

ER

RememberMeAuthenticationF

ilter

http/remember-me

ANONYMOUS_FILTER SessionManagementFilter http/anonymous

SESSION_MANAGEM

ENT_FILTER

AnonymousAuthenticationFilt

er

session-management

EXCEPTION_TRANSL

ATION_FILTER

ExceptionTranslationFilter http

FILTER_SECURITY_IN

TERCEPTOR

FilterSecurityInterceptor http

SWITCH_USER_FILTE

R

SwitchUserAuthenticationFilt

er

N/A

你可以把你自己的过滤器添加到队列中,使用custom-filter 元素,使用这些名字中的一个,来指定你的过滤器应该出现的位置:

你还可以使用after 或before 属性,如果你想把你的过滤器添加到队列中另一个过滤器

的前面或后面。可以分别在position 属性使用"FIRST" 或"LAST"来指定你想让你的过

滤器出现在队列元素的前面或后面。

避免过滤器位置发生冲突

如果你插入了一个自定义的过滤器,而这个过滤器可能与命名空间自己创建的标准过滤器放在同一个位置上,这样首要的是你不要错误包含命名空间的版本信息。避免使用

auto-config 属性,然后删除所有会创建你希望替换的过滤器的元素。

注意,你不能替换那些 元素自己使用而创建出的过滤器,比如SecurityContextPersistenceFilter, ExceptionTranslationFilter 或FilterSecurityInterceptor。

如果你替换了一个命名空间的过滤器,而这个过滤器需要一个验证入口点(比如,认证过程是通过一个未通过验证的用户访问受保护资源的尝试来触发的),你将也需要添加一个自定义的入口点bean。

英语本科段自学考试英汉翻译教程Unit 7 Literature.doc

Unit 7 Literature (2) Lesson 19(E—C) East of Eden(1) By John Steinbeck The Salinas Valley is in Northern California. It is a long narrow swale betwwen two ranges of mountains, and the Salinas River winds and twists up the center until it falls at last into Monterey Bay. I remember my childhood names for grasses and secret flowers. I remember where a toad may live and what time the irds awaken in the summer—and what trees and seasons smelled like—how people looked and walked and smelled even. The memory of odors is very rich. I remember that the Gabilan Mountains to the east of the valley were light gay mountains full of sun and loveliness and a kind of invitation, so that you wanted to climb into their warm foothills almost as you want to climb into the lap of a beloved mother. They were beckoning mountains with a brown grass love. The Santa Lucias stood up against the sky to the west and kept the valley from the open sea, and they were dark and brooding—unfriendly and dangerous. I always found in myself a dread of west and a love of east. Where I ever got such an idea I cannot say, unless it could be that the morning came over the peaks of the Gabilans and the night drifted back from the ridges of the Santa Lucias. It may be that the birth and death of the day had some part in my feeling about the two ranges of mountains. From both sides of the valley little streams slpipped out of the hill canyons and fell into the bed of the Salinas River. In the winte of wet years the streams ran full-freshet, and they swelled the river until sometimes it raged and boiled, bank full, and then it was a destroyer. The river tore the edges of the farm lands and washed whole acres down; it toppled barns and houses into itself, to go floating and bobbing away. It trapped cows and pigs and sheep and drowned them in its muddy brown water and carried them to the sea. Then when the late spring came, the river drew in from its edges and the sand banks appeared. And in the summer the river didn’t run at all above ground. Some pools would be left in the deep swirl places under a high bank. The tules and grasses grew back, and willows straightened up with the flood debris in their upper branches. The Salinas was only a part-time river. The summer sun drove it underground. It was not a fine river at all, but it was the only one we had and so we boasted about it—how dangerous it was in a wet winter and how dry it was in a dry summer. You can boast about anything if it’s all you have. Maybe the less you have, the more you are required to boast. (from John Steinbeck, East of Eden, Chapter1) 译文: 萨利内斯河谷位于加利福民亚州北部。那是两条山脉之间的一片狭长的洼地,萨利内斯河蜿蜒曲折从中间流过,最后注入蒙特雷海湾。 我记得儿时给各种小草和隐蔽的小花取的名字。我记得蛤蟆喜欢在什么地方栖身,鸟雀夏天早晨什么时候醒来——我还记得树木和不同季节特有的气息——记得人们的容貌、走路的姿势、甚至身上的气味。关于气味的记忆实在太多啦。 我记得河谷东面的加毕仑山脉总是阳光璀璨、明媚可爱,仿佛向你殷勤邀请,你不禁想爬上暖洋洋的山麓小丘,正像爬到亲爱的母亲怀里那样。棕色的草坡给你爱抚,向你召唤。西面的圣卢西亚斯山脉高耸入云,黑压压地挡在河谷和大海之间,显得不友好而危险。我发

自考英汉翻译模拟试题2

第一部分选择题 PART ONE 1.Multiple Choice Questions(20 points,2 points for each) A.Directions:This part consists of five sentences-each followed by four different translations labeled A、B、C and D.Choose the one that is the most equivalent to the original in terms of meaning and expressiveness. 1.He is the last person whom I expected to meet.( ) A.他是我最后希望见到的人。B.我怎么也没想到会见到他。 C.他是我最不想见到的人。D.他决不是我期望见到的那个人。 2.Since World WarⅡ,the U.S has been the world’s largest economy country and,in most years,the world’s largest exporter.( ) A.自从第二次世界大战以来,美国一直是世界上最大的经济大国,在大多数年代中,它又是世界上最大的出口国。 B.由于二次世界大战,美国成为世界上最大的经济大国,而且在许多年中,它又是世界上最大的出口国。 C.自从第二次世界大战以来,美国经济成为世界上最强大的,而且在许多年中,它又是世界上最大的出口国。 D.由于二次世界大战,美国经济成为世界上最强大的,而且在许多年中,它又是世界上最大的出口国。 3.It was better for you to know that Richard Was,by nature,a mail of new words.( ) A.对于你来说,知道理查德在本质上是一个话很少的人是再好不过了。

自考《英汉翻译教程》第一章习题答案以及考试重点

《英汉翻译教程》第一章习题答案 一、Bill Morrow's Birthday Party 比尔?莫罗的寿宴 比尔作为中国政府的客人访问中国,好几次者赶上在北京过生日。每次,主人总要为他举行宴会,周恩来总理也出席。他还记得第一次生日宴会的情景: 我在饭店吃饭,最后总是吃冰激凌。我吃得津津有味,惹得那些女服务员发笑。这次生日宴会,周恩来在场。快到结束的时候,他站起来,走到柜台前,要了一杯冰激凌,放在我面前——别忘了,他可是总理呀!他对我说:“这是为您准备的。”我说:“没想到您会说英语呀。”他笑了起来,接着说:“一点点。”一面说着,一面用食指和拇指比划着。后来有时候我们单独在一起,他就跟我说英语。 “这是为您准备的。”这句话,比尔?莫罗在许多难忘的场合听到过——比如在他乘般沿大运河南下的时候,从旁边驶过的每一条般都拉响汽笛,表示敬意。再比如参观南京长江大桥;在修这座桥以前,要靠渡般在这里运送火车过江。参观大桥的时候,天快黑了,人家给了他一把椅子,请他坐下等一会儿。忽然电灯全亮了,照出了整个大桥的轮廓。“这是为您准备的。”他不满地说道:“你们不应该费这么多电,就为了让我高兴。”人家对他说:“全南京也都可以欣赏嘛。” 比尔?莫罗想了解一些新的情况,周恩来就安排北京大学的专家向他作介绍。比尔说:“我在国内不过是个流浪汉,而你们在这里却把我当成一位要人。”周恩来却说:“您做过些什么,我们是知道的。” 二、The Story of My Life (Excerpt 2) 我的生活(摘录2) 海伦?凯勒 我感到有人走近,于是伸出了手,以为是把手伸向母亲。不知是谁抓住了我的手,把我拉过去,紧紧地搂在她的怀里。就是她教我认识了世上的各种事物,而且不仅如此,她还疼爱我。

自考英汉翻译教程词汇整理

自考英汉翻译教程词汇整理

Unit 1 lesson 1 1. fellow countrymen 同胞 2. average height 中等身材 3. gleaming eyes 闪光的眼睛 4. in his middle twenties 二十多岁 5. to be seated 招呼坐下 6. stand squarely 端正正地站着 7. more than ten years his junior 比她年轻十几岁 8. revolutionary road 革命道路 9. Chinese communist Party中共 10. full member 正式成员 11. membership 党籍 12. keep a secret 保密 Lesson 2 1. immeasurable contrast 迥然不同 2. to and fro 走来走去 3. upturn face 仰着脸 4. sweet spring 芬芳的春天 5. anger and bitterness 又气愤又苦恼 6. dense fog 大雾 7. tense and anxious 紧张而焦急

8. 五一的下午on the afternoon of May 1st 9. 无言的呼唤wordless cry 10. 探测绳sounding-line Lesson 3 1. 各种流派的different schools 2. 前两天a few days ago 3. 受限制be restricted/be subjected to 4. 传统观念traditional thinking 5. 不合理的制度irrational system 6. 最高境界the highest state 7. 浓妆艳抹heavy make up 8主人公chief character/principal character 9. 花言巧语flowery language 10.社会进步人性发展social progress and human development Unit 2 Lesson 4 1. 工业革命Industrial Revolution 2. 多功能的机器multi-purpose machine 3. 出于自愿和兴趣on one’s own account, out of interest 4. 新兴城市the rising town

英汉翻译教程自考题 15

英汉翻译教程自考题-15 (总分:100.00,做题时间:90分钟) 一、{{B}}Ⅰ.Multiple Choice{{/B}}(总题数:0,分数:0.00) 二、{{B}}A.Directions: This part consists of ten sentences, each followed by four different versions marked A, B, C and D. Choose the best translation of the original statement in terms of meaning and expressiveness.{{/B}}(总题数:10,分数:20.00) 1.I felt approaching footsteps. I stretched out my hand as I supposed to my mother. ______ ?A.我感到有人走近,于是伸出了手,以为是把手伸向母亲。 ?B.我感到有人走近,我就伸出了手,因为我在等我的母亲。 ?C.我感到有人向我走来,我想那是我母亲,她把手伸向我。 ?D.我感到有人向我走来,我想那是我母亲,她伸手搂抱我。 (分数:2.00) A. √ B. C. D. 解析:[解析] 本题考查句子中动词的翻译。本句的动词是由felt, stretched, supposed一系列的动作构成的,而这 些动作的主语是同一个人,所以只需要写出一个主语,这样显得句子紧凑有力。那么就可以排除B、C、D三项。答案为A。 2.She blurred the ink on the letter with her tears. ______ ?A.她的眼泪把信上的墨水弄得模糊不清。 ?B.她的眼泪把信上的字迹弄得模糊不清。 ?C.她的眼泪把信上的字句弄得模糊不清。 ?D.她的眼泪把信上的话语弄得模糊不清。 (分数:2.00) A. B. √ C. D. 解析:[解析] 本句考查词语暗含意思的翻译。名词ink本身是“墨水”的意思,但是the ink on the letter是表示 信上的“字迹”。同时按照语言习惯,眼泪模糊的是字迹而不是墨水,故选项A、C、D均不正确。答案为B。 3.Bill was given a chair and asked to wait a little as darkness came on, then suddenly the whole bridge was outlined in lights.______ ?A.天快黑了,有人给比尔一把椅子,请他坐下等一会儿。忽然电灯全亮了,整座大桥的轮廓被灯照了出来。 ?B.给比尔一把椅子,他被要求坐下等一会儿,天快黑了。忽然电灯全亮了,照出了整座大桥的轮廓。. ?C.天快黑了,有人给比尔一把椅子,请他坐下等一会儿。忽然电灯全亮了,照出了整座大桥的轮廓。 ?D.给比尔一把椅子,他被要求坐下等一会儿,天快黑了。忽然电灯全亮了,整座大桥的轮廓被灯照了出来。 (分数:2.00)

英语本科段自学考试英汉翻译教程Unit2 History.doc

Unit2 History Lesson 4 (E—C) Ngland Before the Idndustrial Revolution The contry was a place where men worked form dawn to dark, and the labourer lived not in thd sun, but in poverty and karkness. What aids there were to lighten labour were immemorial, like the mill, which was already ancient in Chaucer?s time. The Industrial Revolution began with such machines; the millwrights were the engineers of the coming age. James Brindley of Staffordshire started his self-made career in 1733 by working at mill wheels, at the age of seventeen, having been born poor in a illage. Brindley?s improvements were practical: to sharpen and step up the performance of the water wheel as a machine. It was the first multi-purpose machine for the new industries. Brindley worked, for example, to improve the grinding of flints, which were used in the rising pottery industry. Yet there was a bigger movement in the air by 1750. water had become the engineers?element, and men like Brindley were possessed by it. Water was gushing and fanning out all over the countryside. It was not simply a source of power, it was a new wave of movement. James brindley was a pioneer in the art of building canals or, as it was then called, …navigation?. Brindley had begun on his own account, out of interest, to survey the waterways that he travelled as he went about his engineering projects for mills and mines. The Duke of Bridgewater then got him to build a canal to carry coal from the Duke?s pits at Worsley to the rising town of Manchester…. Brindley went on to connect Manchester with Liverpool in an even bolder manner, and in all laid out almost four hundred miles of cannals in a network all over England. Two things are outstanding in the creation of the English system of canals, and they characterise all the Industrial Revolution. One is that the men who made the revolution were practical men. Like Brindley, they often had little education, and in fact school education as it then was could only dull an inventive mind. The grammar schools legally could only teach the classical subjects for which they had been founded. The universities also(there were only two, at Oxford and Cambridge) took little interest in modern or scientific studies; and they were closed to those who did not conform to the Church of England. The other outstanding feature is that the new invetions were for veryday use. The canals were arteries of communication: They were not made to carry pleasure boat, but barges. And the barges were not made to carry luxuries,but pots and pans and bales of cloth, boxes of ribbon, and all the common things that people buy by the pennyworth. These things had been manufactured in villages which were growing into towns now, away from London; it was a country-wide trade. (from J. Bronowski, The Ascent of Man) 译文: 工业革命前的英国 在农村,人们从早到晚都得干活,劳动者并不是沐浴在阳光下,而是生活在贫困和黑暗中,那些帮助减轻劳动的机械都不知从哪个年代起就有了。比如磨坊、在乔叟的时代就已经是古老的。而工业革命就是从这些机械开始的。修造磨坊的匠人就是开创新时代的工程师。斯塔福郡的詹姆斯·布林德雷,出身于一个贫苦的农村家庭;一七三三年,他十七岁,就着手改良磨坊的车轮,从而开始了他那自我奋斗的生涯。 布林德雷所作的改良是很实际的:改善并加强水车的机械功能。这是为新工业提供的

英语本科段自学考试英汉翻译教程Unit 6 Literature.doc

Unit 6 Literature(1) Lesson 16(E—C) Tess of the D‘Urbervilles(1) By Thomas Hardy On an evening in the latter part of May a middle-aged man was walking homeward from Shaston to the village of Marlott, in the adjoinning Vale of Blakemore or Blackmoor. The pair of legs that carried him were rickety, and there was a bias in his gait which inclined him somewhat to the left of a straight line. He occasinally gave a smart nod, as if in confirmation of some opinion, though he was not thinking of anything in particular. An empty egg-basket was slung upon his arm, the nap of his hat was reffled, a patch being quite worn away at its brim where his thumb came in taking it off. Presently hi was met by an elderly parson astride on a gray mare, who, as he rode, hummed a wandering tune. ?Good night t‘ee,‘ said the man with the basket. ?Good night, Sir John,‘ said the parson. The pedestrian, after another pace or two, halted, and turned round. ?Now, sir, begging your pardon; we met last market-day on this road about this time, and I zaid ―Good night,‖ and you made reply ―Good night, Sir John,‖ as now.‘ ?I did,‘ said the parson. ?And once before that—near a month ago.‘ ?I may have.‘ ?Then what might your meaning be in calling me ―Sir John‖ these different times, when I be plain Jack Durbeyfield, the haggler? The parson rode a step or two nearr. ?It was only my whim,‘he said; and, after a moment‘s hesitation: ?It was on account of a discovery I made some little time ago, whilst I was hunting up pedigres for the new county history. I am Parson Tringham, the antiquary, of Stagfoot Lane. Don‘t you reaally know, Durbeyfield, that you are the lineal representative of the ancient and knightly family of the d‘Urbervilles, who dervie their descent from Sir Pagan d‘Urberville, that renowned knight who came from Normandy with William the Conqueror, as appears by Battle Abbey Roll?‘ ?Never heard it before, sir!‘ ?Well it‘s true.‘ … ?But you‘ll turn back and have a quart of beer wi‘me on the strength o‘t Pa‘son Tringham? There‘s a very pretty brew in tap at The Pure Drop—though, to be sure, not so good as at Rolliver‘s.‘ ?No, thank you—not this evening, Durbeyfield. You‘ve had enough already.‘ (from Thomas Hardy, Tess of the D‘Urbervilles, Chapter 1) 译文: 五月后半月里,有一天傍晚,一个中年男子,正打沙氏屯,朝着跟这相连的那个布蕾谷(或者布莱谷)里面的马勒村往家里走去。支着他的那两条腿老是摇摇晃晃的,他走路的姿势里,又总有一种倾斜的趋势,使他或多或少地往一条直线的左边歪。待一会儿他就轻快地把头一点,好像是对某一个意见表示赞成似的,其实他心里头可并没想什么特别的事儿。

英汉翻译教程 自考Lesson 2 The Story of My Life

Lesson 2 The Story of My Life 1.Warm-up (8’) How much do you know Helen Keller ? And why her books had been translated into several languages? Three Days to See 海伦·凯勒(Helen Keller 1880年6月27日-1968年6月1日),19世纪美国盲聋女作家、教育家、慈善家、社会活动家。她以自强不息的顽强毅力,在安妮。莎莉文老师的帮助下,掌握了英、法、德等五国语言。完成了她的一系列著作,并致力于为残疾人造福,建立慈善机构,被美国《时代周刊》评为美国十大英雄偶像,荣获“总统自由勋章”等奖项。主要著作有《假如给我三天光明》、《我的生活》、《我的老师》等。伟大的著名作家马克·吐温说:“19世纪有两个值得关注的人,一个是拿破仑,另一个就是海伦·凯勒。” If you were blind and deaf now, what would you do? II. Teaching objectives ( 2’) 1.Grasp the skills of translating stories. 2.Know about Helen Keller ? III. 语言对比与翻译方法(40’+40’) 1. Before 的翻译:在…之前,在…之后 It was not long before we met again. 不多久后,我们又见面了。 2. 搭配对比: 洗钱wash money × to launder money √ 和某人结婚to marry with a person to marry a person √ 擅长音乐to excel music to excel at music 写作业to write my homework to do my homework “share” –分享(积极的方面) Share the authority and the burdens. 共享权力,共担责任。 Share the trail and the glory。有难同当,有福同享。 We share the joys and the pains of life. 我们同欢乐,共患难。 主语的选择: 英:主语突出。主语——人、事(多)、感情、身体某一部分(多) 汉:话题突出,常无主语。主语——人、事(少)、身体某一部分(少) When the talk is between father and children, or among the children themselves, the father’ language is used. 子女与父亲说话,或兄弟姐妹间说话,都使用父亲的支系的语言。 One of many sadnesses in his life was that he never had children. 他一生中的许多遗憾之一是没有子女。 4. 词类转换 lesson 1 5. follow(接着),succeed (继而)--有时可用逆译法 the days following her birth 她出生的那几天。 This is usually made clear by the examples which follow such definitions. 在这类释义之后,通常备有例证以分清 6. 长句的译法——顺序法、逆序法、分译法、综合法 顺序法:动作按动作发生时间先后安排。

英汉翻译教程(三)试题及参考答案

高等教育自学考试冲刺模拟试卷一 (英语专业) 英汉翻译教程(三) Part One Ⅰ. Multiple Choice Questions (30 points, 2 points for each)A. Directions: This part consists of ten sentences, each followed by four different versions marked A, B, C and D. Choose the one that is the closest equivalent to the original in terms of meaning and expressiveness. 1. For Britain our membership of the European Union and the World Trade Organization has brought this home. A. 对英国来说,我们的欧盟成员和世界贸易组织成员身份把这带到了家。 B. 对英国来说,我们参加欧盟和世界贸易组织把我们送到了家。 C. 对我们英国来说,我们参加欧盟和世界贸易组织的经历使我们对这一点深有感触。 D. 对我们英国来说,我们的欧盟成员和世界贸易组织成员身份使我们如鱼得水。 2. So now he contrived an eager, ingratiating smile, which he bestowed on Mr. Squires. A. 因此他就装出急切的、迷人的笑,并投向史奎尔先生。 B. 因此他就装出殷切的、拍马的笑,并把这笑赠予史奎尔先生。 C. 因此他就对史奎尔先生装出一副殷勤、讨好的笑脸。 D. 因此他就给史奎尔先生设计了一副殷勤、讨好的笑脸。 3. “People disappear in that river every year,” one of the policemen said to me that afternoon, half in dismay, half in frustration. A. “这条河里年年都有人消失,”当天下午警察中的一个以一种无可奈何的神气沮丧地对我说。 B. “这条河里年年都要死人,”当天下午一个警察半是沮丧,半是失意地对我说。 C. “这条河里年年都要死人,”当天下午一个警察以一种无可奈何的神气沮丧地对我说。 D. “年年都有人消失在这条河里,”当天下午警察中的一个半是沮丧,半是失意地对我说。 4. As recently as the early 1960s, the phrase “environmental law” would probably have produced little more than a puzzled look, even from many lawyers. A. 早在六十年代初,“环保法”这个词儿甚至会使许多律师感到纳闷。

英汉翻译教程自考题 18

英汉翻译教程自考题-18 (总分:100.00,做题时间:90分钟) 一、{{B}}Ⅰ.Multiple Choice Questions{{/B}}(总题数:0,分数:0.00) 二、{{B}}A.{{/B}}(总题数:18,分数:18.00) 1.我觉得有一根鞭子在抽打我的心,又觉得仿佛有什么鬼魂借我的笔为自己申冤一样。______ ?A.I felt there is a whip striking my heart and I also felt there is a ghost borrowing my pen to express its injustices. ?B.I felt someone is whipping my heart and at the same time a ghost is borrowing my pen to redress its injustices. ?C.I felt my mind is whipped by a whip and a ghost takes my pen to redress its injustices. ?D.I felt as if my mind was being whipped, as if a ghost had commandeered my pen and was writing to redress the injustices it had suffered. (分数:1.00) A. B. C. D. √ 解析:[解析] 原文叙述的只是一种假设,事实上并没有发生,应该用as if(意为好像,似乎)来引导。 2.我说我写作如同在生活,又说作品的最高境界是写作同生活的一致,是作家同人的一致,主要的意思是不说谎。______ ?A. I say that I write like I live, and that the highest ideal a work of literature can attain is to be at one with life, and that an author should be able to identify with his readers, I basically mean that books and their authors should never tell lies. ?B. When I say that I write like I live,and that the highest ideal a work of literature can attain is to be at one with life, and that an author should be able to identify with his readers,I basically mean that books and their authors should never tell lies. ?C. When I say that I write as living, and that the highest ideal of a work of literature should be consistent with life and the author himself, I basically mean that books and authors should never tell lies. ?D. I say that I write as living,and that the highest ideal of a work of literature should be consistent with life and the author himself, I basically mean that books and authors should never tell lies. (分数:1.00) A. B. √ C. D. 解析:[解析] 本题主要考查的是句子的连接问题。原句中有四个短句,根据译文可以分析出,A、D两项在句子I basically mean that...之前缺少了连词;C项中对“作家同人的一致”译为了should be ,不是很准确。consistent with life and the author himself

英语本科段自学考试英汉翻译教程Unit 8 Popular Science.doc

Unit 8 Popular Science Lesson 22(E—C) Oil(1) By G.. C. Thornley There are three main groups of oil:animal, vegetable and mineral. Great quantities of animal oil come from whales, those enormous creatures of the sea which are the largest remaining animals in the world. To protect the whale from the cold of the Arctic seas, nature has provided it with a tick covering of fat called blubber. When the whale is killed, the blubber is stripped off and boiled down, either on board ship or on shore. It produces a great quantity of oil which can be made into food for human consumption. A few other creatures yield oil, but none so much as the whale. The livers of the cod and the halibut, two kinds of fish, yield nourishing oil. Both cod liver oil and halibut liver oil are given to sick children and other invalids who need certain vitamins. These oils may be bought at any chemist’s. Vegetable oil has been known from antiquity. No household can get on without it, for it is used in cooking. Perfumes may be made from the oils of certain flowers. Socpa are made from vegetable and animal oils. To the ordinary man, one kind of oil may be as important as another. But when the politician or the engineer refers to oil, he almost always means mineral oil, the oil that drives tanks, aeroplanes and warships, motor-cars and diesel locomotivs, the oil that is used to lubricate all kinds of machinery. This is the oil that is used to lubricate all knids of machinery. This is the oil that has changed the life of the common man. When it is refined into petrol it is used to drive the internal combustion engine. To it we owe the existence of the motor-car, which has replaced the private carriage drawn by the horse. To it we owe the possibility of flying. It has changed the horse. To it we owe the possiblility of flying. It has changed the methods of warfare on land and sea. This knid of oil comes out of the earth. Because it burns well, it is used as fuel and in some ways it is superior to coal in this repect. Many big ships now burn oil instead of coal. Because it burns brightly, it is used for illumination; countless homes are still illuminated with oil-burning lamps. Because it is very slippery, it is used for lubrication. Two metal surfaces rubbing together cause friction and heat; but if they are separated by a thin film of oil, the friction and heat are reduced. No machine would work for long if it were not properly lubricated. The oil used for this purpose must be of the correct thickness; if it is too thin it will not give sufficient lubrication, and if it is too thick it will not reach all parts that must e lubricated. (from English Through Reading) 参考译文: G.C.索恩利 油可以分为三大类:动物油、植物油、矿物油。大量的动物油是从鲸鱼身上得来的。鲸鱼是海里的庞然大物,是世界上现有动物中最大的一种。大自然为了保护鲸鱼,使它不不致在北冰洋受冻,便让它长了厚厚的一层脂肪,叫做鲸脂。鲸鱼杀死之后,把鲸脂剥下来熬油,这项工作有的是在船上进行的,有的是在岸上进行的。这样,就能生产出大量的油,供人们食用。有些动物也出油,但都没有鲸鱼出得多。鳕鱼和比目鱼,这两种鱼的肝脏出的油

相关主题