Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. public String login(){
  2.  
  3. try{
  4. Authentication request = new UsernamePasswordAuthenticationToken(this.getUsername(), this.getPassword());
  5. Authentication result = authenticationManager.authenticate(request);
  6. SecurityContextHolder.getContext().setAuthentication(result);
  7. }
  8. catch(Exception e){
  9.  
  10. e.printStackTrace();
  11. return "incorrect";
  12. }
  13. return "correct";
  14.  
  15. }
  16.  
  17.  
  18.  
  19. <http auto-config="true">
  20.  
  21. <intercept-url pattern="/web/*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
  22. <intercept-url pattern="/**" access="ROLE_USER" />
  23.  
  24. <form-login login-page="/web/login.xhtml"
  25. default-target-url="/main.xhtml"
  26. always-use-default-target="true" />
  27.  
  28. </http>
  29.  
  30. <authentication-manager alias="authenticationManager">
  31.  
  32. <authentication-provider user-service-ref="kullaniciDetayServisi" />
  33.  
  34. </authentication-manager>
  35.  
  36.  
  37.  
  38.  
  39. </beans:beans>
  40.  
  41.  
  42. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  43. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  44. <html xmlns="http://www.w3.org/1999/xhtml"
  45. xmlns:h="http://java.sun.com/jsf/html"
  46. xmlns:f="http://java.sun.com/jsf/core"
  47. xmlns:ui="http://java.sun.com/jsf/facelets">
  48. <h:head>
  49. </h:head>
  50. <h:body>
  51. <div align="center" style="">
  52. <h:form id="loginFormId" prependId="false">
  53. <div id="loginFieldsPnlId">
  54. <div id="loginFieldUsrContId">
  55. <h:outputText id="outTxtUserNameId" value="Username: " name="outTxtUserNameNm"></h:outputText>
  56. <h:inputText id="userName" required="true" value="#{loginBean.username}" requiredMessage="Please enter username"></h:inputText>
  57. <h:outputLabel id="outLblUserNameId" for="userName" name="outLblUserNameNm"></h:outputLabel>
  58. </div>
  59. <div id="loginFieldPassContId">
  60. <h:outputText id="outTxtPasswordId" value="Password: " name="outTxtPasswordNm"></h:outputText>
  61. <h:inputSecret id="password" required="true" value="#{loginBean.password}" requiredMessage="Please enter password" name="inTxtPasswordNm"></h:inputSecret>
  62. <h:outputLabel id="outLblPasswordId" for="password" name="outLblPasswordNm"></h:outputLabel>
  63. </div>
  64. </div>
  65. <div id="loginBtnPanelId">
  66. <h:commandButton id="btnLoginId" value="Login" action="#{loginBean.login}" ajax="false"></h:commandButton>
  67. <h:commandButton id="btnCancelId" value="Cancel" action="#{loginBean.cancel}" immediate="true" update="loginFormId" ajax="false"></h:commandButton>
  68. </div>
  69. </h:form>
  70. </div>
  71. <div>
  72. <h:messages></h:messages>
  73. </div>
  74. </h:body>
  75. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement