/** * Constructs a new {@code AsyncActionExecutor} instance. * * @param action * the action to execute asynchronously. * @param context * the action context. * @param group * the thread group. * @param slaveBackendController * the slave backend controller used to execute the action. */ public AsyncActionExecutor(IAction action, Map<String, Object> context, ThreadGroup group, AbstractBackendController slaveBackendController) { super(group, /* "Jspresso Asynchronous Action Runner " + */ action.getClass().getSimpleName() + "[" + slaveBackendController.getApplicationSession().getId() + "][" + slaveBackendController.getApplicationSession().getUsername() + "]"); this.action = action; this.context = context; this.slaveBackendController = slaveBackendController; this.progressionData = new HashMap<>(); }
private void linkSessionArtifacts() { if (getApplicationSession() != null && getEntityFactory() != null) { ((ApplicationSessionAwareProxyEntityFactory) getEntityFactory()) .setApplicationSession(getApplicationSession()); ((BasicApplicationSession) getApplicationSession()) .setEntityFactory(getEntityFactory()); } } }
/** * Delegates to the translation provider. * <p/> * {@inheritDoc} */ @Override public String getTranslation(String key, Object[] args, Locale locale) { if (customTranslationPlugin != null) { String translation = customTranslationPlugin.getTranslation(key, args, locale, getApplicationSession()); if (translation != null) { return translation; } } return translationProvider.getTranslation(key, args, locale); }
/** * Delegates to the translation provider. * <p/> * {@inheritDoc} */ @Override public String getTranslation(String key, Locale locale) { if (customTranslationPlugin != null) { String translation = customTranslationPlugin.getTranslation(key, locale, getApplicationSession()); if (translation != null) { return translation; } } return translationProvider.getTranslation(key, locale); }
/** * {@inheritDoc} */ @Override public void loggedIn(Subject subject) { getApplicationSession().setSubject(subject); String userPreferredLanguageCode = (String) getApplicationSession().getPrincipal().getCustomProperty( UserPrincipal.LANGUAGE_PROPERTY); if (userPreferredLanguageCode != null) { getApplicationSession().setLocale(LocaleUtils.toLocale(userPreferredLanguageCode)); } if (getUserPreferencesStore() != null) { getUserPreferencesStore().setStorePath(getApplicationSession().getUsername()); } }
/** * Delegates to the translation provider. * <p/> * {@inheritDoc} */ @Override public String getTranslation(String key, String defaultMessage, Locale locale) { if (customTranslationPlugin != null) { String translation = customTranslationPlugin.getTranslation(key, locale, getApplicationSession()); if (translation != null) { return translation; } } return translationProvider.getTranslation(key, defaultMessage, locale); }
/** * Delegates to the translation provider. * <p/> * {@inheritDoc} */ @Override public String getTranslation(String key, Object[] args, String defaultMessage, Locale locale) { if (customTranslationPlugin != null) { String translation = customTranslationPlugin.getTranslation(key, args, locale, getApplicationSession()); if (translation != null) { return translation; } } return translationProvider.getTranslation(key, args, defaultMessage, locale); }
/** * {@inheritDoc} */ @Override public boolean isAccessGranted(ISecurable securable) { if (SecurityHelper.isSubjectGranted(getApplicationSession().getSubject(), securable)) { if (customSecurityPlugin != null) { try { pushToSecurityContext(securable); Map<String, Object> securityContext = new HashMap<>(); if (getApplicationSession() != null && getApplicationSession().getPrincipal() != null) { securityContext.put(SecurityContextConstants.USER_ROLES, SecurityHelper.getRoles(getApplicationSession().getSubject())); securityContext.put(SecurityContextConstants.USER_ID, getApplicationSession().getUsername()); Map<String, Object> sessionProperties = getApplicationSession().getCustomValues(); sessionProperties.putAll(getApplicationSession().getPrincipal().getCustomProperties()); securityContext.put(SecurityContextConstants.SESSION_PROPERTIES, sessionProperties); } securityContext.putAll(getSecurityContext()); return customSecurityPlugin.isAccessGranted(securable, securityContext); } finally { restoreLastSecurityContextSnapshot(); } } return true; } return false; }
/** * Perform login boolean. * * @param username * the username * @param password * the password * @return the boolean */ @Override public boolean performLogin(String username, String password) { Subject subject = null; String lcName = getLoginContextName(); if (lcName != null) { subject = performJAASLogin(username, password); } if (subject == null) { LOG.info("User {} failed to log in for session {}.", username, getApplicationSession().getId()); return false; } LOG.info("User {} logged in for session {}.", username, getApplicationSession().getId()); loggedIn(subject); return true; }
/** * Directly delegates execution to the action after having completed its * execution context with the controller's initial context. * <p> * {@inheritDoc} */ public boolean execute(IAction action, Map<String, Object> context) { if (action == null) { return true; } SecurityHelper.checkAccess(getApplicationSession().getSubject(), action, getTranslationProvider(), getLocale()); Map<String, Object> actionContext = getInitialActionContext(); if (context != null) { context.putAll(actionContext); } return action.execute(this, context); }
/** * Creates a slave backend controller, starts it and assign it the same * application session. * <p/> * {@inheritDoc} */ @Override public AbstractBackendController createBackendController() { AbstractBackendController slaveBackendController = (AbstractBackendController) getSlaveControllerFactory() .createBackendController(); // Start the slave controller slaveBackendController.start(getLocale(), getClientTimeZone()); // Use the same application session slaveBackendController.setApplicationSession(getApplicationSession()); slaveBackendController.sessionUnitOfWork = sessionUnitOfWork; slaveBackendController.workspaceConnectors = workspaceConnectors; slaveBackendController.moduleConnectors = moduleConnectors; slaveBackendController.masterController = this; return slaveBackendController; }