Skip to content

Commit

Permalink
Add a no-op AccessControlService (#355)
Browse files Browse the repository at this point in the history
Resolves #354
  • Loading branch information
acoburn authored Feb 11, 2019
1 parent 9cf08a3 commit 6c9c59a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.trellisldp.api;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableSet;
import static java.util.stream.Collectors.toSet;
import static org.trellisldp.api.TrellisUtils.getInstance;

import java.util.Set;

import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.RDF;

/**
* A no-op AccessControlService implementation.
*/
public class NoopAccessControlService implements AccessControlService {

private static final RDF rdf = getInstance();
private static final String URI = "http://www.w3.org/ns/auth/acl#";
private static final Set<IRI> modes = unmodifiableSet(asList("Control", "Read", "Write", "Append")
.stream().map(mode -> URI + mode).map(rdf::createIRI).collect(toSet()));

@Override
public Set<IRI> getAccessModes(final IRI identifier, final Session session) {
return modes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.trellisldp.api;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.MockitoAnnotations.initMocks;

import org.apache.commons.rdf.api.IRI;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.trellisldp.vocabulary.ACL;

public class NoopAccessControlServiceTest {

@Mock
private Session mockSession;

@BeforeEach
public void setUp() {
initMocks(this);
}

@Test
public void testAccessControl() {
final IRI resource = TrellisUtils.getInstance().createIRI("trellis:data/resource");
final AccessControlService svc = new NoopAccessControlService();
assertTrue(svc.getAccessModes(resource, mockSession).contains(ACL.Control));
assertTrue(svc.getAccessModes(resource, mockSession).contains(ACL.Read));
assertTrue(svc.getAccessModes(resource, mockSession).contains(ACL.Write));
assertTrue(svc.getAccessModes(resource, mockSession).contains(ACL.Append));
}
}

0 comments on commit 6c9c59a

Please sign in to comment.