use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.
the class WebPrismUtil method createAcquition.
public static ProvenanceAcquisitionType createAcquition() {
MidPointApplication app = MidPointApplication.get();
ProvenanceAcquisitionType acquisitionType = new ProvenanceAcquisitionType(app.getPrismContext());
GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
if (principal != null) {
FocusType focus = principal.getFocus();
if (focus != null) {
acquisitionType.setActorRef(ObjectTypeUtil.createObjectRef(focus, app.getPrismContext()));
}
}
acquisitionType.setChannel(GuiChannel.USER.getUri());
acquisitionType.setTimestamp(app.getClock().currentTimeXMLGregorianCalendar());
return acquisitionType;
}
use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.
the class UserMenuPanel method loadJpegPhotoModel.
private IModel<AbstractResource> loadJpegPhotoModel() {
return new ReadOnlyModel<>(() -> {
GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
if (principal == null) {
return null;
}
CompiledGuiProfile profile = principal.getCompiledGuiProfile();
byte[] jpegPhoto = profile.getJpegPhoto();
if (jpegPhoto == null) {
URL placeholder = UserMenuPanel.class.getClassLoader().getResource("static/img/placeholder.png");
if (placeholder == null) {
return null;
}
try {
jpegPhoto = IOUtils.toByteArray(placeholder);
} catch (IOException e) {
LOGGER.error("Cannot load placeholder for photo.");
return null;
}
}
return new ByteArrayResource("image/jpeg", jpegPhoto);
});
}
use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.
the class TaskOperationalButtonsPanel method setupOwner.
private void setupOwner(PrismObjectWrapper<TaskType> taskWrapper) throws SchemaException {
PrismReferenceWrapper<Referencable> taskOwner = taskWrapper.findReference(ItemPath.create(TaskType.F_OWNER_REF));
if (taskOwner == null) {
return;
}
PrismReferenceValueWrapperImpl<Referencable> taskOwnerValue = taskOwner.getValue();
if (taskOwnerValue == null) {
return;
}
if (taskOwnerValue.getNewValue() == null || taskOwnerValue.getNewValue().isEmpty()) {
GuiProfiledPrincipal guiPrincipal = AuthUtil.getPrincipalUser();
if (guiPrincipal == null) {
// BTW something very strange must happened
return;
}
FocusType focus = guiPrincipal.getFocus();
taskOwnerValue.setRealValue(ObjectTypeUtil.createObjectRef(focus, SchemaConstants.ORG_DEFAULT));
}
}
use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.
the class WebComponentUtil method getLocale.
public static <F extends FocusType> Locale getLocale() {
MidPointPrincipal principal = AuthUtil.getPrincipalUser();
if (principal == null) {
return MidPointApplication.getDefaultLocale();
}
Locale locale = null;
if (principal instanceof GuiProfiledPrincipal && ((GuiProfiledPrincipal) principal).getCompiledGuiProfile().getLocale() != null) {
locale = ((GuiProfiledPrincipal) principal).getCompiledGuiProfile().getLocale();
} else {
F focus = (F) principal.getFocus();
if (focus == null) {
return MidPointApplication.getDefaultLocale();
}
String prefLang = focus.getPreferredLanguage();
if (StringUtils.isBlank(prefLang)) {
prefLang = focus.getLocale();
}
try {
locale = LocaleUtils.toLocale(prefLang);
} catch (Exception ex) {
LOGGER.debug("Error occurred while getting user locale, " + ex.getMessage());
}
}
if (locale == null) {
if (ThreadContext.getSession() == null) {
return MidPointApplication.getDefaultLocale();
}
locale = Session.get().getLocale();
}
if (MidPointApplication.containsLocale(locale)) {
return locale;
}
return MidPointApplication.getDefaultLocale();
}
use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.
the class WebModelServiceUtils method getTimezone.
public static TimeZone getTimezone() {
GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
if (principal == null) {
return null;
}
FocusType focus = principal.getFocus();
String timeZone;
if (focus == null || StringUtils.isEmpty(focus.getTimezone())) {
timeZone = principal.getCompiledGuiProfile().getDefaultTimezone();
} else {
timeZone = focus.getTimezone();
}
if (timeZone == null) {
return null;
}
try {
return TimeZone.getTimeZone(timeZone);
} catch (Exception ex) {
LOGGER.debug("Error occurred while getting user time zone, " + ex.getMessage());
return null;
}
}
Aggregations