*/
package org.sonar.ce.user;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
+import org.sonar.db.component.ComponentDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.user.UserSession;
return notImplemented();
}
+ @Override
+ public UserSession checkComponentPermission(String projectPermission, ComponentDto component) {
+ return notImplemented();
+ }
+
@Override
public UserSession checkComponentPermission(String projectPermission, String componentKey) {
return notImplemented();
return notImplemented();
}
+ @Override
+ public boolean hasComponentPermission(String permission, ComponentDto component) {
+ return notImplementedBooleanMethod();
+ }
+
@Override
public boolean hasComponentPermission(String permission, String componentKey) {
return notImplementedBooleanMethod();
*/
package org.sonar.server.user;
+import org.sonar.db.component.ComponentDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
return isRoot() || globalPermissions().contains(globalPermission);
}
+ @Override
+ public boolean hasComponentPermission(String permission, ComponentDto component) {
+ return hasComponentUuidPermission(permission, component.projectUuid());
+ }
+
+ @Override
+ public UserSession checkComponentPermission(String projectPermission, ComponentDto component) {
+ if (!hasComponentPermission(projectPermission, component)) {
+ throw new ForbiddenException(INSUFFICIENT_PRIVILEGES_MESSAGE);
+ }
+ return this;
+ }
+
@Override
public UserSession checkComponentPermission(String projectPermission, String componentKey) {
if (!hasComponentPermission(projectPermission, componentKey)) {
import org.sonar.api.security.DefaultGroups;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.user.GroupDto;
+import org.sonar.db.component.ComponentDto;
/**
* Allow code to be executed with the highest privileges possible, as if executed by a {@link GlobalPermissions#SYSTEM_ADMIN} account.
return Collections.emptyList();
}
+ @Override
+ public boolean hasComponentPermission(String permission, ComponentDto component) {
+ return true;
+ }
+
@Override
public boolean hasComponentPermission(String permission, String componentKey) {
return true;
*/
package org.sonar.server.user;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
+import org.sonar.db.component.ComponentDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.exceptions.UnauthorizedException;
return get().globalPermissions();
}
+ @Override
+ public UserSession checkComponentPermission(String projectPermission, ComponentDto component) {
+ get().checkComponentPermission(projectPermission, component);
+ return this;
+ }
+
@Override
public UserSession checkComponentPermission(String projectPermission, String componentKey) {
get().checkComponentPermission(projectPermission, componentKey);
return this;
}
+ @Override
+ public boolean hasComponentPermission(String permission, ComponentDto component) {
+ return get().hasComponentPermission(permission, component);
+ }
+
@Override
public boolean hasComponentPermission(String permission, String componentKey) {
return get().hasComponentPermission(permission, componentKey);
*/
package org.sonar.server.user;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.sonar.api.security.DefaultGroups;
+import org.sonar.db.component.ComponentDto;
import org.sonar.db.user.GroupDto;
public interface UserSession {
/**
* Ensures that permission is granted to user, otherwise throws a {@link org.sonar.server.exceptions.ForbiddenException}.
-
+
* @deprecated in 6.3 because it doesn't support organizations
* @see org.sonar.core.permission.GlobalPermissions
* @see #checkIsRoot() for system administrators
/**
* Does the user have the given permission ?
-
+
* @deprecated in 6.3 because if doesn't support organizations
* @see org.sonar.core.permission.GlobalPermissions
* @see #isRoot()
@Deprecated
List<String> globalPermissions();
+ /**
+ * Ensures that permission is granted to user, otherwise throws a {@link org.sonar.server.exceptions.ForbiddenException}.
+ * If the component doesn't exist and the user doesn't have the permission, throws
+ * a {@link org.sonar.server.exceptions.ForbiddenException}.
+ *
+ * @see org.sonar.api.web.UserRole for list of project permissions
+ */
+ UserSession checkComponentPermission(String projectPermission, ComponentDto component);
+
/**
* Ensures that permission is granted to user on the specified component, otherwise throws
* a {@link org.sonar.server.exceptions.ForbiddenException}.
*/
UserSession checkComponentUuidPermission(String permission, String componentUuid);
+ /**
+ * Whether the user has the permission on the component. Returns {@code false}
+ * if the component does not exist in database.
+ */
+ boolean hasComponentPermission(String permission, ComponentDto component);
+
/**
* Does the user have the given permission for a component key ?
*
import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.security.DefaultGroups;
+import org.sonar.db.component.ComponentDto;
import org.sonar.server.user.AbstractUserSession;
import static com.google.common.collect.Lists.newArrayList;
return globalPermissions;
}
+ @Override
+ public boolean hasComponentPermission(String permission, ComponentDto component) {
+ return hasComponentUuidPermission(permission, component.projectUuid());
+ }
+
@Override
public boolean hasComponentPermission(String permission, String componentKey) {
String projectKey = projectKeyByComponentKey.get(componentKey);
package org.sonar.server.tester;
import com.google.common.base.Preconditions;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
+import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
return currentUserSession.globalPermissions();
}
+ @Override
+ public boolean hasComponentPermission(String permission, ComponentDto component) {
+ return hasComponentUuidPermission(permission, component.projectUuid());
+ }
+
@Override
public boolean hasComponentPermission(String permission, String componentKey) {
return currentUserSession.hasComponentPermission(permission, componentKey);
return currentUserSession.hasOrganizationPermission(organizationUuid, permission);
}
+ @Override
+ public UserSession checkComponentPermission(String projectPermission, ComponentDto component) {
+ currentUserSession.checkComponentPermission(projectPermission, component);
+ return this;
+ }
+
@Override
public UserSession checkComponentPermission(String projectPermission, String componentKey) {
currentUserSession.checkComponentPermission(projectPermission, componentKey);