Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.93 KB | None | 0 0
  1. public ShopAdminDTO login(String userEmail, String password) throws EmailAddressNotFoundException {
  2.  
  3. LOGGER.debug("Login request for " + userEmail);
  4.  
  5. // Create and initialize user details object for Spring Security authentication mechanism.
  6. ShopAdminUserDetails userDetails = new ShopAdminUserDetails(userEmail, password, true, true, true, true, new ArrayList<GrantedAuthority>());
  7.  
  8. // Create authentication object for the Spring SecurityContext
  9. Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, password, new ArrayList<GrantedAuthority>());
  10.  
  11. boolean requiresEmailActivation = this.shopAdminValidationTokenRepository.getRequiresEmailValidation(userEmail);
  12.  
  13. if(requiresEmailActivation == true) {
  14.  
  15. LOGGER.info("Login denied: Email is not validated yet.");
  16.  
  17. // IMPORTANT NOTE: We throw an EmailNotFoundException instead of a
  18. // PleaseValidateYourEmailFirstException in order to NOT reveal
  19. // that this email exists. So: Do not "FIX" this!
  20. throw new EmailAddressNotFoundException();
  21. }
  22.  
  23. LOGGER.debug("Email appears validated.");
  24.  
  25. try {
  26. // Execute authentication chain to try user authentication
  27. auth = this.adminAuthenticationProvider.authenticate(auth);
  28. } catch(BadCredentialsException e) {
  29. // FIXME Login: We could/should count and limit login attempts here?
  30. LOGGER.info("Bad credentials found for: " + userEmail);
  31. throw e;
  32. }
  33.  
  34. LOGGER.info("User successfully authenticated [userEmail="+userEmail+"]");
  35.  
  36. // Set the authentication to the SecurityContext, the user is now logged in
  37. SecurityContext securityContext = SecurityContextHolder.getContext();
  38. securityContext.setAuthentication(auth);
  39.  
  40.  
  41. // Finally load the user data
  42. ShopAdminDTO shopAdminDto = this.shopAdminRepository.findByUserEmail(userEmail);
  43. return shopAdminDto;
  44. }
  45.  
  46. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  47. <!-- // BEGIN Spring Security -->
  48.  
  49. <sec:http pattern="/**" auto-config="true" use-expressions="true"/>
  50.  
  51. <bean id="httpSessionSecurityContextRepository" class='org.springframework.security.web.context.HttpSessionSecurityContextRepository'>
  52. <property name='allowSessionCreation' value='false' />
  53. </bean>
  54.  
  55. <bean id="securityContextPersistenceFilter" class="org.springframework.security.web.context.SecurityContextPersistenceFilter">
  56. <constructor-arg ref="httpSessionSecurityContextRepository" />
  57. </bean>
  58.  
  59. <bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
  60. <constructor-arg>
  61. <list>
  62. <sec:filter-chain pattern="/**" filters="securityContextPersistenceFilter" />
  63. </list>
  64. </constructor-arg>
  65. </bean>
  66.  
  67. <bean id="authenticationListener" class="com.mz.server.web.auth.CustomAuthenticationListener"/>
  68.  
  69. <bean id="authenticationProvider" class="com.mz.server.web.auth.CustomAuthenticationProvider"/>
  70.  
  71. <bean id="userDetailsService" class="com.mz.server.web.service.CustomUserDetailsService"/>
  72.  
  73. <sec:authentication-manager alias="authenticationManager">
  74. <sec:authentication-provider ref="authenticationProvider"/>
  75. </sec:authentication-manager>
  76.  
  77. <bean id="permissionEvaluator"
  78. class="com.mz.server.web.auth.permission.CustomPermissionEvaluator">
  79. <constructor-arg index="0">
  80. <map key-type="java.lang.String"
  81. value-type="com.mz.server.web.auth.permission.Permission">
  82. <entry key="isTest" value-ref="testPermission"/>
  83. </map>
  84. </constructor-arg>
  85. </bean>
  86.  
  87. <bean id="testPermission" class="com.mz.server.web.auth.permission.TestPermission">
  88. </bean>
  89.  
  90. <bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
  91. <property name="permissionEvaluator" ref="permissionEvaluator"/>
  92. </bean>
  93.  
  94. <sec:global-method-security
  95. authentication-manager-ref="authenticationManager"
  96. pre-post-annotations="enabled">
  97. <sec:expression-handler ref="expressionHandler"/>
  98. </sec:global-method-security>
  99.  
  100. <!-- // END Spring Security -->
  101. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  102.  
  103. if (debug) {
  104. logger.debug("Secure object: " + object + "; Attributes: " + attributes);
  105. }
  106.  
  107. if (SecurityContextHolder.getContext().getAuthentication() == null) {
  108. credentialsNotFound(messages.getMessage(
  109. "AbstractSecurityInterceptor.authenticationNotFound",
  110. "An Authentication object was not found in the SecurityContext"),
  111. object, attributes);
  112. }
  113.  
  114. Authentication authenticated = authenticateIfRequired();
  115.  
  116. [http-bio-8080-exec-4] DEBUG com.mz.server.servlet.LoginServletImpl - Login request by userId: user@gmx.at
  117. [http-bio-8080-exec-4] DEBUG com.mz.server.service.LoginService - Login request for user@gmx.at
  118. [http-bio-8080-exec-4] DEBUG com.mz.server.service.LoginService - Email appears validated.. authenticating..
  119. [http-bio-8080-exec-4] INFO com.mz.server.spring.auth.AdminAuthenticationProvider - authenticate(), User email: user@gmx.at
  120. [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
  121. [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
  122. [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Loading password salt for user@gmx.at
  123. [http-bio-8080-exec-4] INFO com.mz.server.repository.jooq.shop.ShopAdminRepository - Checking password for user@gmx.at
  124. [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Password valid.
  125. [http-bio-8080-exec-4] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - getPrincipal()
  126. [http-bio-8080-exec-4] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - Setting user com.mz.server.spring.auth.ShopAdminUserDetails@8ac733b2: Username: user@gmx.at; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Not granted any authorities to 'authenticated'.
  127. [http-bio-8080-exec-4] INFO com.mz.server.service.LoginService - User successfully authenticated [userEmail=user@gmx.at]
  128. [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
  129. [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
  130. [http-bio-8080-exec-6] DEBUG com.mz.server.servlet.shop.ShopServletImpl - Requested available shops.
  131. [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
  132. [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
  133. [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl - SPRING_SECURITY_CONTEXT: org.springframework.security.core.context.SecurityContextImpl@259bee56: Authentication: com.mz.server.spring.auth.CustomUserAuthentication@259bee56
  134. [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
  135. [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
  136. [http-bio-8080-exec-6] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - Secure object: ReflectiveMethodInvocation: public java.util.List com.mz.server.service.ShopService.getAvailableShops(); target is of class [com.mz.server.service.ShopService]; Attributes: [[authorize: 'isAuthenticated()', filter: 'null', filterTarget: 'null']]
  137. [http-bio-8080-exec-6] DEBUG com.mz.server.spring.auth.CustomHttpSessionListener - AuthenticationCredentialsNotFoundEvent
  138. Jun 09, 2016 8:06:42 PM org.apache.catalina.core.ApplicationContext log
  139. SEVERE: Exception while dispatching incoming RPC call
  140. com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List com.mz.shared.web.service.shop.ShopServlet.getAvailableShops()' threw an unexpected exception: org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
  141. at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:416)
  142. at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:605)
  143. ....
  144.  
  145. [http-bio-8080-exec-7] DEBUG com.mz.server.servlet.LoginServletImpl - Login request by userId: user@gmx.at
  146. [http-bio-8080-exec-7] DEBUG com.mz.server.service.LoginService - Login request for user@gmx.at
  147. [http-bio-8080-exec-7] DEBUG com.mz.server.service.LoginService - Email appears validated.. authenticating..
  148. [http-bio-8080-exec-7] INFO com.mz.server.spring.auth.AdminAuthenticationProvider - authenticate(), User email: user@gmx.at
  149. [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
  150. [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
  151. [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Loading password salt for user@gmx.at
  152. [http-bio-8080-exec-7] INFO com.mz.server.repository.jooq.shop.ShopAdminRepository - Checking password for user@gmx.at
  153. [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Password valid.
  154. [http-bio-8080-exec-7] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - getPrincipal()
  155. [http-bio-8080-exec-7] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - Setting user com.mz.server.spring.auth.ShopAdminUserDetails@8ac733b2: Username: user@gmx.at; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Not granted any authorities to 'authenticated'.
  156. [http-bio-8080-exec-7] INFO com.mz.server.service.LoginService - User successfully authenticated [userEmail=user@gmx.at]
  157. [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
  158. [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
  159. [http-bio-8080-exec-7] DEBUG com.mz.server.servlet.shop.ShopServletImpl - Requested available shops.
  160. [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
  161. [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
  162. [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl - SPRING_SECURITY_CONTEXT: org.springframework.security.core.context.SecurityContextImpl@1ea22883: Authentication: com.mz.server.spring.auth.CustomUserAuthentication@1ea22883
  163. [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
  164. [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
  165. [http-bio-8080-exec-7] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - Secure object: ReflectiveMethodInvocation: public java.util.List com.mz.server.service.ShopService.getAvailableShops(); target is of class [com.mz.server.service.ShopService]; Attributes: [[authorize: 'isAuthenticated()', filter: 'null', filterTarget: 'null']]
  166. [http-bio-8080-exec-7] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - isAuthenticate(): true
  167. [http-bio-8080-exec-7] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - Previously Authenticated: com.mz.server.spring.auth.CustomUserAuthentication@1ea22883
  168. [http-bio-8080-exec-7] DEBUG org.springframework.security.access.vote.AffirmativeBased - Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter@653fccd, returned: 1
  169. [http-bio-8080-exec-7] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - Authorization successful
  170. [http-bio-8080-exec-7] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - RunAsManager did not change Authentication object
  171. [http-bio-8080-exec-7] DEBUG com.mz.server.service.ShopService - Getting available shops for ..
  172. [http-bio-8080-exec-7] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - getPrincipal()
  173. [http-bio-8080-exec-7] DEBUG com.mz.server.service.ShopService - user@gmx.at
  174. [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Fetching shops for shop_admin_id 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement