use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class ShibbolethDispatcher method handleException.
/**
* It first tries to catch the frequent SAMLExceptions and to ask the user to login again.
* It basically lets the user to login again without getting a RedScreen if one of the most
* frequent shibboleth error occurs. Else a RedScreen is the last option.
* @param e
* @param req
* @param resp
*/
private void handleException(Throwable e, HttpServletRequest req, HttpServletResponse resp, Translator transl) {
UserRequest ureq = new UserRequestImpl(ShibbolethDispatcher.PATH_SHIBBOLETH, req, resp);
if (e instanceof ShibbolethException) {
String userMsg = "";
int errorCode = ((ShibbolethException) e).getErrorCode();
switch(errorCode) {
case ShibbolethException.GENERAL_SAML_ERROR:
userMsg = transl.translate("error.shibboleth.generic");
break;
case ShibbolethException.UNIQUE_ID_NOT_FOUND:
userMsg = transl.translate("error.unqueid.notfound");
break;
default:
userMsg = transl.translate("error.shibboleth.generic");
break;
}
showMessage(ureq, "org.opensaml.SAMLException: " + e.getMessage(), e, userMsg, ((ShibbolethException) e).getContactPersonEmail());
return;
} else {
try {
ChiefController msgcc = MsgFactory.createMessageChiefController(ureq, new OLATRuntimeException("Error processing Shibboleth request: " + e.getMessage(), e), false);
msgcc.getWindow().dispatchRequest(ureq, true);
} catch (Throwable t) {
log.error("We're fucked up....", t);
}
}
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class ShibbolethDispatcher method authorization.
private boolean authorization(HttpServletRequest req, HttpServletResponse resp, ShibbolethAttributes shibbolethAttibutes) {
boolean authorized = false;
if (shibbolethModule.isAccessControlByAttributes()) {
if (StringHelper.containsNonWhitespace(shibbolethModule.getAttribute1()) && StringHelper.containsNonWhitespace(shibbolethModule.getAttribute1Values())) {
authorized |= authorization(shibbolethModule.getAttribute1(), shibbolethModule.getAttribute1Values(), shibbolethAttibutes);
}
if (StringHelper.containsNonWhitespace(shibbolethModule.getAttribute2()) && StringHelper.containsNonWhitespace(shibbolethModule.getAttribute2Values())) {
authorized |= authorization(shibbolethModule.getAttribute2(), shibbolethModule.getAttribute2Values(), shibbolethAttibutes);
}
} else {
authorized = true;
}
if (!authorized) {
UserRequest ureq = new UserRequestImpl(ShibbolethDispatcher.PATH_SHIBBOLETH, req, resp);
String userMsg = translator.translate("error.shibboleth.not.authorized");
ChiefController msgcc = MessageWindowController.createMessageChiefController(ureq, null, userMsg, null);
msgcc.getWindow().dispatchRequest(ureq, true);
}
return authorized;
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class GroupController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller sourceController, Event event) {
if (sourceController == tableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
// Single row selects
TableEvent te = (TableEvent) event;
String actionid = te.getActionId();
final Identity identity = identitiesTableModel.getObject(te.getRowId()).getIdentity();
if (actionid.equals(COMMAND_VCARD)) {
// get identity and open new visiting card controller in new window
ControllerCreator userInfoMainControllerCreator = new ControllerCreator() {
@Override
public Controller createController(UserRequest lureq, WindowControl lwControl) {
return new UserInfoMainController(lureq, lwControl, identity, true, false);
}
};
// wrap the content controller into a full header layout
ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, userInfoMainControllerCreator);
// open in new browser window
PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr);
pbw.open(ureq);
//
} else if (actionid.equals(COMMAND_SELECTUSER)) {
fireEvent(ureq, new SingleIdentityChosenEvent(identity));
} else if (COMMAND_IM.equals(actionid)) {
doIm(ureq, identity);
}
} else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
// Multiselect events
TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
if (tmse.getAction().equals(COMMAND_REMOVEUSER)) {
if (tmse.getSelection().isEmpty()) {
// empty selection
showWarning("msg.selectionempty");
return;
}
int size = identitiesTableModel.getObjects().size();
toRemove = identitiesTableModel.getIdentities(tmse.getSelection());
// list is never null, but can be empty
if (keepAtLeastOne && (size == 1 || size - toRemove.size() == 0)) {
// at least one must be kept
// do not delete the last one => ==1
// do not allow to delete all => size - selectedCnt == 0
showError("msg.atleastone");
} else {
// valid selection to be deleted.
if (removeUserMailDefaultTempl == null) {
doBuildConfirmDeleteDialog(ureq);
} else {
removeAsListenerAndDispose(removeUserMailCtr);
removeUserMailCtr = new MailNotificationEditController(getWindowControl(), ureq, removeUserMailDefaultTempl, true, false, true);
listenTo(removeUserMailCtr);
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), translate("close"), removeUserMailCtr.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
}
}
}
} else if (sourceController == removeUserMailCtr) {
if (event == Event.DONE_EVENT) {
removeUserMailCustomTempl = removeUserMailCtr.getMailTemplate();
cmc.deactivate();
doBuildConfirmDeleteDialog(ureq);
} else {
cmc.deactivate();
}
} else if (sourceController == usc) {
if (event == Event.CANCELLED_EVENT) {
cmc.deactivate();
} else {
if (event instanceof SingleIdentityChosenEvent) {
SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
Identity choosenIdentity = singleEvent.getChosenIdentity();
if (choosenIdentity == null) {
showError("msg.selectionempty");
return;
}
toAdd = new ArrayList<Identity>();
toAdd.add(choosenIdentity);
} else if (event instanceof MultiIdentityChosenEvent) {
MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
toAdd = multiEvent.getChosenIdentities();
if (toAdd.size() == 0) {
showError("msg.selectionempty");
return;
}
} else {
throw new RuntimeException("unknown event ::" + event.getCommand());
}
if (toAdd.size() == 1) {
// check if already in group [makes only sense for a single choosen identity]
if (groupDao.hasRole(group, toAdd.get(0), role)) {
String fullName = userManager.getUserDisplayName(toAdd.get(0));
getWindowControl().setInfo(translate("msg.subjectalreadyingroup", new String[] { fullName }));
return;
}
} else if (toAdd.size() > 1) {
// check if already in group
List<Identity> alreadyInGroup = new ArrayList<Identity>();
for (int i = 0; i < toAdd.size(); i++) {
if (groupDao.hasRole(group, toAdd.get(i), role)) {
tableCtr.setMultiSelectSelectedAt(i, false);
alreadyInGroup.add(toAdd.get(i));
}
}
if (!alreadyInGroup.isEmpty()) {
StringBuilder names = new StringBuilder();
for (Identity ident : alreadyInGroup) {
if (names.length() > 0)
names.append(", ");
names.append(userManager.getUserDisplayName(ident));
toAdd.remove(ident);
}
getWindowControl().setInfo(translate("msg.subjectsalreadyingroup", names.toString()));
}
if (toAdd.isEmpty()) {
return;
}
}
// in both cases continue adding the users or asking for the mail
// template if available (=not null)
cmc.deactivate();
if (addUserMailDefaultTempl == null) {
doAddIdentitiesToGroup(ureq, toAdd, null);
} else {
removeAsListenerAndDispose(addUserMailCtr);
addUserMailCtr = new MailNotificationEditController(getWindowControl(), ureq, addUserMailDefaultTempl, true, mandatoryEmail, true);
listenTo(addUserMailCtr);
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), translate("close"), addUserMailCtr.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
}
// in any case cleanup this controller, not used anymore
usc.dispose();
usc = null;
} else if (sourceController == addUserMailCtr) {
if (event == Event.DONE_EVENT) {
MailTemplate customTemplate = addUserMailCtr.getMailTemplate();
doAddIdentitiesToGroup(ureq, toAdd, customTemplate);
cmc.deactivate();
} else if (event == Event.CANCELLED_EVENT) {
cmc.deactivate();
} else {
throw new RuntimeException("unknown event ::" + event.getCommand());
}
} else if (sourceController == confirmDelete) {
if (DialogBoxUIFactory.isYesEvent(event)) {
// before deleting, assure it is allowed
if (!mayModifyMembers)
throw new AssertException("not allowed to remove member!");
// list is never null, but can be empty
// TODO: Theoretically it can happen that the table model here is not accurate!
// the 'keep at least one' should be handled by the security manager that should
// synchronizes the method on the group
int size = identitiesTableModel.getObjects().size();
if (keepAtLeastOne && (size - toRemove.size() == 0)) {
showError("msg.atleastone");
} else {
doRemoveIdentitiesFromGroup(ureq, toRemove, removeUserMailCustomTempl);
}
}
} else if (sourceController == userToGroupWizard) {
if (event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
getWindowControl().pop();
removeAsListenerAndDispose(userToGroupWizard);
userToGroupWizard = null;
if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
reloadData();
}
}
}
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class STCourseNode method createNodeRunConstructionResult.
/**
* @see org.olat.course.nodes.CourseNode#createNodeRunConstructionResult(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.WindowControl,
* org.olat.course.run.userview.UserCourseEnvironment,
* org.olat.course.run.userview.NodeEvaluation)
*/
@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, final UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
updateModuleConfigDefaults(false);
Controller cont;
String displayType = getModuleConfiguration().getStringValue(STCourseNodeEditController.CONFIG_KEY_DISPLAY_TYPE);
String relPath = STCourseNodeEditController.getFileName(getModuleConfiguration());
if (relPath != null && displayType.equals(STCourseNodeEditController.CONFIG_VALUE_DISPLAY_FILE)) {
// we want a user chosen overview, so display the chosen file from the
// material folder, otherwise display the normal overview
// reuse the Run controller from the "Single Page" building block, since
// we need to do exactly the same task
Boolean allowRelativeLinks = getModuleConfiguration().getBooleanEntry(STCourseNodeEditController.CONFIG_KEY_ALLOW_RELATIVE_LINKS);
if (allowRelativeLinks == null) {
allowRelativeLinks = Boolean.FALSE;
}
DeliveryOptions deliveryOptions = (DeliveryOptions) getModuleConfiguration().get(SPEditController.CONFIG_KEY_DELIVERYOPTIONS);
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.class, userCourseEnv.getCourseEnvironment().getCourseResourceableId());
SinglePageController spCtr = new SinglePageController(ureq, wControl, userCourseEnv.getCourseEnvironment().getCourseFolderContainer(), relPath, allowRelativeLinks.booleanValue(), null, ores, deliveryOptions, userCourseEnv.getCourseEnvironment().isPreview());
// check if user is allowed to edit the page in the run view
CourseGroupManager cgm = userCourseEnv.getCourseEnvironment().getCourseGroupManager();
boolean hasEditRights = (cgm.isIdentityCourseAdministrator(ureq.getIdentity()) || cgm.hasRight(ureq.getIdentity(), CourseRights.RIGHT_COURSEEDITOR)) || (getModuleConfiguration().getBooleanSafe(SPEditController.CONFIG_KEY_ALLOW_COACH_EDIT, false) && cgm.isIdentityCourseCoach(ureq.getIdentity()));
if (hasEditRights) {
spCtr.allowPageEditing();
// set the link tree model to internal for the HTML editor
CustomLinkTreeModel linkTreeModel = new CourseInternalLinkTreeModel(userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode());
spCtr.setInternalLinkTreeModel(linkTreeModel);
}
spCtr.addLoggingResourceable(LoggingResourceable.wrap(this));
// create clone wrapper layout, allow popping into second window
CloneLayoutControllerCreatorCallback clccc = new CloneLayoutControllerCreatorCallback() {
@Override
public ControllerCreator createLayoutControllerCreator(final UserRequest uureq, final ControllerCreator contentControllerCreator) {
return BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(uureq, new ControllerCreator() {
@Override
public Controller createController(UserRequest lureq, WindowControl lwControl) {
// wrap in column layout, popup window needs a layout controller
Controller ctr = contentControllerCreator.createController(lureq, lwControl);
LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(lureq, lwControl, ctr);
layoutCtr.setCustomCSS(CourseFactory.getCustomCourseCss(lureq.getUserSession(), userCourseEnv.getCourseEnvironment()));
Controller wrappedCtrl = TitledWrapperHelper.getWrapper(lureq, lwControl, ctr, STCourseNode.this, ICON_CSS_CLASS);
layoutCtr.addDisposableChildController(wrappedCtrl);
return layoutCtr;
}
});
}
};
Controller wrappedCtrl = TitledWrapperHelper.getWrapper(ureq, wControl, spCtr, this, ICON_CSS_CLASS);
if (wrappedCtrl instanceof CloneableController) {
cont = new CloneController(ureq, wControl, (CloneableController) wrappedCtrl, clccc);
} else {
throw new AssertException("Need to be a cloneable");
}
} else {
// evaluate the score accounting for this node. this uses the score accountings local
// cache hash map to reduce unnecessary calculations
ScoreEvaluation se = userCourseEnv.getScoreAccounting().evalCourseNode(this);
cont = TitledWrapperHelper.getWrapper(ureq, wControl, new STCourseNodeRunController(ureq, wControl, userCourseEnv, this, se, ne), this, ICON_CSS_CLASS);
}
// displayed in the ST-Runcontroller
return new NodeRunConstructionResult(cont);
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class TrueFalseEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout("metadata", getTranslator());
if (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop) {
metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_draganddrop");
} else {
metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_match");
}
metadata.setRootForm(mainForm);
formLayout.add(metadata);
formLayout.add("metadata", metadata);
titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), metadata);
titleEl.setElementCssClass("o_sel_assessment_item_title");
titleEl.setMandatory(true);
titleEl.setEnabled(!readOnly);
String description = itemBuilder.getQuestion();
textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", description, 8, -1, itemContainer, metadata, ureq.getUserSession(), getWindowControl());
textEl.setEnabled(!readOnly);
textEl.setVisible(!readOnly);
if (readOnly) {
FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
textReadOnlyEl.setLabel("form.imd.descr", null);
textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
textReadOnlyEl.setMapperUri(mapperUri);
metadata.add(textReadOnlyEl);
}
// responses
String page = velocity_root + "/match_truefalse.html";
answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
answersCont.setRootForm(mainForm);
answersCont.contextPut("showHeaders", (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop));
formLayout.add(answersCont);
formLayout.add("answers", answersCont);
MatchInteraction interaction = itemBuilder.getMatchInteraction();
if (interaction != null) {
List<SimpleAssociableChoice> sourceChoices = itemBuilder.getSourceChoices();
for (SimpleAssociableChoice sourceChoice : sourceChoices) {
wrapSource(ureq, sourceChoice, sourceWrappers);
}
List<TargetWrapper> targetChoices = itemBuilder.getTargetChoices().stream().map(c -> new TargetWrapper(c)).collect(Collectors.toList());
answersCont.contextPut("targetChoices", targetChoices);
}
answersCont.contextPut("sourceChoices", sourceWrappers);
answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
answersCont.contextPut("responseIdentifier", itemBuilder.getResponseIdentifier());
int maxAssociations = itemBuilder.getMatchInteraction().getMaxAssociations();
answersCont.contextPut("interactionMaxAssociations", maxAssociations);
JSAndCSSFormItem js = new JSAndCSSFormItem("js", new String[] { "js/jquery/qti/jquery.match.js" });
formLayout.add(js);
if (!readOnly) {
uifactory.addFormSubmitButton("submit", answersCont);
}
if (!restrictedEdit && !readOnly) {
addRowButton = uifactory.addFormLink("add.match.row", answersCont, Link.BUTTON);
addRowButton.setElementCssClass("o_sel_match_add_row");
addRowButton.setIconLeftCSS("o_icon o_icon_add");
}
}
Aggregations