Při zadání špatného loginu nebo hesla se objeví chybová hláška v

přihlašovacím okně.
multitenant
Josef Rokos 10 years ago
parent a04b5719f8
commit 1829a5c0db

@ -19,9 +19,10 @@ public class SessionData implements Serializable {
private List<Workgroup> userWorkgroups; private List<Workgroup> userWorkgroups;
private User currentUser; private User currentUser;
private Map<Integer, List<Role>> workgroupRoles; private Map<Integer, List<Role>> workgroupRoles;
private boolean loginFailed;
public SessionData() { public SessionData() {
loginFailed = false;
} }
public List<Workgroup> getUserCentres() { public List<Workgroup> getUserCentres() {
@ -56,4 +57,12 @@ public class SessionData implements Serializable {
this.workgroupRoles = workgroupRoles; this.workgroupRoles = workgroupRoles;
} }
public boolean isLoginFailed() {
return loginFailed;
}
public void setLoginFailed(boolean loginFailed) {
this.loginFailed = loginFailed;
}
} }

@ -1,5 +1,7 @@
package info.bukova.isspst.security; package info.bukova.isspst.security;
import info.bukova.isspst.SessionData;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -8,17 +10,25 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.AuthenticationFailureHandler;
public class LoginFailHandler implements AuthenticationFailureHandler { public class LoginFailHandler implements AuthenticationFailureHandler {
@Autowired
private SessionData sessionData;
@Override @Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException ex) public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException ex)
throws IOException, ServletException { throws IOException, ServletException {
Logger logger = LoggerFactory.getLogger(LoginFailHandler.class); Logger logger = LoggerFactory.getLogger(LoginFailHandler.class);
logger.info("Login failed with message: " + ex.getMessage()); logger.info("Login failed with message: " + ex.getMessage());
sessionData.setLoginFailed(true);
response.sendRedirect("app/");
} }

@ -0,0 +1,24 @@
package info.bukova.isspst.ui;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import info.bukova.isspst.SessionData;
public class LoginVM {
@WireVariable
private SessionData sessionData;
@Init
public void init() {
}
public boolean isLoginFailed() {
boolean isFailed = sessionData.isLoginFailed();
sessionData.setLoginFailed(false);
return isFailed;
}
}

@ -1,7 +1,10 @@
<?page title="Přihlášení" contentType="text/x-component;charset=UTF-8"?> <?page title="Přihlášení" contentType="text/x-component;charset=UTF-8"?>
<zk> <zk>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window title="Přihlášení" border="normal" width="300px"> <window title="Přihlášení" border="normal" width="300px"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.LoginVM')">
<label value="Špatný login nebo heslo!" style="font-weight:bold; font-size: 14px; color: red;" visible="@load(vm.loginFailed)"/>
<html style="font-family:arial,sans-serif;font-size:12px;"> <html style="font-family:arial,sans-serif;font-size:12px;">
<![CDATA[ <![CDATA[
<form name='loginForm' action="j_spring_security_check" <form name='loginForm' action="j_spring_security_check"
@ -20,7 +23,7 @@ method='POST'>
</tr> </tr>
<tr> <tr>
<td colspan='2'><input name="submit" type="submit" <td colspan='2'><input name="submit" type="submit"
value="Přihlásit" /> value="Přihlásit" class="nicebutton" />
</td> </td>
</tr> </tr>
</table> </table>

Loading…
Cancel
Save