use of com.google.gerrit.extensions.api.access.GlobalOrPluginPermission in project gerrit by GerritCodeReview.
the class Capabilities method parse.
@Override
public Capability parse(AccountResource parent, IdString id) throws ResourceNotFoundException, AuthException, PermissionBackendException {
IdentifiedUser target = parent.getUser();
if (self.get() != target) {
permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
}
GlobalOrPluginPermission perm = parse(id);
if (permissionBackend.user(target).test(perm)) {
return new AccountResource.Capability(target, perm.permissionName());
}
throw new ResourceNotFoundException(id);
}
use of com.google.gerrit.extensions.api.access.GlobalOrPluginPermission in project gerrit by GerritCodeReview.
the class Capabilities method parse.
private GlobalOrPluginPermission parse(IdString id) throws ResourceNotFoundException {
String name = id.get();
GlobalOrPluginPermission perm = GlobalPermission.byName(name);
if (perm != null) {
return perm;
}
int dash = name.lastIndexOf('-');
if (dash < 0) {
throw new ResourceNotFoundException(id);
}
String pluginName = name.substring(0, dash);
String capability = name.substring(dash + 1);
if (pluginName.isEmpty() || capability.isEmpty()) {
throw new ResourceNotFoundException(id);
}
return new PluginPermission(pluginName, capability);
}
use of com.google.gerrit.extensions.api.access.GlobalOrPluginPermission in project gerrit by GerritCodeReview.
the class UiActions method describe.
@Nullable
private <R extends RestResource> UiAction.Description describe(Extension<RestView<R>> e, R resource) {
int d = e.getExportName().indexOf('.');
if (d < 0) {
return null;
}
RestView<R> view;
try {
view = e.getProvider().get();
} catch (RuntimeException err) {
logger.atSevere().withCause(err).log("error creating view %s.%s", e.getPluginName(), e.getExportName());
return null;
}
if (!(view instanceof UiAction)) {
return null;
}
String name = e.getExportName().substring(d + 1);
UiAction.Description dsc = null;
try (Timer1.Context<String> ignored = uiActionLatency.start(name)) {
dsc = ((UiAction<R>) view).getDescription(resource);
} catch (Exception ex) {
logger.atSevere().withCause(ex).log("Unable to render UIAction. Will omit from actions");
}
if (dsc == null) {
return null;
}
Set<GlobalOrPluginPermission> globalRequired;
try {
globalRequired = GlobalPermission.fromAnnotation(e.getPluginName(), view.getClass());
} catch (PermissionBackendException err) {
logger.atSevere().withCause(err).log("exception testing view %s.%s", e.getPluginName(), e.getExportName());
return null;
}
if (!globalRequired.isEmpty()) {
PermissionBackend.WithUser withUser = permissionBackend.currentUser();
Iterator<GlobalOrPluginPermission> i = globalRequired.iterator();
BooleanCondition p = withUser.testCond(i.next());
while (i.hasNext()) {
p = or(p, withUser.testCond(i.next()));
}
dsc.setVisible(and(p, dsc.getVisibleCondition()));
}
PrivateInternals_UiActionDescription.setMethod(dsc, e.getExportName().substring(0, d));
PrivateInternals_UiActionDescription.setId(dsc, PluginName.GERRIT.equals(e.getPluginName()) ? name : e.getPluginName() + '~' + name);
return dsc;
}
use of com.google.gerrit.extensions.api.access.GlobalOrPluginPermission in project gerrit by GerritCodeReview.
the class GetCapabilities method apply.
@Override
public Response<Map<String, Object>> apply(AccountResource resource) throws RestApiException, PermissionBackendException {
permissionBackend.checkUsesDefaultCapabilities();
PermissionBackend.WithUser perm = permissionBackend.currentUser();
if (!self.get().hasSameAccountId(resource.getUser())) {
perm.check(GlobalPermission.ADMINISTRATE_SERVER);
perm = permissionBackend.absentUser(resource.getUser().getAccountId());
}
Map<String, Object> have = new LinkedHashMap<>();
for (GlobalOrPluginPermission p : perm.test(permissionsToTest())) {
have.put(globalOrPluginPermissionName(p), true);
}
AccountLimits limits = limitsFactory.create(resource.getUser());
addRanges(have, limits);
addPriority(have, limits);
return Response.ok(have);
}
use of com.google.gerrit.extensions.api.access.GlobalOrPluginPermission in project gerrit by GerritCodeReview.
the class Capabilities method parse.
private GlobalOrPluginPermission parse(IdString id) throws ResourceNotFoundException {
String name = id.get();
Optional<GlobalPermission> perm = globalPermission(name);
if (perm.isPresent()) {
return perm.get();
}
int dash = name.lastIndexOf('-');
if (dash < 0) {
throw new ResourceNotFoundException(id);
}
String pluginName = name.substring(0, dash);
String capability = name.substring(dash + 1);
if (pluginName.isEmpty() || capability.isEmpty()) {
throw new ResourceNotFoundException(id);
}
return new PluginPermission(pluginName, capability);
}
Aggregations