Commit c074fd84 authored by Matija Obreza's avatar Matija Obreza

Fix: Auth failure listener

- Authentication principal is not String
parent 967826d6
......@@ -15,11 +15,13 @@
*/
package org.genesys.blocks.security.lockout;
import org.genesys.blocks.security.model.BasicUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.stereotype.Component;
......@@ -45,7 +47,14 @@ public class AuthenticationFailureBadCredentialsListener implements ApplicationL
*/
@Override
public void onApplicationEvent(final AuthenticationFailureBadCredentialsEvent event) {
final String userName = (String) event.getAuthentication().getPrincipal();
final Object principal = event.getAuthentication().getPrincipal();
String userName = null;
if (principal instanceof BasicUser<?>) {
userName = ((BasicUser<?>) principal).getUsername();
} else if (principal instanceof UserDetails) {
userName = ((UserDetails) principal).getUsername();
}
final Object details = event.getAuthentication().getDetails();
if ((details != null) && (details instanceof WebAuthenticationDetails)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment