PrivilegeListResourceResponse result = null;
if (resourceRequest != null) {
result = new PrivilegeListResourceResponse();
PrivilegeResource resource = resourceRequest.getData();
// currently we are allowing only of repotarget privs, so enforcing checkfor it
if (!TargetPrivilegeDescriptor.TYPE.equals(resource.getType())) {
throw new PlexusResourceException(
Status.CLIENT_ERROR_BAD_REQUEST,
"Configuration error.",
getErrorResponse("type", "Not allowed privilege type!"));
}
List<String> methods = resource.getMethod();
if (methods == null || methods.size() == 0) {
throw new PlexusResourceException(
Status.CLIENT_ERROR_BAD_REQUEST,
"Configuration error.",
getErrorResponse("method", "No method(s) supplied, must select at least one method."));
}
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));
}