Skip to content

Commit

Permalink
fixing MID-1976 (dennyAll-like action for development pages)
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Jul 21, 2014
1 parent 39877bf commit 596ff21
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 12 deletions.
Expand Up @@ -185,11 +185,28 @@ private void scanPackagesForPages(List<String> packages, MidPointApplication app
private void loadActions(PageDescriptor descriptor) {
for (String url : descriptor.url()) {
List<AuthorizationActionValue> actions = new ArrayList<>();

//avoid of setting guiAll authz for "public" pages (e.g. login page)
if (descriptor.action() == null || descriptor.action().length == 0){
return;
}

boolean canAccess = true;

for (AuthorizationAction action : descriptor.action()) {
actions.add(new AuthorizationActionValue(action.actionUri(), action.label(), action.description()));
if (AuthorizationConstants.AUTZ_NO_ACCESS_URL.equals(action.actionUri())){
canAccess = false;
break;
}
}
actions.add(new AuthorizationActionValue(AuthorizationConstants.AUTZ_GUI_ALL_URI,

//add http://.../..#guAll authorization only for displayable pages, not for pages used for development..
if (canAccess){

actions.add(new AuthorizationActionValue(AuthorizationConstants.AUTZ_GUI_ALL_URI,
AuthorizationConstants.AUTZ_GUI_ALL_LABEL, AuthorizationConstants.AUTZ_GUI_ALL_DESCRIPTION));
}
this.actions.put(url, actions.toArray(new DisplayableValue[actions.size()]));
}
}
Expand Down
Expand Up @@ -31,7 +31,7 @@
/**
* @author lazyman
*/
@PageDescriptor(url = "/admin/test", action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_DEVEL_URL)})
@PageDescriptor(url = "/admin/test", action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_NO_ACCESS_URL)})
public class PageTest extends PageBase {

public PageTest() {
Expand Down
Expand Up @@ -33,7 +33,7 @@
*
* @author shood
*/
@PageDescriptor(url = "/capability", action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_DEVEL_URL)})
@PageDescriptor(url = "/capability", action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_NO_ACCESS_URL)})
public class PageTest2 extends PageBase {

private static final String ID_CAPABILITY = "capability";
Expand Down
Expand Up @@ -37,7 +37,7 @@
// label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION),
// @AuthorizationAction(actionUri = AuthorizationConstants.NS_AUTHORIZATION + "#bulkAction",
// label = "PageBulkAction.auth.bulkAction.label", description = "PageBulkAction.auth.bulkAction.description")
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_DEVEL_URL)
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_NO_ACCESS_URL)
})
public class PageBulkAction extends PageAdminConfiguration {

Expand Down
Expand Up @@ -44,7 +44,7 @@
// PageAdminResources.AUTHORIZATION_RESOURCE_ALL,
// AuthorizationConstants.NS_AUTHORIZATION + "#resourceWizard"})
@PageDescriptor(url = "/admin/resources/wizard",
action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_DEVEL_URL)})
action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_NO_ACCESS_URL)})
public class PageResourceWizard extends PageAdminResources {

private static final String ID_WIZARD = "wizard";
Expand Down
Expand Up @@ -35,7 +35,7 @@
* @author lazyman
*/
@PageDescriptor(url = "/admin/resources/content/entitlements", encoder = OnePageParameterEncoder.class, action = {
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_DEVEL_URL)})
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_NO_ACCESS_URL)})
public class PageContentEntitlements extends PageAdminResources {

private IModel<PrismObject<ResourceType>> resourceModel;
Expand Down
Expand Up @@ -25,7 +25,7 @@
/**
* @author lazyman
*/
@PageDescriptor(url = "/admin/users/find", action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_DEVEL_URL)})
@PageDescriptor(url = "/admin/users/find", action = {@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_NO_ACCESS_URL)})
public class PageFindUsers extends PageAdminUsers {

private static final Trace LOGGER = TraceManager.getTrace(PageFindUsers.class);
Expand Down
Expand Up @@ -16,12 +16,15 @@

package com.evolveum.midpoint.web.page.login;

import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.menu.top.LocalePanel;
import com.evolveum.midpoint.web.component.menu.top.TopMenuBar;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.page.admin.home.PageDashboard;
import com.evolveum.midpoint.web.security.MidPointAuthWebSession;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.RequiredTextField;
Expand Down
Expand Up @@ -118,7 +118,7 @@ public void decide(Authentication authentication, Object object, Collection<Conf
addSecurityConfig(filterInvocation, guiConfigAttr, entry.getKey(), entry.getValue());
}

if (configAttributes == null && guiConfigAttr.isEmpty()) {
if (configAttributes == null || guiConfigAttr.isEmpty()) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions gui/admin-gui/src/main/webapp/WEB-INF/ctx-web-security.xml
Expand Up @@ -39,9 +39,10 @@ http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<intercept-url pattern="/j_spring_security_check" />
<intercept-url pattern="/spring_security_login" />

<intercept-url pattern="/login" />
<intercept-url pattern="/login"/>

<intercept-url pattern="/bootstrap" />


<intercept-url pattern="/admin/**" access="isFullyAuthenticated()"/> <!-- access="isAuthenticated()"/> -->

Expand All @@ -54,7 +55,7 @@ http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<!-- <custom-filter position="PRE_AUTH_FILTER" ref="requestHeaderAuthenticationFilter" /> -->

<form-login login-page="/login" default-target-url="/home" />

<intercept-url pattern="/**" access="isFullyAuthenticated()"/>
</http>

<beans:bean id="accessDecisionManager" class="com.evolveum.midpoint.web.security.MidPointGuiAuthorizationEvaluator">
Expand Down
Expand Up @@ -36,8 +36,8 @@ public class AuthorizationConstants {
public static final QName AUTZ_ALL_QNAME = new QName(NS_AUTHORIZATION, "all");
public static final String AUTZ_ALL_URL = QNameUtil.qNameToUri(AUTZ_ALL_QNAME);

public static final QName AUTZ_DEVEL_QNAME = new QName(NS_AUTHORIZATION, "devel");
public static final String AUTZ_DEVEL_URL = NS_AUTHORIZATION + "#devel";
// public static final QName AUTZ_DEVEL_QNAME = new QName(NS_AUTHORIZATION, "devel");
public static final String AUTZ_NO_ACCESS_URL = NS_AUTHORIZATION + "#noAccess";
// public static final String AUTZ_DEVEL_URL = QNameUtil.qNameToUri(AUTZ_DEVEL_QNAME);

public static final QName AUTZ_DENY_ALL_QNAME = new QName(NS_AUTHORIZATION, "denyAll");
Expand Down
Expand Up @@ -168,6 +168,11 @@ public <O extends ObjectType, T extends ObjectType> boolean isAuthorized(String
private <O extends ObjectType, T extends ObjectType> boolean isAuthorizedInternal(MidPointPrincipal midPointPrincipal, String operationUrl, AuthorizationPhaseType phase,
PrismObject<O> object, ObjectDelta<O> delta, PrismObject<T> target, OwnerResolver ownerResolver)
throws SchemaException {

if (AuthorizationConstants.AUTZ_NO_ACCESS_URL.equals(operationUrl)){
return false;
}

if (phase == null) {
throw new IllegalArgumentException("No phase");
}
Expand All @@ -181,6 +186,7 @@ private <O extends ObjectType, T extends ObjectType> boolean isAuthorizedInterna
if (authority instanceof Authorization) {
Authorization autz = (Authorization)authority;
LOGGER.trace("Evaluating authorization {}", autz);

// First check if the authorization is applicable.

// action
Expand Down

0 comments on commit 596ff21

Please sign in to comment.