9 远程服务框架-安全管理

本文介绍了一个框架提供的远程组件调用安全保障措施,包括认证、鉴权和数据加密等功能。详细阐述了各安全模块的工作原理、配置方法及使用示例。

1.1    安全管理

安全管理

安全管理模块提供远程组件调用过程中的安全保障措施包括:认证,鉴权,数据加密。系统提供的安全模块是可插拔的,以插件方式引入认证,鉴权,加解密模块。系统提供了默认的插件为:

org.frameworkset.spi.security.SimpleLoginModule

org.frameworkset.spi.security.SimpleAuthorityModule

org.frameworkset.spi.security.SimpleEncryptModule

 

需要引入缺省的默认配置用户角色-方法

这些插件配置在resources/org/frameworkset/spi/manager-rpc-service.xml文件中:

<property

name="system.securityManager"

singlable="true" class="org.frameworkset.spi.security.SecurityManagerImpl">

                     <construction>

                            <property name="securityconfig"

                                         refid="attr:rpc.security" />

                     </construction>     

              </property>

             

<property name="rpc.security" >

                     <map>

                            <property name="rpc.login.module"

 enable="true" class="org.frameworkset.spi.security.SimpleLoginModule"/>

                            <property name="rpc.authority.module"

enable="true" class="org.frameworkset.spi.security.SimpleAuthorityModule"/>

                            <property name="data.encrypt.module"

 enable="true" class="org.frameworkset.spi.security.SimpleEncryptModule"/>

                     </map>

              </property>

 

 

 

1.1.1   认证

Ø         配置认证插件

Aop框架提供的远程服务调用可以启用用户认证功能,用户认证模块以插件的方式配置在远程服务配置文件/bbossaop/resources/org/frameworkset/spi/manager-rpc-service.xml文件中:

<property name="rpc.login.module" enable="true" class="org.frameworkset.spi.remote.security.SimpleLoginModule"/>

org.frameworkset.spi.remote.security. SimpleLoginModule类只需实现接口:

org.frameworkset.spi.remote.security.LoginModule即可,接口只有一个方法

public boolean checkUser(SecurityContext context)

throws SecurityException;

应用可以通过enable属性来控制是否启用认证,enable=true时需要认证,enable=false禁用认证

 

Ø         认证流程

认证操作在服务器端执行,客服端传递用户凭证信息(账号和口令)即可,认证通过继续服务调用,否则拒绝服务调用方法返回false,并向客服端返回认证失败异常。

 

Ø         认证异常处理

认证过程中出现异常时全部以SecurityException异常抛出,系统检测到SecurityException异常时,以认证失败处理,拒绝服务调用,并且将异常返回给客服端

 

Ø         使用实例

如果aop框架中启用了认证模式,则需要在调用的服务url中添加用户账号和口令信息:

user---账号参数

password------口令参数

系统提供了两个常量,分别对应于传递账号信息的参数名称:

org.frameworkset.spi.security.SecurityManager.USER_ACCOUNT_KEY

org.frameworkset.spi.security.SecurityManager.USER_PASSWORD_KEY

例如:

(mina::172.16.17.216:12347)/test.security.bean?user=admin&password=123456,其中的账号为admin,密码为123456

 

@Test

    public void testMinaSecurityBean()

    {

        BussinessBeanInf beaninf = (BussinessBeanInf)BaseSPIManager.getBeanObject("(mina::172.16.17.216:12347)/test.security.bean?user=admin&password=123456");

        System.out.println("testMinaSecurityBean beaninf.getCount():"+beaninf.getCount());

        System.out.println("testMinaSecurityBean beaninf.printMessage(message):"+beaninf.printMessage("test.security.bean"));

    }

   

    @Test

    public void testJmsSecurityBean()

    {

        BussinessBeanInf beaninf = (BussinessBeanInf)BaseSPIManager.getBeanObject("(jms::yinbiaoping-jms)/test.security.bean?user=admin&password=123456");

        System.out.println("testJmsSecurityBean beaninf.getCount():"+beaninf.getCount());

        System.out.println("testJmsSecurityBean beaninf.printMessage(message):"+beaninf.printMessage("test.security.bean"));

    }

   

    @Test

    public void testJGroupSecurityBean()

    {

        BussinessBeanInf beaninf = (BussinessBeanInf)BaseSPIManager.getBeanObject("(jgroup::172.16.17.216:1186)/test.security.bean?user=admin&password=123456");

        System.out.println("testJGroupSecurityBean beaninf.getCount():"+beaninf.getCount());

        System.out.println("testJGroupSecurityBean beaninf.printMessage(message):"+beaninf.printMessage("test.security.bean"));

    }

   

    @Test

    public void testWebServiceSecurityBean()

    {

        BussinessBeanInf beaninf = (BussinessBeanInf)BaseSPIManager.getBeanObject("(webservice::http://172.16.17.216:8080/WebRoot/cxfservices)/test.security.bean?user=admin&password=123456");

        System.out.println("testJGroupSecurityBean beaninf.getCount():"+beaninf.getCount());

        System.out.println("testJGroupSecurityBean beaninf.printMessage(message):"+beaninf.printMessage("test.security.bean"));

    }

   

   

    @Test

    public void testMuticallSecurityBean()

    {

        BussinessBeanInf beaninf = (BussinessBeanInf)BaseSPIManager.getBeanObject("(mina::172.16.17.216:12346)/test.security.bean?user=admin&password=123456");

        System.out.println("testMuticallSecurityBean beaninf.getCount():"+beaninf.getCount());

        System.out.println("testMuticallSecurityBean beaninf.printMessage(message):"+beaninf.printMessage("test.security.bean"));

}

 

 

