NutzCN Logo
问答 SecurityUtils.getSubject().getPrincipal()
发布于 2453天前 作者 bb3239 4276 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
SecurityUtils.getSubject().getPrincipal()

返回值为空是怎么回事?

19 回复

有可能,我是有一个静态页面登陆进去了,在这个页面上有一个菜单,点击弹出一个iframe,显示内容为另一个静态页面的内容

@wendal 是不是第二个静态页面也需要登录?这是不是属于跨域,我不太懂

如果是静态页面又怎么会涉及java代码呢?你是把html后缀当静态页面了?

@wendal 不是模板页面,是静态页面,这点我还是可以区分,从模板页面向后台请求数据

那怎么又提到跨域了? 有两个webapp?

@wendal 所以还请你帮忙分析一下

那你得回答我啊,到底有几个webapp

哪里调用SecurityUtils.getSubject().getPrincipal() 了?导致啥问题了?

@wendal 入口函数里调用,返回值为空

这是用iframe显示静态页面到控件中显示的代码

var content = '<iframe id="iframe_content" src="'+url2+ '" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';
        $('#div_tunnel').dialog({
            title:title,
            width:width,
            height:height,
            resizable:true,
            content:content,
            draggable:true,

这是ajax请求:

$.ajax({
				url:,   //粘贴省略
				index:index,
				username:username,
                note:note,
				success:function (data) {
                    Toast.success(data.msg);
                },
				error:function (data) {
                    Toast.error(data.msg);
                }
			});

这是后台入口函数:

@At
	@Ok("json")
	@RequiresAuthentication
	public Object submitA(@Param("..") Ope_app ope_app,@Param("index") int index,@Param("username")String username,@Param("note")String note) {
		try {
			Object curUser = SecurityUtils.getSubject().getPrincipal();

curUser 返回值为空

把submitA方法贴完整

@At
	@Ok("json")
	@RequiresAuthentication
	public Object submitA(@Param("..") Ope_app ope_app,@Param("index") int index,@Param("username")String username,@Param("note")String note) {
		try {
			Object curUser = SecurityUtils.getSubject().getPrincipal();
			return Result.success("system.success");
		}
		catch (Exception e){
			return Result.error("system.error");
		}
	}

无法获取用户信息,没法往下写了

@wendal 已经解决了,谢谢

方法标注@RequiresAuthentication, 应该是登录成功才能访问的, 改成这样试一下输出啥

		try {
			Object curUser = SecurityUtils.getSubject().getPrincipal();
                        System.out.println(">>"+curUser );
			return Result.success("system.success");
		}
		catch (Exception e){
			return Result.error("system.error");
		}

还有一种可能性是登录的问题

@wendal 的确是未登录,另外一个同事写的,没注意,在浏览器上保存了一个书签,点击书签直接就进去了,没有走登陆这一步,也没有保存密码自动登录

添加回复
请先登陆
回到顶部