
org.fcrepo.auth.roles.common.AccessRolesResources Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fcrepo-auth-roles-common Show documentation
Show all versions of fcrepo-auth-roles-common Show documentation
This module adds access roles to the repository tree. It creates a REST/JSON API for post and get of access roles on Fedora objects and datastreams. It supports the querying of effective roles by authorization delegates.
/*
* Copyright 2015 DuraSpace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fcrepo.auth.roles.common;
import static java.util.Collections.singletonMap;
import java.util.Map;
import javax.jcr.RepositoryException;
import javax.ws.rs.core.UriInfo;
import org.fcrepo.http.commons.api.rdf.UriAwareResourceModelFactory;
import org.fcrepo.kernel.api.FedoraTypes;
import org.fcrepo.kernel.api.RdfLexicon;
import org.fcrepo.kernel.api.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.api.identifiers.IdentifierConverter;
import org.fcrepo.kernel.api.models.FedoraResource;
import org.springframework.stereotype.Component;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
/**
* Exposes access roles endpoint for any resource.
*
* @author Gregory Jansen
*/
@Component
public class AccessRolesResources implements UriAwareResourceModelFactory {
/*
* (non-Javadoc)
* @see org.fcrepo.http.commons.api.rdf.UriAwareResourceModelFactory#
* createModelForResource( org.fcrepo.kernel.api.FedoraResourceImpl,
* javax.ws.rs.core.UriInfo, org.fcrepo.kernel.api.rdf.IdentifierTranslator)
*/
@Override
public Model createModelForResource(final FedoraResource resource,
final UriInfo uriInfo, final IdentifierConverter graphSubjects) {
final Model model = ModelFactory.createDefaultModel();
try {
final Resource s = graphSubjects.reverse().convert(resource);
if (resource.getNode().isNodeType(
FedoraTypes.FEDORA_RESOURCE)) {
final Map pathMap =
singletonMap("path", resource.getPath().substring(1));
final Resource acl = model.createResource(uriInfo.getBaseUriBuilder().path(
AccessRoles.class).buildFromMap(pathMap).toASCIIString());
model.add(s, RdfLexicon.HAS_ACCESS_ROLES_SERVICE, acl);
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
return model;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy