use of com.haulmont.cuba.web.Connection in project cuba by cuba-platform.
the class DefaultApp method connectionStateChanged.
@Override
public void connectionStateChanged(StateChangeEvent event) {
Connection connection = event.getSource();
log.debug("connectionStateChanged connected: {}, authenticated: {}", connection.isConnected(), connection.isAuthenticated());
cleanupBackgroundTasks();
closeAllWindows();
clearSettingsCache();
if (connection.isConnected()) {
UserSession userSession = connection.getSessionNN();
setLocale(userSession.getLocale());
// substitution listeners are cleared by connection on logout
connection.addUserSubstitutionListener(this);
preventSessionFixation(connection, userSession);
initExceptionHandlers(true);
initializeUi();
if (linkHandler != null && linkHandler.canHandleLink()) {
linkHandler.handle();
linkHandler = null;
}
afterLoggedIn();
publishAppLoggedInEvent();
} else {
initExceptionHandlers(false);
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
if (currentRequest != null) {
Locale requestLocale = currentRequest.getLocale();
setLocale(resolveLocale(requestLocale));
}
try {
connection.login(new AnonymousUserCredentials(getLocale()));
} catch (LoginException e) {
throw new RuntimeException("Unable to login as anonymous!");
}
publishAppLoggedOutEvent(event.getPreviousSession());
}
}
use of com.haulmont.cuba.web.Connection in project cuba by cuba-platform.
the class IdpLoginLifecycleManager method onAppStarted.
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void onAppStarted(AppStartedEvent event) throws LoginException {
Connection connection = event.getApp().getConnection();
// can be already authenticated by another event listener
if (webIdpConfig.getIdpEnabled() && !connection.isAuthenticated()) {
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
if (currentRequest != null) {
Principal principal = currentRequest.getUserPrincipal();
if (principal instanceof IdpSessionPrincipal) {
IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession();
Locale locale = event.getApp().getLocale();
ExternalUserCredentials credentials = new ExternalUserCredentials(principal.getName(), locale);
credentials.setSessionAttributes(ImmutableMap.of(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId()));
connection.login(credentials);
}
}
}
}
use of com.haulmont.cuba.web.Connection in project cuba by cuba-platform.
the class ChangePasswordAfterLoginListener method onApplicationEvent.
@Override
public void onApplicationEvent(AppLoggedInEvent event) {
App app = event.getApp();
Connection connection = app.getConnection();
if (connection.isAuthenticated() && !isLoggedInWithExternalAuth(connection.getSessionNN())) {
User user = connection.getSessionNN().getUser();
// Change password on logon
if (Boolean.TRUE.equals(user.getChangePasswordAtNextLogon())) {
WebWindowManager wm = app.getWindowManager();
for (Window window : wm.getOpenWindows()) {
window.setEnabled(false);
}
WindowInfo changePasswordDialog = windowConfig.getWindowInfo("sec$User.changePassword");
Window changePasswordWindow = wm.openWindow(changePasswordDialog, WindowManager.OpenType.DIALOG.closeable(false), ParamsMap.of("cancelEnabled", Boolean.FALSE));
changePasswordWindow.addCloseListener(actionId -> {
for (Window window : wm.getOpenWindows()) {
window.setEnabled(true);
}
});
}
}
}
use of com.haulmont.cuba.web.Connection in project cuba by cuba-platform.
the class LegacyLoginEventsForwarder method redirectToExternalAuthentication.
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void redirectToExternalAuthentication(AppLoggedOutEvent event) {
Connection connection = event.getApp().getConnection();
if (webAuthConfig.getExternalAuthentication() && event.getLoggedOutSession() != null && isLoggedInWithExternalAuth(event.getLoggedOutSession())) {
String loggedOutUrl = connection.logoutExternalAuthentication();
event.setRedirectUrl(loggedOutUrl);
}
}
use of com.haulmont.cuba.web.Connection in project cuba by cuba-platform.
the class WebUserSessionSource method checkCurrentUserSession.
@Override
public boolean checkCurrentUserSession() {
if (App.isBound()) {
App app = App.getInstance();
Connection connection = app.getConnection();
return connection.isConnected() && connection.getSession() != null;
} else {
SecurityContext securityContext = AppContext.getSecurityContext();
if (securityContext == null) {
return false;
}
if (securityContext.getSession() != null) {
return true;
} else {
try {
getUserSessionFromMiddleware(securityContext.getSessionId());
return true;
} catch (Exception e) {
return false;
}
}
}
}
Aggregations