Advertisement
Guest User

Untitled

a guest
Feb 26th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <h:form id="formLogin" prependId="false">
  2. <center>
  3. <p:messages closable="true"/>
  4.  
  5. <p:panelGrid columns="2">
  6. <f:facet name="header">Login</f:facet>
  7.  
  8. <h:outputLabel for="username" value="Username:" />
  9. <p:inputText id="username" required="true" />
  10.  
  11. <h:outputLabel for="password" value="Password:" />
  12. <p:password id="password" required="true" feedback="false" />
  13.  
  14. <f:facet name="footer">
  15. <center>
  16. <p:commandButton value="Login" ajax="false" action="#{loginController.doLogin('login')}"/>
  17. </center>
  18. </f:facet>
  19.  
  20. </p:panelGrid>
  21. </center>
  22. </h:form>
  23.  
  24. public String doLogin(String path) throws ServletException, IOException
  25. {
  26. ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  27.  
  28. ServletRequest servletRequest = (ServletRequest)context.getRequest();
  29. RequestDispatcher dispatcher = servletRequest.getServletContext().getRequestDispatcher(path.startsWith("/") ? path : "/" + path);
  30. dispatcher.forward(servletRequest, (ServletResponse)context.getResponse());
  31.  
  32. FacesContext.getCurrentInstance().responseComplete();
  33.  
  34. return null;
  35. }
  36.  
  37. <http pattern="/resources/css/**" security="none"/>
  38. <http pattern="/resources/images/**" security="none"/>
  39. <http pattern="/javax.faces.resource/**" security="none"/>
  40.  
  41. <http>
  42. <intercept-url pattern="/views/login.xhtml" access="isAnonymous()"/>
  43. <intercept-url pattern="/" access="hasRole('USER')"/>
  44. <intercept-url pattern="/**" access="hasRole('USER')"/>
  45. <form-login
  46. login-page="/views/login.xhtml"
  47. login-processing-url="/login"
  48. always-use-default-target="true"
  49. default-target-url="/views/persones.xhtml"/>
  50. <http-basic/>
  51. <csrf disabled="true"/>
  52. <logout invalidate-session="true"
  53. delete-cookies="JSESSIONID,SPRING_SECURITY_REMEMBER_ME_COOKIE"
  54. logout-success-url="/views/login.xhtml">
  55. </logout>
  56. </http>
  57.  
  58. @Configuration
  59. public class WebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter
  60. {
  61. @Override
  62. protected void configure(HttpSecurity http) throws Exception
  63. {
  64. http
  65. .authorizeRequests()
  66. .antMatchers("/resources/css/**, /resources/images/**").permitAll()
  67. .antMatchers("/javax.faces.resource/**").permitAll()
  68. .antMatchers("/views/login*").permitAll()
  69. .antMatchers("/views/error.xhtml").permitAll()
  70. .anyRequest().authenticated()
  71. .and()
  72. .formLogin()
  73. .loginPage("/views/login.xhtml")
  74. .loginProcessingUrl("/login")
  75. .defaultSuccessUrl("/views/persones.xhtml", true)
  76. .and()
  77. .httpBasic()
  78. .and()
  79. .logout().logoutSuccessUrl("/views/login.xhtml")
  80. .invalidateHttpSession(true)
  81. .deleteCookies("JSESSIONID", "SPRING_SECURITY_REMEMBER_ME_COOKIE")
  82. .and()
  83. .csrf().disable();
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement