【问题标题】:Enabling/Disabling Shiro Security - Apache Camel启用/禁用 Shiro 安全性 - Apache Camel
【发布时间】:2016-11-11 03:22:00
【问题描述】:

我正在使用 Apache Camel 路由,我想启用/禁用 Shiro 安全性。

这是路线(blueprint.xml):

<bean id="shiroPolicy" class="org.apache.camel.component.shiro.security.ShiroSecurityPolicy">
     <argument value="shiro.ini"/>
 </bean>

<route>
<from uri="bean:com.ngt.secured.ShiroSecurity?method=tokeninject(Exchange)"/>
                <policy ref="shiroPolicy">
                        <to uri="bean:com.ngt.secured.transform?method=addrip(Exchange)"/>
                         ...
                         some process..
                </policy>
</route>

这是令牌注入(ShiroSecurity.java):

public void tokeninject(Exchange exchange) throws Exception
           {
           ShiroSecurityToken shiroSecurityToken = new ShiroSecurityToken(login,password);
           TestShiroSecurityTokenInjector shiroSecurityTokenInjector = new     TestShiroSecurityTokenInjector(shiroSecurityToken, passPhrase);
           shiroSecurityTokenInjector.process(exchange);
}
private static class TestShiroSecurityTokenInjector extends ShiroSecurityTokenInjector {
                   public TestShiroSecurityTokenInjector(ShiroSecurityToken shiroSecurityToken, byte[] bytes)
                   {
                        super(shiroSecurityToken, bytes);
                   }

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setHeader("SHIRO_SECURITY_TOKEN", encrypt());
                        //exchange.getIn().setBody("Beatle Mania");
                    }
           }

在这种情况下,启用了安全性。如何禁用它?有设置开/关的选项吗?

【问题讨论】:

    标签: java security apache-camel shiro blueprint-osgi


    【解决方案1】:

    我在寻找解决我遇到的骆驼白问题的方法时偶然发现了这一点。希望回复不会太晚。

    在 apache camel 中没有设置 shiro 安全性的选项/属性。您也可以通过在路由设置中包含一个选项来实现此目的,如下所示,并在注入安全令牌时将 on/off 选项作为标头属性注入:

    <route>
    <from uri="bean:com.ngt.secured.ShiroSecurity?method=tokeninject(Exchange)"/>
    <choice>
        <when>
            <simple>${in.header.isSecured} == 'true'</simple>
            <policy ref="shiroPolicy">
                <to uri="bean:com.ngt.secured.transform?method=addrip(Exchange)"/>
                 ...
                 some process..
            </policy>
        </when>
        <otherwise>
            <to uri="bean:com.ngt.secured.transform?method=addrip(Exchange)"/>
             ...
             some process..
        </otherwise>
    </choice>            
    </route>
    
    public void process(Exchange exchange) throws Exception {
        exchange.getIn().setHeader("SHIRO_SECURITY_TOKEN", encrypt());
        exchange.getIn().setHeader("isSecured", Boolean.FALSE);
        //exchange.getIn().setBody("Beatle Mania");
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-14
      • 1970-01-01
      • 2011-03-23
      • 2011-11-27
      • 2012-07-15
      • 2014-04-27
      • 2013-09-15
      • 1970-01-01
      • 2019-03-30
      相关资源
      最近更新 更多