Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ApacheCamel-调用http或rest调用(通过Shiro安全性过滤)_Rest_Apache Camel_Shiro - Fatal编程技术网

ApacheCamel-调用http或rest调用(通过Shiro安全性过滤)

ApacheCamel-调用http或rest调用(通过Shiro安全性过滤),rest,apache-camel,shiro,Rest,Apache Camel,Shiro,需要一些建议,以确定是否可能在骆驼为以下场景 我们正在尝试使用ApacheCamel对web应用程序进行集成测试。必须通过rest服务调用访问应用程序。每个应用程序请求都通过shiro security进行过滤。当我对此应用程序进行restful调用或http调用时,我需要在头中设置必要的shiro身份验证信息,并确保成功处理了camel请求。在camel中有没有一种方法可以做到这一点——“调用http或rest调用来访问其请求由apacheshiro保护的应用程序”?我看到Camel有一个sh

需要一些建议,以确定是否可能在骆驼为以下场景

我们正在尝试使用ApacheCamel对web应用程序进行集成测试。必须通过rest服务调用访问应用程序。每个应用程序请求都通过shiro security进行过滤。当我对此应用程序进行restful调用或http调用时,我需要在头中设置必要的shiro身份验证信息,并确保成功处理了camel请求。在camel中有没有一种方法可以做到这一点——“调用http或rest调用来访问其请求由apacheshiro保护的应用程序”?我看到Camel有一个shiro安全组件,它更像是授权Camel路线或定义Camel路线的安全性,我看不出我可以将其用于此目的

我确实尝试过以不同的可能方式(例如:使用Exchange的身份验证属性)在标头中设置shiro身份验证令牌,但它不起作用。有什么建议吗

更新: Shiro维护自己的会话,并查找用户ID和他/她的权限(称为Shiro Subject),以确保它是经过身份验证和授权的请求。每当我们向Shiro安全应用程序发送请求时,它都会过滤请求,验证请求,以确定其是否有权访问应用程序功能,然后允许我们进入。如果用户信息在Shiro会话中不可用,则会将您带到登录屏幕。我们的web应用程序已经公开了rest服务的功能。在Camel中调用这样一个嵌入了ApacheShiro安全性的应用程序是否可行?基本上,我应该模拟Shiro主题,并将其设置在HTTP头中,使其看起来像一个Shiro认证的请求

我尝试使用exchange标头中设置的Shiro身份验证令牌进行http调用。但它失败了。这是可能的,还是我走错了方向?非常感谢您在这方面的任何建议或帮助。下面是我一直在玩的代码的子集

//用一个主题来概括它

Subject subjectUnderTest = new Subject.Builder(getSecurityManager())
        .principals(new SimplePrincipalCollection("Username", "RealmName")).authenticated(true).buildSubject();    

MockEndpoint OutEndpoint = getMockEndpoint("mock.out");

OutEndpoint.expectedMessageCount(1);

Endpoint InEndpoint = context.getEndpoint("direct.in");


Map<String, Object> headers = new HashMap<String, Object>();

headers.put(Exchange.HTTP_METHOD, "GET");

headers.put(Exchange.AUTHENTICATION, subjectUnderTest);

template.sendBodyAndHeaders(InEndpoint, "test body", headers);
Subject subjectiondertest=新建Subject.Builder(getSecurityManager())
.principals(新的SimplePrincipalCollection(“用户名”、“reallName”)).authenticated(true).buildSubject();
MockEndpoint OutEndpoint=getMockEndpoint(“mock.out”);
OutEndpoint.expectedMessageCount(1);
Endpoint InEndpoint=context.getEndpoint(“direct.in”);
Map headers=newhashmap();
headers.put(Exchange.HTTP_方法,“GET”);
headers.put(Exchange.AUTHENTICATION,subjectUnderTest);
模板。发送体和标题(InEndpoint,“测试体”,标题);

谢谢Viggy

我认为您应该使用下面的代码设置用户名和密码。使用这些配置设置上下文

HttpConfiguration config = new HttpConfiguration();
config.setAuthMethod(AuthMethod.Basic);
config.setAuthUsername("donald");
config.setAuthPassword("duck");
HttpComponent http = context.getComponent("http", HttpComponent.class);
http.setHttpConfiguration(config);

通常,您可以在Camel exchange上设置您喜欢的任何头,该头将作为HTTP头随请求一起发送。通过Shiro进行身份验证的确切要求是什么?我已经添加了我在应用程序中尝试执行的更新。