Skip to content

Commit

Permalink
MID-3705 MID-3649 fix, also login page redirect after user is already…
Browse files Browse the repository at this point in the history
… authenticated fixed.
  • Loading branch information
1azyman committed Mar 13, 2017
1 parent c39b983 commit 89184f9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.web.page.admin.configuration.*;
import com.evolveum.midpoint.web.page.admin.reports.*;
import com.evolveum.midpoint.web.page.self.*;
import com.evolveum.midpoint.web.util.NewWindowNotifyingBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
Expand Down Expand Up @@ -274,14 +275,7 @@ public PageBase(PageParameters parameters) {

MidPointAuthWebSession.getSession().setClientCustomization();

add(new AjaxNewWindowNotifyingBehavior() {

@Override
protected void onNewWindow(AjaxRequestTarget target) {
LOGGER.debug("Page version already used in different tab, refreshing page");
setResponsePage(getPageClass(), getPageParameters());
}
});
add(new NewWindowNotifyingBehavior());

initializeModel();

Expand Down Expand Up @@ -499,6 +493,8 @@ public void renderHead(IHeaderResponse response) {
// this attaches jquery.js as first header item, which is used in our
// scripts.
CoreLibrariesContributor.contribute(getApplication(), response);

// response.render(JavaScriptHeaderItem.forScript("alert(window.name);", "windowNameScript"));
}

@Override
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.evolveum.midpoint.web.component.breadcrumbs;

import com.evolveum.midpoint.web.util.NewWindowNotifyingBehavior;
import org.apache.commons.lang.Validate;
import org.apache.wicket.Component;
import org.apache.wicket.IPageFactory;
Expand All @@ -26,6 +27,7 @@
import org.apache.wicket.request.mapper.parameter.PageParameters;

import java.util.Arrays;
import java.util.List;

/**
* @author Viliam Repan (lazyman)
Expand Down Expand Up @@ -55,6 +57,12 @@ public PageParameters getParameters() {

@Override
public WebPage redirect() {
List<NewWindowNotifyingBehavior> behaviors = page.getBehaviors(NewWindowNotifyingBehavior.class);
behaviors.forEach(behavior -> page.remove(behavior));

page.add(new NewWindowNotifyingBehavior());


return page;
}

Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.RegistrationsPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;

import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
Expand Down Expand Up @@ -59,11 +60,6 @@ public class PageLogin extends PageBase {
private static final String OPERATION_LOAD_REGISTRATION_POLICY = DOT_CLASS + "loadRegistrationPolicy";

public PageLogin() {
if (SecurityUtils.getPrincipalUser() != null) {
MidPointApplication app = getMidpointApplication();
setResponsePage(app.getHomePage());
}

BookmarkablePageLink<String> link = new BookmarkablePageLink<>(ID_FORGET_PASSWORD, PageForgotPassword.class);
link.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -157,4 +153,14 @@ protected void onConfigure() {
protected void createBreadcrumb() {
//don't create breadcrumb for login page
}

@Override
protected void onBeforeRender() {
super.onBeforeRender();

if (SecurityUtils.getPrincipalUser() != null) {
MidPointApplication app = getMidpointApplication();
throw new RestartResponseException(app.getHomePage());
}
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.web.util;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.apache.wicket.ajax.AjaxNewWindowNotifyingBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebPage;

/**
* Created by lazyman on 13/03/2017.
*/
public class NewWindowNotifyingBehavior extends AjaxNewWindowNotifyingBehavior {

private static final Trace LOG = TraceManager.getTrace(NewWindowNotifyingBehavior.class);

@Override
protected void onNewWindow(AjaxRequestTarget target) {
LOG.debug("Page version already used in different tab, refreshing page");
WebPage page = (WebPage) getComponent();

page.setResponsePage(page.getPageClass(), page.getPageParameters());
}
}

0 comments on commit 89184f9

Please sign in to comment.