Example usage for org.apache.wicket.authorization Action getName

List of usage examples for org.apache.wicket.authorization Action getName

Introduction

In this page you can find the example usage for org.apache.wicket.authorization Action getName.

Prototype

public String getName() 

Source Link

Usage

From source file:au.org.theark.security.CustomAuthorizationStrategy.java

License:Open Source License

public boolean isActionAuthorized(final Component component, final Action action) {

    ShiroAction _action = (action.getName().equals(Action.RENDER)) ? ShiroAction.RENDER : ShiroAction.ENABLE;

    Class<? extends Component> clazz = component.getClass();

    SecurityConstraint fail = checkInvalidInstantiation(clazz.getAnnotations(), _action);
    if (fail == null) {
        fail = checkInvalidInstantiation(clazz.getPackage().getAnnotations(), _action);
    }//ww  w  . ja va  2s. c o  m
    return fail == null;
}

From source file:de.inren.frontend.application.security.InRenAuthorizationStrategy.java

License:Apache License

@Override
public boolean isActionAuthorized(Component component, Action action) {

    if (!(SecuredPage.class.isAssignableFrom(component.getClass()))) {
        return true;
    }/* w ww .  j a  v a2s. c  om*/
    log.info("isActionAuthorized : " + component.getPath() + " action:" + action.getName());
    for (ComponentAccess componentAccess : componentAccessService.getComponentAccessList()) {

        if (component.getClass().getSimpleName().equalsIgnoreCase(componentAccess.getName())) {
            log.info("Found componentAccess=" + componentAccess);
            BasicAuthenticationSession s = ((BasicAuthenticationSession) Session.get());
            User u = s.getUser();
            log.info("User u=" + u);
            if (u != null) {
                log.info("user rights are: " + u.getGrantedRoles());
                Role role = hasRole(u.getGrantedRoles(), componentAccess.getGrantedRoles());
                log.info("role check result = " + role);

                if (isActionAllowed(action, role)) {
                    return true;
                }
            }
        }
    }
    // TODO nur Test
    return false;
}

From source file:de.inren.frontend.application.security.InRenAuthorizationStrategy.java

License:Apache License

private boolean isActionAllowed(Action action, Role role) {
    for (Right right : role.getRights()) {
        if (right.getName().equalsIgnoreCase(action.getName())) {
            return true;
        }/*from w w w  . ja  va  2  s  . c  o m*/
    }
    return false;
}

From source file:eu.uqasar.auth.strategies.annotation.AnnotationBasedAuthorizationStrategy.java

License:Apache License

/**
 * @param action//from   w ww .  j  ava  2  s  . com
 *            The action to check
 * @param authorizeActionAnnotation
 *            The annotations information
 * @return False if the action is not authorized
 */
private boolean check(final Action action, final AuthorizeAction authorizeActionAnnotation) {
    if (authorizeActionAnnotation != null) {
        if (action.getName().equals(authorizeActionAnnotation.action())) {
            Role[] deniedRoles = authorizeActionAnnotation.deny();
            if ((!isEmpty(deniedRoles)) && hasAny(deniedRoles)) {
                return false;
            }

            Role[] acceptedRoles = authorizeActionAnnotation.roles();
            if (!(isEmpty(acceptedRoles) || hasAny(acceptedRoles))) {
                return false;
            }
        }
    }
    return true;
}

From source file:org.cast.isi.ISIAnnotationsRoleAuthorizationStrategy.java

License:Open Source License

/**
 * @param action/*from ww  w .  ja  v  a  2 s.com*/
 *            The action to check
 * @param authorizeActionAnnotation
 *            The annotations information
 * @return False if the action is not authorized
 */
private boolean check(final Action action, final AuthorizeAction authorizeActionAnnotation) {
    if (authorizeActionAnnotation != null) {
        if (action.getName().equals(authorizeActionAnnotation.action())) {
            // The following 3 lines are the fix
            Roles deniedRoles = new Roles(authorizeActionAnnotation.deny());
            deniedRoles.remove(""); // If deny annotation is not present, deny() will have incorrectly returned "".
            if (isEmpty(deniedRoles) == false && hasAny(deniedRoles)) {
                return false;
            }

            Roles roles = new Roles(authorizeActionAnnotation.roles());
            if (!(isEmpty(roles) || hasAny(roles))) {
                return false;
            }
        }
    }
    return true;
}

From source file:org.devproof.portal.core.app.PortalSession.java

License:Apache License

private boolean evaluateSecuredAnnotation(Class<?> clazz, Action action) {
    // if the user do not have the right when page is annotated with @Secured, he is not allowed to visit
    // page with this annotation is always protected
    Secured secured = getSecuredAnnotation(clazz);
    if (action != null && !secured.action().equals(action.getName())) {
        return true;
    }/*from  w  w  w .  j  a  v a  2s. c  om*/
    for (String right : secured.value()) {
        if (hasRight(right)) {
            return true;
        }
    }
    return false;
}

From source file:org.openengsb.ui.common.DomainAuthorizationStrategy.java

