package de.larmic.butterfaces.joinfaces.security;

import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;

/**
 * Session scoped spring bean represents logged in user with user name and logged in flag.
 */
@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Identity {

    private String userName;
    private boolean loggedIn;

    public String login(String userName, String password) {
        this.loggedIn = "admin".equals(userName) && "admin".equals(password);
        this.userName = loggedIn ? userName : null;
        return loggedIn ? "/secure/index.jsf?faces-redirect=true" : null;
    }

    public String logout() {
        loggedIn = false;
        userName = null;

        return "/login.jsf?faces-redirect=true";
    }

    public boolean isLoggedIn() {
        return loggedIn;
    }

    public String getUserName() {
        return userName;
    }
}

@@ -44,16 +44,73 @@
 urity;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -470,16 +470,90 @@
 tity %7B%0A%0A
+    private final Logger log = LoggerFactory.getLogger(this.getClass());%0A%0A
     priv
@@ -660,24 +660,76 @@
 password) %7B%0A
+        log.info(%22Try to login user %7B%7D%22, userName);%0A
         this
@@ -798,60 +798,129 @@
 d);%0A
-        this.userName = loggedIn ? userName : null;%0A
+%0A        if (loggedIn) %7B%0A            this.userName = userName;%0A            log.info(%22User %7B%7D logged in.%22, userName);%0A    
     
@@ -933,19 +933,8 @@
 turn
- loggedIn ?
  %22/s
@@ -973,16 +973,170 @@
 rue%22
- : null;
+;%0A        %7D else %7B%0A            this.userName = null;%0A            log.info(%22User %7B%7D not logged in. Bad credentials.%22, userName);%0A            return null;%0A        %7D
 %0A   
@@ -1220,16 +1220,67 @@
  null;%0A%0A
+        log.info(%22User %7B%7D logged out%22, userName);%0A%0A
         

add some logging output