Package org.apache.wicket.authorization.strategies.role

Examples of org.apache.wicket.authorization.strategies.role.Roles


    if (rolesToAdd == null)
    {
      throw new IllegalArgumentException("Argument rolesToadd cannot be null");
    }

    Roles roles = rolesForComponentClass.get(componentClass);
    if (roles == null)
    {
      roles = new Roles();
      rolesForComponentClass.put(componentClass, roles);
    }
    roles.addAll(rolesToAdd);
  }
View Full Code Here


    if (rolesToRemove == null)
    {
      throw new IllegalArgumentException("Argument rolesToRemove cannot be null");
    }

    Roles roles = rolesForComponentClass.get(componentClass);
    if (roles != null)
    {
      roles.removeAll(rolesToRemove);
    }
    else
    {
      roles = new Roles();
      rolesForComponentClass.put(componentClass, roles);
    }

    // If we removed the last authorized role, we authorize the empty role
    // so that removing authorization can't suddenly open something up to
    // everyone.
    if (roles.size() == 0)
    {
      roles.add(MetaDataRoleAuthorizationStrategy.NO_ROLE);
    }
  }
View Full Code Here

  /**
   * @see IRoleCheckingStrategy#hasAnyRole(Roles)
   */
  public final boolean hasAnyRole(final Roles roles)
  {
    final Roles sessionRoles = AuthenticatedWebSession.get().getRoles();
    return sessionRoles != null && sessionRoles.hasAnyRole(roles);
  }
View Full Code Here

   */
  public void testAdd1() throws Exception
  {
    ActionPermissions permissions = new ActionPermissions();
    Action mambo = new Action("mambo");
    permissions.authorize(mambo, new Roles("jonathan"));
    permissions.authorize(mambo, new Roles("johan"));
    permissions.authorize(mambo, new Roles("maurice"));
    permissions.authorize(mambo, new Roles("eelco"));
    assertEquals(4, permissions.rolesFor(mambo).size());
    permissions.unauthorize(mambo, new Roles("maurice"));
    assertEquals(3, permissions.rolesFor(mambo).size());
    permissions.authorizeAll(mambo);
    assertEquals(null, permissions.rolesFor(mambo));
  }
View Full Code Here

  public void testRemove1() throws Exception
  {
    ActionPermissions permissions = new ActionPermissions();
    Action mambo = new Action("mambo");
    assertEquals(null, permissions.rolesFor(mambo));
    permissions.unauthorize(mambo, new Roles("maurice"));
    assertEquals(new Roles(MetaDataRoleAuthorizationStrategy.NO_ROLE), permissions
        .rolesFor(mambo));
  }
View Full Code Here

   * @throws Exception
   */
  public void testAdd1() throws Exception
  {
    InstantiationPermissions permissions = new InstantiationPermissions();
    permissions.authorize(Page.class, new Roles("jonathan"));
    permissions.authorize(Page.class, new Roles("johan"));
    permissions.authorize(Page.class, new Roles("maurice"));
    permissions.authorize(Page.class, new Roles("eelco"));
    assertEquals(4, permissions.getRolesForComponentClass().get(Page.class).size());
    permissions.unauthorize(Page.class, new Roles("maurice"));
    assertEquals(3, permissions.getRolesForComponentClass().get(Page.class).size());
    permissions.authorizeAll(Page.class);
    assertEquals(null, permissions.getRolesForComponentClass().get(Page.class));
  }
View Full Code Here

   */
  public void testRemove1() throws Exception
  {
    InstantiationPermissions permissions = new InstantiationPermissions();
    assertEquals(null, permissions.getRolesForComponentClass().get(Page.class));
    permissions.unauthorize(Page.class, new Roles("eelco"));
    assertEquals(new Roles(MetaDataRoleAuthorizationStrategy.NO_ROLE), permissions
        .getRolesForComponentClass().get(Page.class));
  }
View Full Code Here

    if (componentPackage != null)
    {
      final AuthorizeInstantiation packageAnnotation = componentPackage.getAnnotation(AuthorizeInstantiation.class);
      if (packageAnnotation != null)
      {
        authorized = hasAny(new Roles(packageAnnotation.value()));
      }
    }

    // Check class annotation
    final AuthorizeInstantiation classAnnotation = componentClass.getAnnotation(AuthorizeInstantiation.class);
    if (classAnnotation != null)
    {
      // If roles are defined for the class, that overrides the package
      authorized = hasAny(new Roles(classAnnotation.value()));
    }

    return authorized;
  }
View Full Code Here

  {
    if (authorizeActionAnnotation != null)
    {
      if (action.getName().equals(authorizeActionAnnotation.action()))
      {
        if (hasAny(new Roles(authorizeActionAnnotation.deny())))
        {
          return false;
        }

        Roles roles = new Roles(authorizeActionAnnotation.roles());
        if (!(isEmpty(roles) || hasAny(roles)))
        {
          return false;
        }
      }
View Full Code Here

    if (componentPackage != null)
    {
      final AuthorizeInstantiation packageAnnotation = componentPackage.getAnnotation(AuthorizeInstantiation.class);
      if (packageAnnotation != null)
      {
        authorized = hasAny(new Roles(packageAnnotation.value()));
      }
    }

    // Check class annotation
    final AuthorizeInstantiation classAnnotation = componentClass.getAnnotation(AuthorizeInstantiation.class);
    if (classAnnotation != null)
    {
      // If roles are defined for the class, that overrides the package
      authorized = hasAny(new Roles(classAnnotation.value()));
    }

    return authorized;
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.authorization.strategies.role.Roles

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.