NutzCN Logo
问答 兽董,请问nutz集成shiro后,怎么做到动态跳转到不同的登录页面
发布于 3043天前 作者 qq_8af2c940 2043 次浏览 复制 上一个帖子 下一个帖子
标签:

需求是当用户没有登录状态,发送请求重定向到登录页面,登录页面不唯一,根据请求地址决定

10 回复

@wendal
配置了

authc = org.nutz.integration.shiro.SimpleAuthenticationFilter
authc.loginUrl = /demo/login

入口方法注解了@RequiresUser
重写了FormAuthenticationFilter中的onAccessDenied(),但是拦截不到,请求后先跳转了/user/login
并没有配置/user/login,这是nutz默认的吗

配了新的authc,还会走老的FormAuthenticationFilter吗?!

是shiro默认的URI

onAccessDenied 只是登陆失败时才走的吧??

如果快到入口方法就重定向了,那是NutShiroProcessor做的跳转, 可以通过NutShiro类的属性配置,或者覆盖这个类.

@wendal

#authc = org.nutz.integration.shiro.SimpleAuthenticationFilter
#authc.loginUrl = /console/login
#logout.redirectUrl = /console/login

[filters]
myForm = net.demo.common.shiro.filter.MyFormAuthenticationFilter

[urls]
/* = anon
/user/** = myForm
public class MyFormAuthenticationFilter extends FormAuthenticationFilter{

	@Override
	protected boolean onAccessDenied(ServletRequest request,
			ServletResponse response, Object mappedValue) throws Exception {
		System.out.println("MyFormAuthenticationFilter-------------onAccessDenied");
		HttpServletRequest httpReq = (HttpServletRequest) request;
		System.out.println("isAccessAllowed-url:"+httpReq.getRequestURL());
		return false;
	}
	
}

这样不走authc,请求后还是先跳转了/user/login再进入onAccessDenied()的

@qq_8af2c940 贴日志

来自炫酷的 NutzCN

2016-08-24 11:07:50,670 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92) DEBUG - Found mapping for [GET] path=/jingwang/user/addOrder/lvb : CourseModule.commitCourseOrder(CourseModule.java:104)
2016-08-24 11:07:50,673 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'courseModule'<class net.eluxue.modules.controllers.web.CourseModule>
2016-08-24 11:07:50,674 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:178) DEBUG - 	 >> Load definition name=courseModule
2016-08-24 11:07:50,674 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(courseModule) in AnnotationIocLoader(packages=[net.eluxue])
2016-08-24 11:07:50,674 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:208) DEBUG - 	 >> Make...'courseModule'<class net.eluxue.modules.controllers.web.CourseModule>
2016-08-24 11:07:50,675 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class net.eluxue.modules.controllers.web.CourseModule without AOP
2016-08-24 11:07:50,675 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'courseModule' to [app] 
2016-08-24 11:07:50,676 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'courseLvbService'<class net.eluxue.modules.services.CourseLvbService>
2016-08-24 11:07:50,676 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:178) DEBUG - 	 >> Load definition name=courseLvbService
2016-08-24 11:07:50,676 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(courseLvbService) in AnnotationIocLoader(packages=[net.eluxue])
2016-08-24 11:07:50,676 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:208) DEBUG - 	 >> Make...'courseLvbService'<class net.eluxue.modules.services.CourseLvbService>
2016-08-24 11:07:50,677 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class net.eluxue.modules.services.CourseLvbService without AOP
2016-08-24 11:07:50,677 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'courseLvbService' to [app] 
2016-08-24 11:07:50,677 org.nutz.service.EntityService.<init>(EntityService.java:40) DEBUG - Get TypeParams for self : net.eluxue.modules.models.CourseLvb
2016-08-24 11:07:50,677 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<>
2016-08-24 11:07:50,677 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'courseVodService'<class net.eluxue.modules.services.CourseVodService>
2016-08-24 11:07:50,677 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:178) DEBUG - 	 >> Load definition name=courseVodService
2016-08-24 11:07:50,677 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(courseVodService) in AnnotationIocLoader(packages=[net.eluxue])
2016-08-24 11:07:50,678 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:208) DEBUG - 	 >> Make...'courseVodService'<class net.eluxue.modules.services.CourseVodService>
2016-08-24 11:07:50,678 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class net.eluxue.modules.services.CourseVodService without AOP
2016-08-24 11:07:50,678 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'courseVodService' to [app] 
2016-08-24 11:07:50,678 org.nutz.service.EntityService.<init>(EntityService.java:40) DEBUG - Get TypeParams for self : net.eluxue.modules.models.CourseVod
2016-08-24 11:07:50,678 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<>
2016-08-24 11:07:50,678 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'orderService'<class net.eluxue.modules.services.OrderService>
2016-08-24 11:07:50,678 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:178) DEBUG - 	 >> Load definition name=orderService
2016-08-24 11:07:50,678 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(orderService) in AnnotationIocLoader(packages=[net.eluxue])
2016-08-24 11:07:50,678 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:208) DEBUG - 	 >> Make...'orderService'<class net.eluxue.modules.services.OrderService>
2016-08-24 11:07:50,678 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class net.eluxue.modules.services.OrderService without AOP
2016-08-24 11:07:50,678 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'orderService' to [app] 
2016-08-24 11:07:50,679 org.nutz.service.EntityService.<init>(EntityService.java:40) DEBUG - Get TypeParams for self : net.eluxue.modules.models.Orders
2016-08-24 11:07:50,679 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<>
2016-08-24 11:07:50,679 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
MyFormAuthenticationFilter-------------onAccessDenied
isAccessAllowed-url:http://192.168.1.35/user/login

所以呢, 看NutShiroProcessor

@wendal 威武!已解决,谢谢了!

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