/**
 * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gravitee.management.security.listener;

import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;

/**
 * @author David BRASSELY (brasseld at gmail.com)
 */
public class AuthenticationSuccessListener implements ApplicationListener<AuthenticationSuccessEvent> {

    @Override
    public void onApplicationEvent(AuthenticationSuccessEvent event) {
        System.out.println("User Logged In: " + event.getAuthentication());
    }
}
@@ -686,140 +686,498 @@
 ort 
-org.springframework.context.ApplicationListener;%0Aimport org.springframework.security.authentication.event.AuthenticationSuccessEvent
+java.util.List;%0Aimport java.util.Optional;%0Aimport java.util.stream.Collectors;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.context.ApplicationListener;%0Aimport org.springframework.security.authentication.event.AuthenticationSuccessEvent;%0Aimport org.springframework.security.core.Authentication;%0A%0Aimport io.gravitee.management.model.NewUserEntity;%0Aimport io.gravitee.management.model.UserEntity;%0Aimport io.gravitee.management.service.UserService
 ;%0A%0A/
@@ -1338,16 +1338,69 @@
 ent%3E %7B%0A%0A
+    @Autowired%0A    private UserService userService;%0A%0A
     @Ove
@@ -1476,16 +1476,621 @@
 vent) %7B%0A
+        final Authentication authentication = event.getAuthentication();%0A        final Optional%3CUserEntity%3E user = userService.findByName(authentication.getName());%0A        if (!user.isPresent()) %7B%0A            final NewUserEntity newUser = new NewUserEntity();%0A            newUser.setUsername(authentication.getName());%0A            final List%3CString%3E roles = authentication.getAuthorities().stream().map(%0A                grantedAuthority -%3E grantedAuthority.getAuthority()%0A            ).collect(Collectors.toList());%0A            newUser.setRoles(roles);%0A            userService.create(newUser);%0A        %7D%0A
         
@@ -2129,26 +2129,17 @@
 In: %22 + 
-event.getA
+a
 uthentic
@@ -2143,18 +2143,16 @@
 tication
-()
 );%0A    %7D

Create user on successful logon