周恒超
骑士
骑士
  • UID146
  • 粉丝1
  • 关注1
  • 发帖数15
  • 社区居民
阅读:9146回复:3

平台如何实现不经过登录进入登录后页面?

楼主#
更多 发布于:2016-10-24 14:03
实际场景,例如在一个门户网站中挂一个链接,点击链接后不经过登录页面,直接跳转到登录后的页面中如何实现?
刘魁
管理员
管理员
  • UID62
  • 粉丝1
  • 关注0
  • 发帖数23
  • 社区居民
沙发#
发布于:2016-10-25 09:00
两种方法:
1.将你要访问的页面设置成不需要登录的,在page.xml中配置成不需要登录
<page view-id="/main2.xhtml" login-required="false"/>

2.可以采取用Servlet直接登录,再跳转到你想访问的页面
hpackage com.sunsheen.jfids.dsi.sysman.security.login;
 
import java.io.IOException;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.jboss.seam.security.Identity;
 
import com.sunsheen.jfids.system.servlet.Servlet;
 
@Servlet(value = "/data/Login.svt", anonymous = true)
public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Identity identity = Identity.instance();
        identity.getCredentials().setPassword(request.getParameter("password"));
        identity.getCredentials().setUsername(request.getParameter("username"));
        identity.login();
        response.sendRedirect("../main.xhtml");
    }
 
    public void doPost(HttpServletRequest req, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(req, response);
    }
}
周恒超
骑士
骑士
  • UID146
  • 粉丝1
  • 关注1
  • 发帖数15
  • 社区居民
板凳#
发布于:2016-10-27 09:08
@刘魁
按照第二种方式,使用servlet直接登录,后台报错,09:13:34,771 INFO  [STDOUT] 16-10-27 09:13:34,770 WARN  [org.jboss.seam.security.jaas.SeamLoginModule] - Error invoking login method
javax.el.ELException: java.lang.NullPointerException
 at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
 at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
 at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
 at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
 at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
 at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175)
 at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:109)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:483)
 at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
 at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
 at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
 at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
 at java.security.AccessController.doPrivileged(Native Method)
 at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
 at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
 at org.jboss.seam.security.Identity.authenticate(Identity.java:344)
 at org.jboss.seam.security.Identity.authenticate(Identity.java:332)
 at org.jboss.seam.security.Identity.login(Identity.java:259)
 at com.sunsheen.system.sysman.userMan.userPower.CustomLoginServlet.doGet(CustomLoginServlet.java:24)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at com.sunsheen.jfids.system.servlet.SystemPageFilter.a(Unknown Source)
 at com.sunsheen.jfids.system.servlet.SystemPageFilter.doFilter(Unknown Source)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:82)
 at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:70)
 at org.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
 at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
 at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:44)
 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:70)
 at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:61)
 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:70)
 at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:70)
 at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:70)
 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:66)
 at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:159)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at com.sunsheen.jfids.system.init.ResourceSecurityFilter.doFilter(ResourceSecurityFilter.java:47)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
 at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
 at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
 at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
 at com.sunsheen.jfids.dsi.sysman.security.login.LoginImpl.doLogin(LoginImpl.java:112)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:483)
 at org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationInvoker.invoke(JavaImplementationInvoker.java:156)
 at org.apache.tuscany.sca.binding.sca.impl.SCABindingInvoker.invoke(SCABindingInvoker.java:61)
 at org.apache.tuscany.sca.core.invocation.JDKInvocationHandler.invoke(JDKInvocationHandler.java:349)
 at org.apache.tuscany.sca.core.invocation.JDKInvocationHandler.invoke(JDKInvocationHandler.java:193)
 at com.sun.proxy.$Proxy148.doLogin(Unknown Source)
 at com.sunsheen.jfids.system.security.login.SystemLoginAction.login(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:483)
 at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
 at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
 at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
 at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
 at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
 at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
 at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
 at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
 at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
 at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
 at com.sunsheen.jfids.sy
09:13:34,771 INFO  [STDOUT] stem.security.login.SystemLoginAction_$$_javassist_seam_59.login(SystemLoginAction_$$_javassist_seam_59.java)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:483)
 at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
 ... 64 more
[周恒超于2016-10-27 12:59编辑了帖子]
周恒超
骑士
骑士
  • UID146
  • 粉丝1
  • 关注1
  • 发帖数15
  • 社区居民
地板#
发布于:2016-10-28 16:37
刘魁:两种方法:
1.将你要访问的页面设置成不需要登录的,在page.xml中配置成不需要登录
<page view-id="/main2.xhtml" login-required="false"/>
2.可以采取用Servl...
回到原帖
可以了,谢谢魁哥。
游客

返回顶部