在我的Java应用程序中,我声明了以下restful类
@Path("userProfile")
@Stateless
public class UserProfileRestful {
@Resource
private SessionContext sessionContext;
@Path("userName")
@GET
@Produces(MediaType.Text_Palin)
public String findCurrentUserName(){
return sessionContext.getCallerPrincipal.getName();
}
}通过任何客户端获取当前登录用户的用户名。
在我用用户名"myuser“登录后,我在一个新的选项卡中将下面的url粘贴到web浏览器上
http://localhost:8080/MyApp/rest/userProfile/userName显示的响应与预期的一样:"myuser“。
现在,我尝试从另一个ExtJS应用程序(不需要身份验证)中获得这个用户名,执行Ajax请求如下:
Ext.Ajax.Request({
url : "http://localhost:8080/MyApp/rest/userProfile/userName",
success : function(response,options){
alert('username : ' + response.responseText);
},
failure : function(){
alert('request failed');
}
});警告的结果是“匿名”,尽管在同一会话中我仍然以"myuser“的身份登录。
那么,为什么调用方主体在第二种情况下会发生变化,并且有解决方案吗?
发布于 2014-08-27 16:05:19
好吧,完成了..。
我的想法是
sessionContext.getCallerPrincipal.getName()取决于调用方(客户端)的上下文,实际上它运行的是哪个应用服务器。
我的ExtJS应用程序(客户端)首先运行在Jitty服务器上,而Java应用程序(服务器端)运行在GlassFish上。
两个不同的应用服务器,因此两个不同的上下文就是问题所在。
Clearly...after我在玻璃鱼上部署了这两个应用程序,一切都很顺利。
https://stackoverflow.com/questions/25522758
复制相似问题