use of org.olat.core.gui.media.RedirectMediaResource in project openolat by klemens.
the class DefaultMinimalTopNavController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == closeLink) {
// close window (a html page which calls Window.close onLoad
ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(StaticMediaDispatcher.createStaticURIFor("closewindow.html")));
// release all resources and close window
WindowBackOffice wbo = getWindowControl().getWindowBackOffice();
Window w = wbo.getWindow();
Windows.getWindows(ureq).deregisterWindow(w);
wbo.dispose();
}
}
use of org.olat.core.gui.media.RedirectMediaResource in project openolat by klemens.
the class HtmlStaticPageComponent method getAsyncMediaResource.
/**
* @see org.olat.core.gui.media.AsyncMediaResponsible#getAsyncMediaResource(org.olat.core.gui.UserRequest)
*/
public MediaResource getAsyncMediaResource(UserRequest ureq) {
// is the path to the desired resource (put together by the webbrowser by
// combining latesturl and relative link)
String moduleURI = ureq.getModuleURI();
MediaResource mr = null;
if (moduleURI != null) {
// 1. check for an olat command (special link to indicate a command)
if (moduleURI.startsWith(OLAT_CMD_PREFIX)) {
String cmdAndSub = moduleURI.substring(OLAT_CMD_PREFIX.length());
int slpos = cmdAndSub.indexOf('/');
if (slpos != -1) {
String cmd = cmdAndSub.substring(0, slpos);
String subcmd = cmdAndSub.substring(slpos + 1);
OlatCmdEvent aev = new OlatCmdEvent(cmd, subcmd);
fireEvent(ureq, aev);
// Mediaresourse)
if (aev.isAccepted())
return null;
}
// else ignore (syntax error in command
}
// make sure moduleURI does not contain ".." or such (hack attempt)
// -> ok, userrequest class asserts this.
VFSItem sourceItem = rootContainer.resolve(moduleURI);
// return 404 if the requested file does not exist
if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
return new NotFoundMediaResource();
}
// we know the file exists.
boolean checkRegular = true;
// check for special case: render the follwing link in a new (server) window and all following clicks as well
if ((ureq.getParameter("olatsite") != null) || ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") != null))) {
log.debug("moduleURI=" + moduleURI);
ExternalSiteEvent ese = new ExternalSiteEvent(moduleURI);
fireEvent(ureq, ese);
if (ese.isAccepted()) {
mr = ese.getResultingMediaResource();
log.debug("ExternalSiteEvent is accepted");
checkRegular = false;
} else {
// it is a html page with olatraw parameter => redirect to mapper
Mapper mapper = new HtmlStaticMapper(rootContainer);
// NOTE: do not deregister this mapper, since it could be used a lot later (since it is opened in a new browser window)
// Register mapper as cacheable
String mapperID = VFSManager.getRealPath(rootContainer);
if (mapperID == null) {
// Can't cache mapper, no cacheable context available
amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapper);
} else {
// Add classname to the file path to remove conflicts with other
// usages of the same file path
mapperID = this.getClass().getSimpleName() + ":" + mapperID;
amapPath = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapperID, mapper);
}
String path = amapPath.getUrl() + "/" + moduleURI;
ese.setResultingMediaResource(new RedirectMediaResource(path));
if (log.isDebug())
log.debug("RedirectMediaResource=" + path);
ese.accept();
mr = ese.getResultingMediaResource();
checkRegular = false;
}
}
if (checkRegular) {
// mediaresource (raw inputstream)
if ((moduleURI.endsWith(".html") || moduleURI.endsWith(".htm")) && (ureq.getParameter("olatraw") == null)) {
// we remember what to render inline later and return null to indicate
// inline rendering
currentURI = moduleURI;
getFileContent((VFSLeaf) sourceItem);
fireEvent(ureq, new NewInlineUriEvent(currentURI));
} else {
// it is indeed an image or such -> serve it
mr = new VFSMediaResource((VFSLeaf) sourceItem);
}
}
}
// -> do a normal inline rendering (reload)
return mr;
}
use of org.olat.core.gui.media.RedirectMediaResource in project openolat by klemens.
the class OAuthDispatcher method execute.
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uri = request.getRequestURI();
try {
uri = URLDecoder.decode(uri, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new AssertException("UTF-8 encoding not supported!!!!");
}
String uriPrefix = DispatcherModule.getLegacyUriPrefix(request);
uri = uri.substring(uriPrefix.length());
UserRequest ureq = null;
try {
// upon creation URL is checked for
ureq = new UserRequestImpl(uriPrefix, request, response);
} catch (NumberFormatException nfe) {
if (log.isDebug()) {
log.debug("Bad Request " + request.getPathInfo());
}
DispatcherModule.sendBadRequest(request.getPathInfo(), response);
return;
}
String error = request.getParameter("error");
if (null != error) {
error(ureq, translateOauthError(ureq, error));
return;
}
String problem = request.getParameter("oauth_problem");
if (problem != null && "token_rejected".equals(problem.trim())) {
error(ureq, translateOauthError(ureq, error));
return;
}
try {
HttpSession sess = request.getSession();
// OAuth 2.0 hasn't any request token
Token requestToken = (Token) sess.getAttribute(OAuthConstants.REQUEST_TOKEN);
OAuthService service = (OAuthService) sess.getAttribute(OAuthConstants.OAUTH_SERVICE);
OAuthSPI provider = (OAuthSPI) sess.getAttribute(OAuthConstants.OAUTH_SPI);
Token accessToken;
if (provider == null) {
log.audit("OAuth Login failed, no provider in request");
DispatcherModule.redirectToDefaultDispatcher(response);
return;
} else if (provider.isImplicitWorkflow()) {
String idToken = ureq.getParameter("id_token");
if (idToken == null) {
redirectImplicitWorkflow(ureq);
return;
} else {
Verifier verifier = OpenIDVerifier.create(ureq, sess);
accessToken = service.getAccessToken(requestToken, verifier);
}
} else {
String requestVerifier = request.getParameter("oauth_verifier");
if (requestVerifier == null) {
// OAuth 2.0 as a code
requestVerifier = request.getParameter("code");
}
accessToken = service.getAccessToken(requestToken, new Verifier(requestVerifier));
}
OAuthUser infos = provider.getUser(service, accessToken);
if (infos == null || !StringHelper.containsNonWhitespace(infos.getId())) {
error(ureq, translate(ureq, "error.no.id"));
log.error("OAuth Login failed, no infos extracted from access token: " + accessToken);
return;
}
OAuthRegistration registration = new OAuthRegistration(provider.getProviderName(), infos);
login(infos, registration);
if (provider instanceof OAuthUserCreator) {
Identity newIdentity;
OAuthUserCreator userCreator = (OAuthUserCreator) provider;
if (registration.getIdentity() == null) {
newIdentity = userCreator.createUser(infos);
} else {
newIdentity = userCreator.updateUser(infos, registration.getIdentity());
}
if (newIdentity != null) {
registration.setIdentity(newIdentity);
}
}
if (registration.getIdentity() == null) {
if (CoreSpringFactory.getImpl(OAuthLoginModule.class).isAllowUserCreation()) {
register(request, response, registration);
} else {
error(ureq, translate(ureq, "error.account.creation"));
log.error("OAuth Login ok but the user has not an account on OpenOLAT: " + infos);
}
} else {
if (ureq.getUserSession() != null) {
// re-init the activity logger
ThreadLocalUserActivityLoggerInstaller.initUserActivityLogger(request);
}
Identity identity = registration.getIdentity();
int loginStatus = AuthHelper.doLogin(identity, provider.getProviderName(), ureq);
if (loginStatus != AuthHelper.LOGIN_OK) {
if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
DispatcherModule.redirectToServiceNotAvailable(response);
} else {
// error, redirect to login screen
DispatcherModule.redirectToDefaultDispatcher(response);
}
} else {
// update last login date and register active user
UserDeletionManager.getInstance().setIdentityAsActiv(identity);
MediaResource mr = ureq.getDispatchResult().getResultingMediaResource();
if (mr instanceof RedirectMediaResource) {
RedirectMediaResource rmr = (RedirectMediaResource) mr;
rmr.prepare(response);
} else {
// error, redirect to login screen
DispatcherModule.redirectToDefaultDispatcher(response);
}
}
}
} catch (Exception e) {
log.error("Unexpected error", e);
error(ureq, translate(ureq, "error.generic"));
}
}
Aggregations