1.1.2   鉴权

Ø         配置鉴权插件

Aop框架提供的远程服务调用可以启用用户鉴权功能,鉴权模块以插件的方式配置在远程服务配置文件/bbossaop/resources/org/frameworkset/spi/manager-rpc-service.xml文件中:

<property name="rpc.authority.module" enable="false" class="org.frameworkset.spi.remote.security.SimpleAuthorityModule"/>

             

      

org.frameworkset.spi.remote.security. SimpleAuthorityModule类只需实现接口:

org.frameworkset.spi.remote.security.AuthorityModule即可,接口只有一个方法

public boolean checkPermission(SecurityContext context)  throws SecurityException;

应用可以通过enable属性来控制是否启用鉴权功能,enable=true时需要鉴权,enable=false禁用鉴权。

 

启用鉴权功能的前提是系统必需先启用认证功能。

 

Ø         鉴权流程

服务调用端经过系统认证后,如果启用了鉴权功能,则进入鉴权操作,鉴权模块检测用户是否有执行服务调用的权限,如果有则运行执行服务调用,否则拒绝服务调用。服务调用被拒绝时,方法返回falseaop框架将返回拒绝访问异常SecurityException给调用端

 

Ø         鉴权异常处理

鉴权过程中出现的所有异常系统都包装为SecurityException异常返回给客服端。

Ø         使用实例

通过权限认证后,就可以在组件方法中使用:

SecurityContext securityContext

= SecurityContext.getSecurityContext();

securityContext包含用户账号信息和口令信息,以及操作的方法的签名信息。

1.1.3   /解密

系统支持调用端对远程调用请求消息加密,服务端对消息进行解密,防止信息在传输的过程中被窃取,保证数据安全性。支持多种加密算法:AES Advanced Encryption Standard)等。

Ø         加密解密流程

 

加解密流程

Ø         使用实例

加密插件必须实现org.frameworkset.spi.security. EncryptModule接口,加密插件配置在/bbossaop/resources/org/frameworkset/spi/manager-rpc-service.xml文件中。

n         简单的配置方法

<property name="data.encrypt.module"

 enable="true" class="org.frameworkset.spi.security.SimpleEncryptModule"/>

采用这种配置时,默认的加密算法为:MD5DES,加密口令为123456Security ProviderSunJCE

n         构造函数注入配置方法

<property name="data.encrypt.module"

 enable="true" class="org.frameworkset.spi.security.SimpleEncryptModule">

<construction>   

           <property name=”algorithmvalue="PBEWithMD5AndDES"/>

           <property name="password" value=”123456”/>

           <property name="provider"

value="SunJCE"/>

       </construction>

</property>

采用这种配置方式,用户可以指定相关的加密算法- algorithmpasswordprovider,具体指定的范围参考另外的开源加密框架:

JASYPT: Java Simplified Encryption

 ----------------------------------

 

 Jasypt (Java Simplified Encryption) is a java library which allows the

 developer to add basic encryption capabilities to his/her projects with

 minimum effort, and without the need of having deep knowledge on how

 cryptography works.

http://www.jasypt.org

Enable属性决定是否对数据进行加密,框架根据该属性对客服端的请求消息进行加密,然后传输到服务器端,服务器端自动对加密的消息进行解密。服务器端根据该属性对响应消息进行加密,然后将加密消息返回给客服端,客户端自动对加密的响应消息进行解密。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值