为什么我不再使用realm swift3 使用

解决自定义Shiro.Realm扩展类不能用注解(@Resource或@Autowire)自动装配的问题
解决自定义Shiro.Realm扩展类不能用注解(@Resource或@Autowire)自动装配的问题
问题产生原因:加载Realm时其他Spring配置文件(xml)尚未加载,导致注入失败。
解决方法:编写一个设置类把注入工作提前完成。
package com.xkt.shiro
import org.apache.shiro.realm.R
import org.apache.shiro.web.mgt.DefaultWebSecurityM
import org.springframework.beans.BeansE
import org.springframework.context.ApplicationC
import org.springframework.context.ApplicationContextA
import org.springframework.context.annotation.C
* 把securityManager和userRealm装配到ApplicationContext
@Configuration
public class ShiroConfig implements ApplicationContextAware {
public void setApplicationContext(ApplicationContext ac) throws BeansException {
Realm userRealm = (Realm) ac.getBean(&userRealm&);
DefaultWebSecurityManager defaultWebSecurityManager = (DefaultWebSecurityManager) ac.getBean(&securityManager&);
defaultWebSecurityManager.setRealm(userRealm);
我的热门文章
即使是一小步也想与你分享关注微信公众号: PMvideo
Android6.0权限处理不再复杂
作者:街头客
谷歌在2015年8月份时候,发布了Android 6.0版本,代号叫做“棉花糖”(Marshmallow ),其中的很大的一部分变化,是在用户权限授权上,或许是感觉之前默认授权的不合理,现在6.0出来,使得用户权限授权变得合理。
Android 6.0版本之前
在此版本之前,只要在清单文件(AndroidManifest)中申请需要用到的权限,安装之后,所申请的权限将会被允许。
Android 6.0版本之后
从Android6.0开始,APP可以直接安装,但所需的权限则需要动态申请。App在运行时询问用户授予权限,弹出Dialog窗口进行询问是否允许,【拒绝】之后,也可以引导用户前往设置界面。
Google将权限分为两类:一类是Normal Permissions,这类权限一般不涉及用户隐私,是不需要用户进行授权的,比如手机震动、访问网络等,所以开发者直接在清单文件中申请即可;
另一类是Dangerous Permission,一般是涉及到用户隐私的,需要用户进行授权,比如读取sdcard、访问通讯录等;
但在Dangerous Permission中,其实还有比较特殊的两个权限存在,分别是SYSTEM_ALERT_WINDOW(允许一个程序打开窗口,显示在其他所有程序的顶层)和WRITE_SETTINGS(允许应用程序更改主屏幕中的设置和快捷方式)。
这两个权限也属于Dangerous Permission,但是在申请上却有点特殊。这两个权限是不能自动授权,也不能运行时请求授权,只能引导用户去应用的设置页手动开启。
PS:Dangerous Permission的权限9大类别
Dangerous Permission的权限9大类别
只要授权某一个类别中的其中某一个权限,则该类别的权限默认全部授权,不需要针对该类别再次询问用户是否允许。
常用的权限申请
从Android6.0后,我们常用的权限申请,例如相机权限的申请,代码如下:
// 相机权限
public static final int REQUEST_CAMERA = 4;
private static String[] PERMISSIONS_CAMERA = {
Manifest.permission.CAMERA};
* 申请相机权限
* @param activity
public static void cameraPermissions(Activity activity) {
logger.debug("Camera permissions.");
int permission = ActivityCompat.checkSelfPermission(activity,
Manifest.permission.CAMERA);
if (permission != PackageManager.PERMISSION_GRANTED) {
logger.debug("Not have camera permissions.");
ActivityCompat.requestPermissions(activity, PERMISSIONS_CAMERA,
REQUEST_CAMERA);
上面是申请相机权限的代码,那么在调用的Activity类中,重写如下方法:
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == RequestPermissions.REQUEST_CAMERA) {
if (grantResults.length & 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "请授予相机权限", Toast.LENGTH_SHORT).show();
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
以上就是我们常用的权限申请。
PermissionsDispatcher
在module.build.gradle中配置,如下:
compile 'com.github.hotchemi:permissionsdispatcher:2.3.2'
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.3.2'
旧版需要在top.build.gradle中配置如下信息:
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
在module.build.gradle中配置,如下:
apply plugin: 'android-apt'
我在最新的版本2.3.2已经不需要以上的配置了,不然会生成失败。等会在下面会讲。
Activity中的使用
package com.example.chenchubin.
import android.M
import android.app.A
import android.app.AlertD
import android.content.DialogI
import android.content.I
import android.os.B
import android.provider.S
import android.support.annotation.NonN
import permissions.dispatcher.NeedsP
import permissions.dispatcher.OnNeverAskA
import permissions.dispatcher.OnPermissionD
import permissions.dispatcher.OnShowR
import permissions.dispatcher.PermissionR
import permissions.dispatcher.RuntimeP
@RuntimePermissions
public class ScanQRActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
// 检查权限
ScanQRActivityPermissionsDispatcher.getCameraWithCheck(this);
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[]
grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// 回调代理进行处理
ScanQRActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
* 已授权时,进入Activity会调用该方法
@NeedsPermission(Manifest.permission.CAMERA)
public void getCamera() {
* 授权申请提示,回调
* @param request
@OnShowRationale(Manifest.permission.CAMERA)
public void showRationaleForCamera(final PermissionRequest request) {
new AlertDialog.Builder(this)
.setCancelable(false)
.setTitle("权限申请")
.setMessage("应用需要使用相机权限,您是否确定要使用")
.setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
request.cancel();
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
request.proceed();
.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
* 拒绝时,回调
@OnPermissionDenied(Manifest.permission.CAMERA)
public void showDeniedForCamera() {
new AlertDialog.Builder(this)
.setCancelable(false)
.setTitle("权限申请")
.setMessage("在设置-应用-当前应用权限中开启相机权限,以正常使用拍照")
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//开启设置页
startActivity(new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS));
dialog.dismiss();
* 不再询问时,回调
@OnNeverAskAgain(Manifest.permission.CAMERA)
public void showNeverAskForCamera() {
new AlertDialog.Builder(this)
.setCancelable(false)
.setTitle("权限申请")
.setMessage("您已禁止不再询问,请前往设置-应用-当前应用权限中开启相机权限,以正常使用拍照")
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//开启设置页
startActivity(new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS));
dialog.dismiss();
注解的意思
@RuntimePermissions(必选)运行时,需要检查权限的类。
@NeedsPermission(必选)当进入Activity类时,如果已授权,会直接调用该注解的方法。
@OnShowRationale(可选)授权申请时,调用。
@OnPermissionDenied(可选)授权申请被拒绝时,调用。
@OnNeverAskAgain(可选)授权申请被勾选不再提示时,调用。
1,执行request.proceed()调用系统申请权限的弹窗;如果在系统申请弹窗中勾选了不在提示并且拒绝,会调用@OnNeverAskAgain的方法;
2,执行request.cancel()会调用@OnPermissionDenied的方法。
Make Project
Make Project后,编译器会在app\build\intermediates\classes\debug目录下与被注解的Activity同一个包下生成一个辅助类,名称为被注解的Activity名称+PermissionsDispatcher.class,如图所示:
ScanQRActivityPermissionsDispatcher
这里需要注意,因为我在这里遇到了一个大坑。
就是上面提到的,新版中已不需要在top.build.gradle中配置android-apt插件,要不上面的ScanQRActivityPermissionsDispatcher一直没有生成出来,找了我半个小时。。。
生成代理类后,检查调用,代码如下:
// 检查权限
ScanQRActivityPermissionsDispatcher.getCameraWithCheck(this);
进入检查提示
确定时,提示
拒绝时,提示
这样使用后,Android权限请求这一块的逻辑就变得比较友好。
以上的所有内容就是今天要讲的关于Android6.0权限处理的内容。
我自己在写这文章时,也有所收获,同时希望能对大家有所帮助。
谢谢支持~~~
关注微信公众号:PMvideo
前言:本文所写的是博主的个人见解,如有错误或者不恰当之处,欢迎私信博主,加以改正!原文链接, demo链接...
这就是圆形进度条,可以实现仿 QQ 健康计步器的效果,支持配置进度条背景色、宽度、起始角度、支持进度条渐变。...
在以前的一个项目中,需要实现类似QQ讨论组头像的控件,只是头像数量和布局有一小点不一样:一是最头像数是4个,二是头像数是2个时的布局是横着排的。其实当时GitHub上就有类似的开源...
微信,微博,微商,QQ空间,大量的软件使用内嵌了H5,这个时候就需要了解Android如何更H5交互的了;有些外包公司,为了节约成本,采用Android内嵌H5模式开发,便于在IO...
本文为菜鸟窝作者蒋志碧的连载。“从 0 开始开发一款直播 APP ”系列来聊聊时下最火的直播 APP,如何完整的实现一个类&腾讯直播&的商业化项目视频地址:http://ww...
Error 用了很久的Android Studio2.2,不知不觉Android Studio已经到了2.4版本了。Android Studio更新完成后,进入module提...
写这个的来源:公司需要现在透明状态栏,状态栏颜色随着页面切换而改变,虚拟键盘不变!OK,拿到这个需求的时候,so easy !打开github!搜索statusbar,选了这...
自定义EditText的光标颜色,需要在EditText的XML代码中加入如下一条属性: 其中的参数如果为@null,则光标颜色与字体颜色相同,宽度为最窄。而要实现自己自定义...
大家好,我是森森 上节课我们把应用程序的界面完成了,这节课就要真正的把数据给它存储起来了. 昨天开会,公司把人按重要程度给每个人标了个颜色,我的颜色和休产假的一样,看来我得少...
surface,这个单词的意思是浮在表面的,那么surfaceview就是浮在表面的view了。如果真的这样解释,估计有人要拍砖了。然而,话虽不能这么说,取这个名儿,多少还是...8049人阅读
JAVA(35)
Shiro(7)
Apache Shiro Realms
Realm 是可以访问程序特定的安全数据如用户、角色、权限等的一个组件。Realm会将这些程序特定的安全数据转换成一种shiro可以理解的形式,shiro就可以依次提供容易理解的Subject程序API而不管有多少数据源或者程序中你的数据如何组织。
Realm 通常和数据源如数据库、LDAP目录、文件系统或者其它类似的数据源是一对一的关系,所以,可以用数据源相应的API如JDBC、File
IO、 Hibernate 或者JPA以及其它的API来实现Realm接口,从而获取授权的相关数据(角色、权限等)。
realm本质上就是一个指定安全的DAO。
因为大部分这类数据源通常都会同时存储认证数据(如密码)和授权数据(如角色和权限),所以每一个Shiro Realm都可以同时执行认证和授权操作。
Realm Configuration
如果使用shiro的ini配置文件,你可以在[main]区域内像配置其它对象一样定义和引用Realms,但是Realm在secrityManager上的配置有两种方式:明确方式和隐含方式。
在迄今所知的INI配置文件的相关知识中,这是一种显示的配置方式。在定义一个或多个Realm后,再将它们在securityManager上进行统一配置。
fooRealm = pany.foo.Realm
barRealm = pany.another.Realm
bazRealm = pany.baz.Realm
securityManager.realms = $fooRealm, $barRealm, $bazRealm
明确设置是确定性的,你可以非常确切地知道哪个realm在使用并且知道它们执行的顺序。可以查看认证章节的Authentication Sequence
了解Realm的执行顺序的影响效果。
不明确指定
不是首选的
不明确指定时,如果你改变了realm定义时的顺序可能引起未可知的动作,建议你避免使用这种方式而使用明确指定的方式,不明确指定将来会从shiro的版本中去除。
如果你真的有理由不想明确配置securityManager.realms属性,你可以让Shiro自行去发现所有配置的realm并且直接将它们指定给securityManager。
使用这种方法,realm按照定义的顺序指定给securityManager实例。
也就是说,对于下面shiro.ini的例子:
blahRealm = pany.blah.Realm
fooRealm = pany.foo.Realm
barRealm = pany.another.Realm
# no securityManager.realms assignment here
本质上和加上下面这行效果相同:
securityManager.realms = $blahRealm, $fooRealm, $barRealm
然而,要明白使用不明确的指定方法,realm定义的顺序直接影响其在验证和授权尝试中执行的顺序,如果你改变了定义顺序,你必须改变Authenticator的验证序列函数。
因此,为了确保行为的确定性,我们建议使用明确指定的方式代替不明确的指定方式。
一旦理解了shiro主要的认证流程,你应该知道非常重要的一点:尝试进行认证时Realm和Authenticator之间究竟发生了什么。
支持AuthenticationTokens
正如在验证序列中提到的,在一个realm执行一个验证尝试之前,它的“支持”方法被调用。只有在返回值为true的时候它的getAuthenticationInfo(token)
方法才会执行。
通常情况下,一个realm将检查提交的令牌类型(接口或类)确定自己是否可以处理它,例如,一个处理生物特性数据的Realm可能一点也不理解UsernamePasswordTokens,在这种情况下它将从支持函数中返回false。
处理支持的验证令牌
如果一个Realm支持提交的验证令牌,验证将调用Realm的getAuthenticationInfo(token)方法,这是Realm使用后台数据进行验证的一次有效尝试,顺序执行以下动作:
1.检查主要身份令牌(用户身份信息);
2.基于主要信息,在数据源中查找对应的用户数据;
3.确定令牌支持的凭证数据和存储的数据相符;
4.如果凭证相符,返回一个AuthenticationInfo实例,里面封装了Shiro可以理解的用户数据。
5.如果证据不符,抛出AuthenticationException
这是所有Realm getAuthenticationInfo 实现的最高级别工作流,Realm在这个过程中可以自由做自己想做的事情,比如记录日志,修改数据,以及其他,只要对于存储的数据和验证尝试来讲是合理的就行。
仅有一件事情是必须的,如果证据和给定的主要信息匹配,需要返回一个非空的AuthenticationInfo实例,用来表示来自数据源的用户信息。
直接实现Realm接口也许需要时间并容易出错,大部分用户选择继承AuthorizingRealm虚拟类,这个类实现了常用的验证和授权工作流,这会节省你的时间而且不易出错。
在上述realm验证工作流中,一个Realm必须较验Subject提交的凭证(如密码)是否与存储在数据中的证书相匹配,如果匹配,验证成功,系统保留已证实的终端用户身份。
Realm凭证匹配
检查提交的凭证是否与后台存储数据相匹配是每一个Realm的责任而不是Authenticator的责任,每一个Realm都具备与凭证形式及存储密切相关的技能,可以执行详细的证明比对,而Authenticator只是一个普通的工作流组件。
凭证匹配的过程在所有程序中基本上是一样的,通常只是对比数据方式不同。要确保这个过程在必要时是可插拔和可定制的,AuthenticatingRealm以及它的子类支持用CredentialsMatcher来执行一个凭证对比。
在找到用户数据之后,它和提交的 AuthenticationToken一起传递给一个 CredentialsMatcher
,后者用来检查提交的数据和存储的数据是否相匹配。
Shiro某些CredentialsMatcher实现可以使你开始out of the box,比如 SimpleCredentialsMatcher和HashedCredentialsMatcher实现,但如果你想配置一个自定义的实现来完成特定的对比逻辑,你可以这样做:
Realm myRealm = pany.shiro.realm.MyRealm();
CredentialsMatcher customMatcher = pany.shiro.realm.CustomCredentialsMatcher();
myRealm.setCredentialsMatcher(customMatcher);
或者,使用Shiro的INI配置文件
customMatcher = pany.shiro.realm.CustomCredentialsMatcher
myRealm = pany.shiro.realm.MyRealm
myRealm.credentialsMatcher = $customMatcher
简单证明匹配
所有Shiro的out-of-the-box Realm默认使用一个 SimpleCredentialsMatcher(简单证明匹配), SimpleCredentialsMatcher对存储的用户凭证和从AuthenticationToken提交的用户凭证直接执行相等的检查。
例如,如果提交了一个UsernamePasswordToken,SimpleCredentialsMatcher检查提交的密码与存储的密码是否完全相等。
SimpleCredentialsMatcher 不仅仅对字符串执行相同对比,它可以对大多数常用类型,如字符串、字符数组、字节数组、文件和输入流等执行对比,查看JavaDoc获取更多的信息。
Hashing凭证:
取代将凭证按它们原始形式存储并执行原始数据的对比,存储终端用户的凭证(如密码)更安全的办法是在存储数据之前,先进行hash运算。
这确保终端用户的凭证不会以他们原始的形式存储,没有人能知道其原始值。与明文原始比较相比这是一种更为安全的做法,有安全意识的程序会更喜欢这种方法。
要支持这种加密的hash策略,Shiro为Realm配置提供了一个HashedCredentialsMatcher实现替代之前的
SimpleCredentialsMatcher。
Hashing 凭证以及hash迭代的好处超出了该Realm文档的范围,可以在HashedCredentialsMatcher JavaDoc更详细地了解这些主要内容。
Hashing以及相符合的匹配
对于一个使用Shiro的程序,如何配置才能简单地做到这些?
Shiro提供了多个HashedCredentialsMatcher子类实现,你必须在你的Realm上配置指定的实现来匹配你的凭证所使用的hash算法。
例发,假设你的程序使用用户名/密码对来进行验证,基于上述hash凭证的好处,你希望当创建用户时以SHA-265方式加密用户的密码,你可以加密用户输入的明文密码并保存加密值:
import org.apache.shiro.crypto.hash.Sha256H
import org.apache.shiro.crypto.RandomNumberG
import org.apache.shiro.crypto.SecureRandomNumberG
//We'll use a Random Number Generator to generate salts.&
//is much more secure than using a username as a salt or not
//having a salt at all.&
Shiro makes this easy.
//Note that a normal app would reference an attribute rather
//than create a new RNG every time:
RandomNumberGenerator rng = new SecureRandomNumberGenerator();
Object salt = rng.nextBytes();
//Now hash the plain-text password with the random salt and multiple
//iterations and then Base64-encode the value (requires less space than Hex):
String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, 1024).toBase64();
User user = new User(username, hashedPasswordBase64);
//save the salt with the new account.&
The HashedCredentialsMatcher
//will need it later when handling login attempts:
user.setPasswordSalt(salt);
userDAO.create(user);
由于你使用SHA-256加密你的密码,你需要告诉Shiro使用相应的 HashedCredentialsMatcher来检查你的hashing值,在这个例子中,我们为了加强安全创建了一个随机的salt并且执行1024
Hash迭代(查看HashedCredentialsMatcher JAVADoc了解为什么),下面的Shiro INI
配置来做这件工作。
credentialsMatcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
# base64 encoding, not hex in this example:
credentialsMatcher.storedCredentialsHexEncoded = false
credentialsMatcher.hashIterations = 1024
# This next property is only needed in Shiro 1.0.&
Remove it in 1.1 and later:
credentialsMatcher.hashSalted = true
myRealm = pany.....
myRealm.credentialsMatcher = $credentialsMatcher
SaltedAuthenticationInfo
确保正常运行的最后一件要做的事情是你的Realm实现必须返回一个 SaltedAuthenticationInfo
实例而不是普通的AuthenticationInfo,SaltedAuthenticationInfo
接口确保你在创建用户帐户时使用的salt(如上面调用的 user.setPasswordSalt(salt);)能被HashedCredentialsMatcher引用。
HashedCredentialsMatcher需要使用salt来对提交的AuthenticationToken执行相同的hashing技术来对比提交的令牌是否与存储的数据相匹配,所以如果你对用户密码使用salting(你应该这么做),确保你的Realm实现在返回SaltedAuthenticationInfo
实例时引用它。
如果有理由,你不希望某个Realm对某个资源执行验证(或者因为你只想Realm去执行授权检查),你可以完全禁用Realm的验证支持,方法就是在Realm的支持方法中始终返回False,这样,你的realm将在整个验证过程中不再被使用。
当然如果你想验证Subject,至少要配置一个支持AuthenticationTokens
Realm 授权
原文地址:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:392668次
积分:4330
积分:4330
排名:第6053名
原创:64篇
转载:35篇
评论:49条
阅读:42135
(1)(2)(2)(6)(3)(1)(1)(1)(1)(1)(2)(1)(5)(11)(1)(1)(1)(3)(4)(2)(3)(2)(1)(3)(1)(1)(2)(2)(7)(4)(2)(2)(1)(3)(6)(10)(2)(6)(2)(2)(2)(6)多平台阅读
《财富》书签(Weekly Read)专栏专门刊载《财富》杂志(Fortune)编辑团队的书评,解读商界及其他领域的新书。我们每周都会选登一篇新的评论。
电力、大型制药公司和工业革命是我们缺乏睡眠的罪魁祸首。爱迪生发明的那个讨厌的电光源搞乱了我们的昼夜节律,以及调节睡眠和许多其他基因功能的激素周期。
《梦境》(Dreamland)一书探讨的是我们无意识的时刻。作者大卫o兰德尔开篇首先叙述了自己梦游经历的开始。一天夜晚,作者醒来时发现自己躺在其布鲁克林公寓的走廊里,双手正紧握着一只伤腿。这是他的首次梦游经历,很明显(他也记不清楚是怎么回事),他对方向的把控不够熟练,进而撞到了腿。他去医院看病,尔后在一个睡眠实验室呆了一宿,不料却被医生告知这次短途之旅的原因还不清楚,无法给他推荐可靠的治疗之策。兰德尔非常惊讶地发现我们对这一领域的认识如此贫瘠,于是展开了调查,这本书就是他调查的成果。
开篇讲述自身梦游经历是非常自然的事情,但对像我这样偶尔失眠、以及其他有睡眠问题的人来说,他的不幸遭遇并没有什么让人印象深刻的地方。他的腿受了点轻伤?而且只有一次?这算什么大不了的睡眠事故啊!我想这个兰德尔肯定是个年轻人,书中使用的作者照片似乎证明了这一点【他是路透社(Reuters)的资深记者,《梦境》是他的处女作】“睡眠并不是我们在21世纪头些年应该担忧的事情,”他若有所思地写道。他还说:“在我们大多数人的生活中,睡眠的重要性可能跟使用牙线的重要程度差不多。”
果真如此吗?我认识的那些不堪生活重压的中年人常常受到睡眠不足的困扰,他们大量服用安眠药,花费数千美元购买花哨的床垫。睡眠不足这个问题几乎跟子女和房子一样,让我们发表了无数单调乏味的长篇大论。对睡眠问题这么高的关注度使得兰德尔这本书备受瞩目——也由此具有非常好的销售前景。
在这个奇怪的开篇之后,《梦境:探究陌生的睡眠科学》(Dreamland: Adventures in the Strange Science of Sleep)随即以详实的内容对那些个让人苦恼的8小时进行了引人入胜的探索。我们的问题出在什么地方?大背景是:工业革命和托马斯o爱迪生发明的那个讨厌的电光源搞乱了我们的昼夜节律,以及调节睡眠和许多其他基因功能的激素周期。
大脑中那个微小的、似乎依然处于爬行类动物阶段的松果体也难辞其咎。当它感觉到被延长的黑暗时,它就会产生出诱导睡眠的褪黑激素。然而,兰德尔解释称:“充分的白光,特别是带着一丝蓝色调,宛若蓝天的白光能够诱使松果体误以为依然艳阳高照。”这意味着,正躺在床上使用个人电脑,观看电视或用iPad看电影的你(没错,就是你),正在摁下作者所说的“反向嗜睡按钮”。
这些因素有助于解释为什么每7个美国人中就有1位有长期的睡眠障碍问题。此外还有一些人有短期的睡眠问题:“每天晚上,大约五分之二的美国成年人都难以入睡或无法持续睡眠,”兰德尔写道。他在书中提及一个由此产生的、在私营部门、特别是美军中迅速兴起的领域:“疲劳管理”。由于兰德尔堆积了太多睡眠不足的士兵和水手犯下致命错误的故事,这本书写到这里时似乎陷入了停顿。他随后做了一个令人大开眼界的预测:到2020年,所有美军士兵都将在手腕上带上睡眠监控器。兰德尔在书中写道:“只需点击几下鼠标,一位指挥官就可以了解他麾下的每位士兵究竟睡了多长时间,并由此确定他或她可能会作出的决策。”
作者在最令人震惊的(没有双关语意)一章中追溯了安眠药的历史,而且差点对大型制药公司的“嗜睡欺诈”行为进行了指责。仅在美国,这些有力的小药丸就是一门价值300亿美元的生意(2010年数据),比全球人口每年去电影院的花费还稍稍高一些。他指出,在2010年,四分之一美国成年人的药品柜中放有医生开的安眠药。然而,“许多研究显示,类似安必恩(Ambien)和鲁尼斯塔(Lunesta)这样的安眠药并没有显著改善睡眠质量,对于睡眠数量的改善也仅仅是稍好一点而已,”兰德尔写道。
David K. Randall beginsDreamland, his look at our unconscious hours, by recounting the start of his own Z-journey. The author awakes one night lying in the hallway of his Brooklyn apartment, clutching a wounded leg. He'd sleepwalked for the first time and apparently -- he couldn't remember a thing -- his steering wasn't skillful enough to avoid a leg-on collision. He sees a doctor, then stays overnight in a sleep lab, only to be told that the causes of his jaunt are unclear and no treatments can reliably be recommended. Amazed at how little we know for certain in this realm, Randall investigates, and this book is the result.
It's a natural place to begin, but to this occasional insomniac and, I suspect, others with sleep problems, his misadventure does not impress. He got a boo-boo on his leg? Once? Big sleeping deal. This Randall must be a younger man, I thought, and his author photo seems to bear that out. (He's a senior reporter for Reuters, and Dreamland is his first book.) "Sleep wasn't something that we were supposed to worry about in the first years of the twenty-first century,'' he muses, adding that "the importance of sleep likely hovers somewhere near that of flossing in most of our lives.''
Really? The stressed-out middle-agers I know are obsessed with the sleep they're not getting, gobbling Lunesta, and spending thousands on fancy mattresses. Our monologues about (lack of) sleep are almost as tedious as our riffs on children and real estate. This preoccupation is what makes Randall's book such a compelling -- and marketable -- idea.
After this curious opening gambit, Dreamland, subtitled Adventures in the Strange Science of Sleep, turns out to be an engaging, well-reported exploration of those fraught eight hours. What's our problem? Big picture: the Industrial Revolution and Thomas Edison's pesky electric light screwed up our circadian rhythms, the natural, hormonal cycles that regulate sleep and many other genetic functions.
The brain's tiny and still-a-bit-too-reptilian pineal gland is also to blame. It produces sleep-inducing melatonin when it senses prolonged darkness. However, Randall explains, "abundant white light -- especially white with a slight blue tint that mimics the sky -- can fool the pineal gland into thinking that the sun is still up.'' That means you over there -- yes, you -- clutching that laptop in bed, or watching the tube, or catching a movie on your iPad -- are pushing what the author calls "reverse snooze buttons.''
These factors help explain why one out of every seven Americans has a long-term sleep disorder. Then there are the short-termers: "Every night, about two of every five adults in the United States have problems falling asleep and staying asleep,'' Randall writes. He describes the resulting, burgeoning field of "fatigue management,'' in the private sector and especially in the U.S. military. Here the story bogs down a bit as Randall piles on too many examples of sleep-deprived soldiers and sailors making fatal errors. He then makes the eye-opening prediction that by 2020 all U.S. soldiers will wear sleep monitors on their wrists: "With a few clicks of a mouse, a commander will know how many hours each person in the unit has slept -- and, by extension, what kind of decisions he or she will likely make.''
In the most alarming (no pun intended) chapter, the author traces the history of sleeping pills and comes close to accusing Big Pharma of somnolence fraud. Those potent little pills were a $30 billion business in 2010 in the U.S. alone, or slightly more than the global population spends going to the movies every year. In 2010, he notes, a quarter of U.S. adults had prescription sleeping pills in their medicine cabinets. And yet, Randall writes, "a number of studies have shown that drugs like Ambien and Lunesta offer no significant improvement in the quality of sleep … They give only a tiny bit more in the quantity department, too.''
最新文章:
中国煤业大迁徙
500强情报中心
500强国家分布 500强行业分布}

我要回帖

更多关于 realm swift3 使用 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信