use of org.hisp.dhis.security.spring2fa.TwoFactorWebAuthenticationDetails in project dhis2-core by dhis2.
the class AuthenticationListener method handleAuthenticationSuccess.
@EventListener({ InteractiveAuthenticationSuccessEvent.class, AuthenticationSuccessEvent.class })
public void handleAuthenticationSuccess(AbstractAuthenticationEvent event) {
Authentication auth = event.getAuthentication();
String username = event.getAuthentication().getName();
Object details = auth.getDetails();
if (TwoFactorWebAuthenticationDetails.class.isAssignableFrom(details.getClass())) {
TwoFactorWebAuthenticationDetails authDetails = (TwoFactorWebAuthenticationDetails) details;
log.debug(String.format("Login attempt succeeded for remote IP: %s", authDetails.getIp()));
}
if (OAuth2LoginAuthenticationToken.class.isAssignableFrom(auth.getClass())) {
OAuth2LoginAuthenticationToken authenticationToken = (OAuth2LoginAuthenticationToken) auth;
DhisOidcUser principal = (DhisOidcUser) authenticationToken.getPrincipal();
username = principal.getUser().getUsername();
WebAuthenticationDetails tokenDetails = (WebAuthenticationDetails) authenticationToken.getDetails();
String remoteAddress = tokenDetails.getRemoteAddress();
log.debug(String.format("OIDC login attempt succeeded for remote IP: %s", remoteAddress));
}
registerSuccessfulLogin(username);
}
use of org.hisp.dhis.security.spring2fa.TwoFactorWebAuthenticationDetails in project dhis2-core by dhis2.
the class AccountController method authenticate.
private void authenticate(String username, String rawPassword, Collection<GrantedAuthority> authorities, HttpServletRequest request) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, rawPassword, authorities);
token.setDetails(new TwoFactorWebAuthenticationDetails(request));
Authentication auth = twoFactorAuthenticationProvider.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(auth);
HttpSession session = request.getSession();
session.setAttribute("SPRING_SECURITY_CONTEXT", SecurityContextHolder.getContext());
}
use of org.hisp.dhis.security.spring2fa.TwoFactorWebAuthenticationDetails in project dhis2-core by dhis2.
the class AuthenticationListener method handleAuthenticationFailure.
@EventListener
public void handleAuthenticationFailure(AbstractAuthenticationFailureEvent event) {
Authentication auth = event.getAuthentication();
String username = event.getAuthentication().getName();
Object details = auth.getDetails();
if (details != null && TwoFactorWebAuthenticationDetails.class.isAssignableFrom(details.getClass())) {
TwoFactorWebAuthenticationDetails authDetails = (TwoFactorWebAuthenticationDetails) details;
log.debug(String.format("Login attempt failed for remote IP: %s", authDetails.getIp()));
}
if (OAuth2LoginAuthenticationToken.class.isAssignableFrom(auth.getClass())) {
OAuth2LoginAuthenticationToken authenticationToken = (OAuth2LoginAuthenticationToken) auth;
DhisOidcUser principal = (DhisOidcUser) authenticationToken.getPrincipal();
if (principal != null) {
username = principal.getUser().getUsername();
}
WebAuthenticationDetails tokenDetails = (WebAuthenticationDetails) authenticationToken.getDetails();
String remoteAddress = tokenDetails.getRemoteAddress();
log.debug(String.format("OIDC login attempt failed for remote IP: %s", remoteAddress));
}
securityService.registerFailedLogin(username);
}
Aggregations