use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class CustomConditionFrame method initComponents.
@Override
public void initComponents() {
super.initComponents();
typeSelect.addValueChangeListener(e -> {
boolean disableTypeCheckBox = ParamType.UNARY.equals(typeSelect.getValue()) || ParamType.BOOLEAN.equals(typeSelect.getValue());
inExprCb.setEnabled(!disableTypeCheckBox);
if (disableTypeCheckBox)
inExprCb.setValue(false);
boolean isEntity = ParamType.ENTITY.equals(typeSelect.getValue());
boolean isEnum = ParamType.ENUM.equals(typeSelect.getValue());
boolean isDate = ParamType.DATE.equals(typeSelect.getValue());
entityLab.setEnabled(isEntity || isEnum);
entitySelect.setEnabled(isEntity || isEnum);
entitySelect.setRequired(entitySelect.isEnabled());
paramWhereLab.setEnabled(isEntity);
entityParamWhereField.setEnabled(isEntity);
paramViewLab.setEnabled(isEntity);
entityParamViewField.setEnabled(isEntity);
useUserTimeZoneLab.setVisible(isDate);
useUserTimeZone.setVisible(isDate);
Param param = condition.getParam();
fillEntitySelect(param);
// recreate default value component based on param type
if (!initializing && defaultValueLayout.isVisible()) {
ParamType paramType = (ParamType) e.getValue();
if ((isEntity || isEnum) && (entitySelect.getValue() == null)) {
defaultValueLayout.remove(defaultValueComponent);
param.setJavaClass(null);
} else {
Class paramJavaClass = getParamJavaClass(paramType);
param.setJavaClass(paramJavaClass);
param.setDefaultValue(null);
createDefaultValueComponent();
}
}
});
inExprCb.addValueChangeListener(e -> {
condition.getParam().setInExpr(BooleanUtils.isTrue((Boolean) e.getValue()));
// recreate default value component based on "in list" checkbox value
if (!initializing && defaultValueLayout.isVisible()) {
condition.getParam().setDefaultValue(null);
createDefaultValueComponent();
}
});
useUserTimeZone.addValueChangeListener(e -> {
if (defaultValueComponent != null) {
if (defaultValueComponent instanceof DateField) {
DateField dateField = (DateField) defaultValueComponent;
if (Boolean.TRUE.equals(e.getValue())) {
UserSession userSession = userSessionSource.getUserSession();
if (userSession.getTimeZone() != null) {
dateField.setTimeZone(userSession.getTimeZone());
}
dateField.setValue(null);
dateField.setEditable(false);
} else {
dateField.setTimeZone(TimeZone.getDefault());
dateField.setEditable(true);
}
}
}
});
entitySelect.addValueChangeListener(e -> {
if (initializing || !defaultValueLayout.isVisible()) {
return;
}
if (e.getValue() == null) {
defaultValueLayout.remove(defaultValueComponent);
return;
}
Param param = condition.getParam();
Class paramJavaClass = e.getValue() instanceof Class ? (Class) e.getValue() : ((MetaClass) e.getValue()).getJavaClass();
param.setJavaClass(paramJavaClass);
param.setDefaultValue(null);
createDefaultValueComponent();
});
FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
filterHelper.setLookupNullSelectionAllowed(typeSelect, false);
filterHelper.setLookupFieldPageLength(typeSelect, 12);
joinField.setSuggester((source, text, cursorPosition) -> requestHint(joinField, text, cursorPosition));
joinField.setHighlightActiveLine(false);
joinField.setShowGutter(false);
whereField.setSuggester((source, text, cursorPosition) -> requestHint(whereField, text, cursorPosition));
whereField.setHighlightActiveLine(false);
whereField.setShowGutter(false);
entityParamWhereField.setSuggester((source, text, cursorPosition) -> requestHintParamWhere(entityParamWhereField, text, cursorPosition));
entityParamWhereField.setHighlightActiveLine(false);
entityParamWhereField.setShowGutter(false);
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class ListEditorHelper method getValueCaption.
public static String getValueCaption(Object v, ListEditor.ItemType itemType, TimeZone timeZone) {
if (v == null)
return null;
switch(itemType) {
case ENTITY:
if (v instanceof Instance)
return ((Instance) v).getInstanceName();
else
return v.toString();
case STRING:
return (String) v;
case DATE:
return Datatypes.getNN(java.sql.Date.class).format(v);
case DATETIME:
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
UserSession userSession = userSessionSource.getUserSession();
if (timeZone != null) {
return ((TimeZoneAwareDatatype) Datatypes.getNN(Date.class)).format(v, userSession.getLocale(), timeZone);
} else {
return Datatypes.getNN(Date.class).format(v, userSession.getLocale());
}
case INTEGER:
return Datatypes.getNN(Integer.class).format(v);
case LONG:
return Datatypes.getNN(Long.class).format(v);
case BIGDECIMAL:
return Datatypes.getNN(BigDecimal.class).format(v);
case DOUBLE:
return Datatypes.getNN(Double.class).format(v);
case ENUM:
return AppBeans.get(Messages.class).getMessage((Enum) v);
case UUID:
return Datatypes.getNN(java.util.UUID.class).format(v);
default:
throw new IllegalStateException("Unknown item type");
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class LogMdc method setup.
public static void setup(SecurityContext securityContext) {
String userProp = AppContext.getProperty("cuba.logUserName");
if (userProp == null || Boolean.valueOf(userProp)) {
if (securityContext != null) {
String user = securityContext.getUser();
if (user == null) {
UserSession session = securityContext.getSession();
if (session != null)
user = session.getUser().getLogin();
else if (securityContext.getSessionId() != null) {
ApplicationContext applicationContext = AppContext.getApplicationContext();
if (applicationContext.containsBean("cuba_UserSessions")) {
UserSessionFinder sessionFinder = (UserSessionFinder) applicationContext.getBean("cuba_UserSessions");
session = sessionFinder.get(securityContext.getSessionId());
if (session != null) {
user = session.getUser().getLogin();
}
}
}
}
if (user != null) {
MDC.put(USER, "/" + user);
}
} else {
MDC.remove(USER);
}
}
String applicationProp = AppContext.getProperty("cuba.logAppName");
if (applicationProp == null || Boolean.valueOf(applicationProp)) {
if (securityContext != null) {
MDC.put(APPLICATION, "/" + AppContext.getProperty("cuba.webContextName"));
} else {
MDC.remove(APPLICATION);
}
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class FoldersServiceBean method checkImportPermissions.
protected void checkImportPermissions(Folder folder) {
UserSession userSession = userSessionSource.getUserSession();
if (folder instanceof SearchFolder) {
SearchFolder searchFolder = (SearchFolder) folder;
User currentUser = userSession.getCurrentOrSubstitutedUser();
if (searchFolder.getUser() != null && !currentUser.equals(searchFolder.getUser())) {
throw new AccessDeniedException(PermissionType.ENTITY_OP, Folder.class.getSimpleName());
}
if (searchFolder.getUser() == null && !userSession.isSpecificPermitted("cuba.gui.searchFolder.global")) {
throw new AccessDeniedException(PermissionType.ENTITY_OP, Folder.class.getSimpleName());
}
}
if (folder instanceof AppFolder) {
if (!userSession.isSpecificPermitted("cuba.gui.appFolder.global")) {
throw new AccessDeniedException(PermissionType.ENTITY_OP, Folder.class.getSimpleName());
}
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class ExecutionsImpl method endExecution.
public void endExecution() {
try {
Thread thread = Thread.currentThread();
if (thread.isInterrupted()) {
Thread.interrupted();
}
ExecutionContextImpl context = (ExecutionContextImpl) ExecutionContextHolder.getCurrentContext();
if (context == null) {
throw new IllegalStateException("No execution context found");
}
log.debug("End execution context: group={}, key={}", context.getGroup(), context.getKey());
UserSession userSession = userSessionSource.getUserSession();
removeExecutionContextFromUserSession(userSession, context);
context.setState(ExecutionContextImpl.State.COMPLETED);
} finally {
ExecutionContextHolder.removeContext();
}
}
Aggregations