License:Apache License

@Override
public boolean isActionAuthorized(Component arg0, Action arg1) {
    List<SecurityAttributeEntry> attributeList = Lists.newArrayList();
    if (hasSecurityAnnotation(arg0.getClass())) {
        attributeList.addAll(getSecurityAttributes(arg0.getClass()));
    }//from ww w . j a v  a2s. c o m

    LOGGER.info(ArrayUtils.toString(attributeProviders.getClass().getInterfaces()));

    for (SecurityAttributeProvider p : attributeProviders) {
        Collection<SecurityAttributeEntry> runtimeAttributes = p.getAttribute(arg0);
        if (runtimeAttributes != null) {
            attributeList.addAll(runtimeAttributes);
        }
    }

    if (attributeList.isEmpty()) {
        return true;
    }

    String user = getAuthenticatedUser();
    if (user == null) {
        return false;
    }
    UIAction secureAction = new UIAction(attributeList, arg1.getName(),
            ImmutableMap.of("component", (Object) arg0));

    Access checkAccess = authorizer.checkAccess(user, secureAction);
    if (checkAccess != Access.GRANTED) {
        LOGGER.warn("User {} was denied action {} on component {}",
                new Object[] { user, arg1.toString(), arg0.getClass().getName() });
    }
    return checkAccess == Access.GRANTED;
}

From source file:org.ops4j.pax.wicket.util.authorization.UserAdminAuthorizationStrategy.java

License:Apache License

public final boolean isActionAuthorized(Component component, Action action) {
    final Class<? extends Component> componentClass = component.getClass();

    // First check for denial restrictions on the component
    final DenyAction annotation = componentClass.getAnnotation(DenyAction.class);
    final boolean doDenyAction;
    if (null == annotation)
    // There is no annotation, so no authorization restrictions.
    {//w  ww .j a va 2s. c om
        doDenyAction = false;
    } else if ("".equals(annotation.value()))
    // There is an annotation with an empty value, which means that
    // all actions are to be tested.
    {
        doDenyAction = true;
    } else {
        // There is an annotation with a non-empty value, which means that
        // we need to test to see if the action should be authorized.
        boolean isActionSpecified = false;
        for (final String nextAction : annotation.value()) {
            if (action.getName().equals(nextAction)) {
                isActionSpecified = true;
                break;
            }
        }
        doDenyAction = isActionSpecified;
    }

    if (doDenyAction) {
        final StringBuilder s = new StringBuilder();
        s.append(componentClass.getName());
        s.append(".");
        s.append(action.getName());
        return !isAuthorized(s.toString());
    }

    // If we do not deny the action, next check for authorization
    // restrictions on the component
    final AuthorizeAction authorizeActionAnnotation = componentClass.getAnnotation(AuthorizeAction.class);
    final boolean doAuthorizeAction;
    if (null == authorizeActionAnnotation)
    // There is no annotation, so no authorization restrictions.
    {
        doAuthorizeAction = false;
    } else if ("".equals(authorizeActionAnnotation.value()))
    // There is an annotation with an empty value, which means that
    // all actions are to be tested.
    {
        doAuthorizeAction = true;
    } else {
        // There is an annotation with a non-empty value, which means that
        // we need to test to see if the action should be authorized.
        boolean isActionSpecified = false;
        for (final String nextAction : authorizeActionAnnotation.value()) {
            if (action.getName().equals(nextAction)) {
                isActionSpecified = true;
                break;
            }
        }
        doAuthorizeAction = isActionSpecified;
    }

    if (doAuthorizeAction) {
        final StringBuilder s = new StringBuilder();
        s.append(componentClass.getName());
        s.append(".");
        s.append(action.getName());
        return isAuthorized(s.toString());
    }

    return true;
}

From source file:org.wicketstuff.security.swarm.actions.SwarmActionFactory.java

License:Apache License

/**
 * //from w w  w.  j a  va 2  s . c  o  m
 * @see org.wicketstuff.security.actions.WaspActionFactory#getAction(org.apache.wicket.authorization.Action)
 */
public WaspAction getAction(Action action) {
    if (action != null)
        try {
            return getAction(action.getName());
        } catch (IllegalArgumentException e) {
            // according to the spec we return null if the action does not
            // exist
        }
    return null;
}

From source file:org.wicketstuff.security.swarm.actions.SwarmActionFactoryTest.java

License:Apache License

/**
 * @see SwarmActionFactory#getAction(Action)
 *//*from  w  w w . ja  va2s  .  c  o  m*/
public void testGetActionAction() {
    WaspAction action = factory.getAction(Component.RENDER);
    assertNotNull(action);
    assertEquals(factory.getAction(Render.class), action);
    assertEquals(factory.getAction("render"), action);

    Action wicketAction = new Action("inherit, render");
    action = factory.getAction(wicketAction);
    assertNotNull(action);
    assertEquals(factory.getAction(wicketAction.getName()), action);

    assertNull(factory.getAction((Action) null));
    assertNull(factory.getAction(new Action("foo")));
}