Package org.sonatype.security.model

Examples of org.sonatype.security.model.CPrivilege


  }

  public Privilege addPrivilege(Privilege privilege)
      throws InvalidConfigurationException
  {
    final CPrivilege secPriv = this.toPrivilege(privilege);
    // create implies read, so we need to add logic for that
    addInheritedPrivileges(secPriv);

    try {
      this.configuration.runWrite(new ConfigurationManagerAction()
View Full Code Here


  }

  public Privilege updatePrivilege(Privilege privilege)
      throws NoSuchPrivilegeException, InvalidConfigurationException
  {
    final CPrivilege secPriv = this.toPrivilege(privilege);

    try {
      this.configuration.runWrite(new ConfigurationManagerAction()
      {
        @Override
View Full Code Here

  }

  public CPrivilege readPrivilege(String id)
      throws NoSuchPrivilegeException
  {
    final CPrivilege privilege = getConfiguration().getPrivilegeById(id);

    if (privilege != null) {
      privilege.setReadOnly(true);

      return privilege;
    }
    else {
      return manager.readPrivilege(id);
View Full Code Here

  }

  // ==

  public void addPrivilege(final CPrivilege cPrivilege) {
    final CPrivilege cp = cPrivilege.clone();
    delegate.addPrivilege(cp);
    id2privileges.put(cp.getId(), cp);
  }
View Full Code Here

  public CPrivilege getPrivilegeById(final String id) {
    return getPrivilegeById(id, true);
  }

  public CPrivilege getPrivilegeById(final String id, final boolean clone) {
    final CPrivilege privilege = id2privileges.get(id);
    if (privilege != null) {
      return clone ? privilege.clone() : privilege;
    }
    else {
      return null;
    }
  }
View Full Code Here

      return null;
    }
  }

  public boolean removePrivilegeById(final String id) {
    final CPrivilege privilege = getPrivilegeById(id, false);
    if (privilege != null) {
      delegate.removePrivilege(privilege);
      return id2privileges.remove(id) != null;
    }
    else {
View Full Code Here

    Privilege priv2 = authzManager.getPrivilege("2");
    priv2.setDescription("new description");

    authzManager.updatePrivilege(priv2);

    CPrivilege secPriv = this.getConfigurationManager().readPrivilege(priv2.getId());

    Assert.assertEquals(priv2.getId(), secPriv.getId());
    Assert.assertEquals(priv2.getName(), secPriv.getName());
    Assert.assertEquals(priv2.getDescription(), secPriv.getDescription());
    Assert.assertEquals(priv2.getType(), secPriv.getType());

    Map<String, String> props = this.getPropertyMap(secPriv);
    Assert.assertEquals("read", props.get("method"));
    Assert.assertEquals("/some/path/", props.get("permission"));
    Assert.assertEquals(2, secPriv.getProperties().size());
  }
View Full Code Here

    CProperty methodProp = new CProperty();
    methodProp.setKey(ApplicationPrivilegeMethodPropertyDescriptor.ID);
    methodProp.setValue("read");

    CPrivilege priv = new CPrivilege();
    priv.setId("priv");
    priv.setName("somepriv");
    priv.setType(ApplicationPrivilegeDescriptor.TYPE);
    priv.setDescription("somedescription");
    priv.addProperty(permissionProp);
    priv.addProperty(methodProp);

    configurationManager.createPrivilege(priv);

    CRole role = new CRole();
    role.setId("role");
    role.setName("somerole");
    role.setDescription("somedescription");
    role.setSessionTimeout(60);
    role.addPrivilege(priv.getId());

    configurationManager.createRole(role);

    CUser user = new CUser();
    user.setEmail("dummyemail@foo");
View Full Code Here

    permissionsCache.put(roleString, permissions);
  }

  protected Set<Permission> getPermissions(final String privilegeId) {
    try {
      final CPrivilege privilege = configuration.readPrivilege(privilegeId);
      for (PrivilegeDescriptor descriptor : privilegeDescriptors) {
        final String permission = descriptor.buildPermission(privilege);
        if (permission != null) {
          return Collections.singleton(permissionFactory.create(permission));
        }
View Full Code Here

  public void testRoles()
      throws Exception
  {
    SecurityValidationContext context = new SecurityValidationContext();

    CPrivilege priv = new CPrivilege();
    priv.setId("priv");
    priv.setName("priv");
    priv.setType("invalid");
    context.addExistingPrivilegeIds();
    context.getExistingPrivilegeIds().add("priv");

    CRole role1 = new CRole();
    role1.setId("role1");
    role1.setName("role1");
    role1.setDescription("desc");
    role1.setSessionTimeout(50);
    role1.addPrivilege(priv.getId());
    role1.addRole("role2");
    ArrayList<String> containedRoles = new ArrayList<String>();
    containedRoles.add("role2");
    context.addExistingRoleIds();
    context.getExistingRoleIds().add("role1");
    context.getRoleContainmentMap().put("role1", containedRoles);

    CRole role2 = new CRole();
    role2.setId("role2");
    role2.setName("role2");
    role2.setDescription("desc");
    role2.setSessionTimeout(50);
    role2.addPrivilege(priv.getId());
    role2.addRole("role3");
    containedRoles = new ArrayList<String>();
    containedRoles.add("role3");
    context.addExistingRoleIds();
    context.getExistingRoleIds().add("role2");
    context.getRoleContainmentMap().put("role2", containedRoles);

    CRole role3 = new CRole();
    role3.setId("role3");
    role3.setName("role3");
    role3.setDescription("desc");
    role3.setSessionTimeout(50);
    role3.addPrivilege(priv.getId());
    role3.addRole("role1");
    containedRoles = new ArrayList<String>();
    containedRoles.add("role1");
    context.addExistingRoleIds();
    context.getExistingRoleIds().add("role3");
View Full Code Here

TOP

Related Classes of org.sonatype.security.model.CPrivilege

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.