Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ShopAdminDTO login(String userEmail, String password) throws EmailAddressNotFoundException {
- LOGGER.debug("Login request for " + userEmail);
- // Create and initialize user details object for Spring Security authentication mechanism.
- ShopAdminUserDetails userDetails = new ShopAdminUserDetails(userEmail, password, true, true, true, true, new ArrayList<GrantedAuthority>());
- // Create authentication object for the Spring SecurityContext
- Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, password, new ArrayList<GrantedAuthority>());
- boolean requiresEmailActivation = this.shopAdminValidationTokenRepository.getRequiresEmailValidation(userEmail);
- if(requiresEmailActivation == true) {
- LOGGER.info("Login denied: Email is not validated yet.");
- // IMPORTANT NOTE: We throw an EmailNotFoundException instead of a
- // PleaseValidateYourEmailFirstException in order to NOT reveal
- // that this email exists. So: Do not "FIX" this!
- throw new EmailAddressNotFoundException();
- }
- LOGGER.debug("Email appears validated.");
- try {
- // Execute authentication chain to try user authentication
- auth = this.adminAuthenticationProvider.authenticate(auth);
- } catch(BadCredentialsException e) {
- // FIXME Login: We could/should count and limit login attempts here?
- LOGGER.info("Bad credentials found for: " + userEmail);
- throw e;
- }
- LOGGER.info("User successfully authenticated [userEmail="+userEmail+"]");
- // Set the authentication to the SecurityContext, the user is now logged in
- SecurityContext securityContext = SecurityContextHolder.getContext();
- securityContext.setAuthentication(auth);
- // Finally load the user data
- ShopAdminDTO shopAdminDto = this.shopAdminRepository.findByUserEmail(userEmail);
- return shopAdminDto;
- }
- <!-- //////////////////////////////////////////////////////////////////////////////// -->
- <!-- // BEGIN Spring Security -->
- <sec:http pattern="/**" auto-config="true" use-expressions="true"/>
- <bean id="httpSessionSecurityContextRepository" class='org.springframework.security.web.context.HttpSessionSecurityContextRepository'>
- <property name='allowSessionCreation' value='false' />
- </bean>
- <bean id="securityContextPersistenceFilter" class="org.springframework.security.web.context.SecurityContextPersistenceFilter">
- <constructor-arg ref="httpSessionSecurityContextRepository" />
- </bean>
- <bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
- <constructor-arg>
- <list>
- <sec:filter-chain pattern="/**" filters="securityContextPersistenceFilter" />
- </list>
- </constructor-arg>
- </bean>
- <bean id="authenticationListener" class="com.mz.server.web.auth.CustomAuthenticationListener"/>
- <bean id="authenticationProvider" class="com.mz.server.web.auth.CustomAuthenticationProvider"/>
- <bean id="userDetailsService" class="com.mz.server.web.service.CustomUserDetailsService"/>
- <sec:authentication-manager alias="authenticationManager">
- <sec:authentication-provider ref="authenticationProvider"/>
- </sec:authentication-manager>
- <bean id="permissionEvaluator"
- class="com.mz.server.web.auth.permission.CustomPermissionEvaluator">
- <constructor-arg index="0">
- <map key-type="java.lang.String"
- value-type="com.mz.server.web.auth.permission.Permission">
- <entry key="isTest" value-ref="testPermission"/>
- </map>
- </constructor-arg>
- </bean>
- <bean id="testPermission" class="com.mz.server.web.auth.permission.TestPermission">
- </bean>
- <bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
- <property name="permissionEvaluator" ref="permissionEvaluator"/>
- </bean>
- <sec:global-method-security
- authentication-manager-ref="authenticationManager"
- pre-post-annotations="enabled">
- <sec:expression-handler ref="expressionHandler"/>
- </sec:global-method-security>
- <!-- // END Spring Security -->
- <!-- //////////////////////////////////////////////////////////////////////////////// -->
- if (debug) {
- logger.debug("Secure object: " + object + "; Attributes: " + attributes);
- }
- if (SecurityContextHolder.getContext().getAuthentication() == null) {
- credentialsNotFound(messages.getMessage(
- "AbstractSecurityInterceptor.authenticationNotFound",
- "An Authentication object was not found in the SecurityContext"),
- object, attributes);
- }
- Authentication authenticated = authenticateIfRequired();
- [http-bio-8080-exec-4] DEBUG com.mz.server.servlet.LoginServletImpl - Login request by userId: user@gmx.at
- [http-bio-8080-exec-4] DEBUG com.mz.server.service.LoginService - Login request for user@gmx.at
- [http-bio-8080-exec-4] DEBUG com.mz.server.service.LoginService - Email appears validated.. authenticating..
- [http-bio-8080-exec-4] INFO com.mz.server.spring.auth.AdminAuthenticationProvider - authenticate(), User email: user@gmx.at
- [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
- [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
- [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Loading password salt for user@gmx.at
- [http-bio-8080-exec-4] INFO com.mz.server.repository.jooq.shop.ShopAdminRepository - Checking password for user@gmx.at
- [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Password valid.
- [http-bio-8080-exec-4] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - getPrincipal()
- [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'.
- [http-bio-8080-exec-4] INFO com.mz.server.service.LoginService - User successfully authenticated [userEmail=user@gmx.at]
- [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
- [http-bio-8080-exec-4] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
- [http-bio-8080-exec-6] DEBUG com.mz.server.servlet.shop.ShopServletImpl - Requested available shops.
- [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [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
- [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [http-bio-8080-exec-6] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [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']]
- [http-bio-8080-exec-6] DEBUG com.mz.server.spring.auth.CustomHttpSessionListener - AuthenticationCredentialsNotFoundEvent
- Jun 09, 2016 8:06:42 PM org.apache.catalina.core.ApplicationContext log
- SEVERE: Exception while dispatching incoming RPC call
- 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
- at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:416)
- at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:605)
- ....
- [http-bio-8080-exec-7] DEBUG com.mz.server.servlet.LoginServletImpl - Login request by userId: user@gmx.at
- [http-bio-8080-exec-7] DEBUG com.mz.server.service.LoginService - Login request for user@gmx.at
- [http-bio-8080-exec-7] DEBUG com.mz.server.service.LoginService - Email appears validated.. authenticating..
- [http-bio-8080-exec-7] INFO com.mz.server.spring.auth.AdminAuthenticationProvider - authenticate(), User email: user@gmx.at
- [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
- [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
- [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Loading password salt for user@gmx.at
- [http-bio-8080-exec-7] INFO com.mz.server.repository.jooq.shop.ShopAdminRepository - Checking password for user@gmx.at
- [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - Password valid.
- [http-bio-8080-exec-7] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - getPrincipal()
- [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'.
- [http-bio-8080-exec-7] INFO com.mz.server.service.LoginService - User successfully authenticated [userEmail=user@gmx.at]
- [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - findByUserEmail(): user@gmx.at
- [http-bio-8080-exec-7] DEBUG com.mz.server.repository.jooq.shop.ShopAdminRepository - User found.
- [http-bio-8080-exec-7] DEBUG com.mz.server.servlet.shop.ShopServletImpl - Requested available shops.
- [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [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
- [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [http-bio-8080-exec-7] INFO com.mz.server.servlet.shop.ShopServletImpl -
- [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']]
- [http-bio-8080-exec-7] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - isAuthenticate(): true
- [http-bio-8080-exec-7] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - Previously Authenticated: com.mz.server.spring.auth.CustomUserAuthentication@1ea22883
- [http-bio-8080-exec-7] DEBUG org.springframework.security.access.vote.AffirmativeBased - Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter@653fccd, returned: 1
- [http-bio-8080-exec-7] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - Authorization successful
- [http-bio-8080-exec-7] DEBUG org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor - RunAsManager did not change Authentication object
- [http-bio-8080-exec-7] DEBUG com.mz.server.service.ShopService - Getting available shops for ..
- [http-bio-8080-exec-7] DEBUG com.mz.server.spring.auth.CustomUserAuthentication - getPrincipal()
- [http-bio-8080-exec-7] DEBUG com.mz.server.service.ShopService - user@gmx.at
- [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