Package org.sonatype.security.authorization

Examples of org.sonatype.security.authorization.Privilege


  public PrivilegeStatusResourceResponse get(Context context, Request request, Response response, Variant variant)
      throws ResourceException
  {
    PrivilegeStatusResourceResponse result = new PrivilegeStatusResourceResponse();

    Privilege priv = null;

    try {
      AuthorizationManager authzManager = getSecuritySystem().getAuthorizationManager(PRIVILEGE_SOURCE);
      priv = authzManager.getPrivilege(getPrivilegeId(request));
    }
View Full Code Here


  @Override
  @DELETE
  public void delete(Context context, Request request, Response response)
      throws ResourceException
  {
    Privilege priv;

    try {
      AuthorizationManager authzManager = getSecuritySystem().getAuthorizationManager(PRIVILEGE_SOURCE);

      priv = authzManager.getPrivilege(getPrivilegeId(request));

      if (priv.getType().equals(ApplicationPrivilegeDescriptor.TYPE)) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
            "Cannot delete an application type privilege");
      }
      else {
        authzManager.deletePrivilege(getPrivilegeId(request));
View Full Code Here

      }
    }

    for (String privilegeId : role.getPrivileges()) {
      try {
        Privilege childPrivilege = authzManager.getPrivilege(privilegeId);
        RoleTreeResource childResource = new RoleTreeResource();
        childResource.setId(childPrivilege.getId());
        childResource.setName(childPrivilege.getName());
        childResource.setType("privilege");
        if (resource != null) {
          resource.addChildren(childResource);
        }
        else {
View Full Code Here

      }
      else {
        try {
          // Add a new privilege for each method
          for (String method : methods) {
            Privilege priv = new Privilege();

            priv.setName(resource.getName() != null ? resource.getName() + " - (" + method + ")" : null);
            priv.setDescription(resource.getDescription());
            priv.setType(TargetPrivilegeDescriptor.TYPE);

            priv.addProperty(ApplicationPrivilegeMethodPropertyDescriptor.ID, method);

            priv.addProperty(TargetPrivilegeRepositoryTargetPropertyDescriptor.ID, resource
                .getRepositoryTargetId());

            priv.addProperty(TargetPrivilegeRepositoryPropertyDescriptor.ID, resource.getRepositoryId());

            priv.addProperty(TargetPrivilegeGroupPropertyDescriptor.ID, resource.getRepositoryGroupId());

            priv = getSecuritySystem().getAuthorizationManager(DEFAULT_SOURCE).addPrivilege(priv);

            result.addData(this.securityToRestModel(priv, request, true));
          }
View Full Code Here

    return secPriv;
  }

  protected Privilege toPrivilege(CPrivilege secPriv) {
    Privilege privilege = new Privilege();
    privilege.setId(secPriv.getId());
    privilege.setName(secPriv.getName());
    privilege.setDescription(secPriv.getDescription());
    privilege.setReadOnly(secPriv.isReadOnly());
    privilege.setType(secPriv.getType());

    if (secPriv.getProperties() != null) {
      for (CProperty prop : (List<CProperty>) secPriv.getProperties()) {
        privilege.addProperty(prop.getKey(), prop.getValue());
      }
    }

    return privilege;
  }
View Full Code Here

    Map<String, String> properties = new HashMap<String, String>();
    properties.put(ApplicationPrivilegeMethodPropertyDescriptor.ID, "read");
    properties.put(ApplicationPrivilegePermissionPropertyDescriptor.ID, "permissionOne");

    securitySystem.getAuthorizationManager("default").addPrivilege(new Privilege(
        "randomId",
        "permissionOne",
        "permissionOne",
        ApplicationPrivilegeDescriptor.TYPE,
        properties, false));
View Full Code Here

    Assert.assertTrue(roleMap.containsKey("2"));
    Assert.assertTrue(roleMap.containsKey("3"));
    Assert.assertTrue(roleMap.containsKey("4"));
    Assert.assertEquals(4, privileges.size());

    Privilege priv3 = roleMap.get("3");

    Assert.assertEquals("3", priv3.getId());
    Assert.assertEquals("3-name", priv3.getName());
    Assert.assertEquals("Privilege Three", priv3.getDescription());
    Assert.assertEquals("method", priv3.getType());
    Assert.assertEquals("read", priv3.getPrivilegeProperty("method"));
    Assert.assertEquals("/some/path/", priv3.getPrivilegeProperty("permission"));
  }
View Full Code Here

  public void testGetPrivilege()
      throws Exception
  {
    AuthorizationManager authzManager = this.getAuthorizationManager();

    Privilege priv3 = authzManager.getPrivilege("3");

    Assert.assertEquals("3", priv3.getId());
    Assert.assertEquals("3-name", priv3.getName());
    Assert.assertEquals("Privilege Three", priv3.getDescription());
    Assert.assertEquals("method", priv3.getType());
    Assert.assertEquals("read", priv3.getPrivilegeProperty("method"));
    Assert.assertEquals("/some/path/", priv3.getPrivilegeProperty("permission"));
  }
View Full Code Here

  public void testAddPrivilege()
      throws Exception
  {
    AuthorizationManager authzManager = this.getAuthorizationManager();

    Privilege privilege = new Privilege();
    privilege.addProperty("foo1", "bar2");
    privilege.addProperty("bar1", "foo2");
    privilege.setId("new-priv");
    privilege.setName("new-name");
    privilege.setDescription("new-description");
    privilege.setReadOnly(true);
    privilege.setType("TEST");

    authzManager.addPrivilege(privilege);

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

    Assert.assertEquals(privilege.getId(), secPriv.getId());
    Assert.assertEquals(privilege.getName(), secPriv.getName());
    Assert.assertEquals(privilege.getDescription(), secPriv.getDescription());
    Assert.assertEquals(privilege.getType(), secPriv.getType());
    Assert.assertEquals(privilege.getProperties().size(), secPriv.getProperties().size());

    Map<String, String> props = this.getPropertyMap(secPriv);
    Assert.assertEquals("bar2", props.get("foo1"));
    Assert.assertEquals("foo2", props.get("bar1"));
View Full Code Here

  public void testUpdatePrivilege()
      throws Exception
  {
    AuthorizationManager authzManager = this.getAuthorizationManager();

    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

TOP

Related Classes of org.sonatype.security.authorization.Privilege

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.