Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a WebACAuthorizationImpl class
- Loading branch information
Showing
2 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/main/java/org/fcrepo/auth/webac/impl/WebACAuthorizationImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* 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.webac.impl; | ||
|
||
import java.net.URI; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.fcrepo.auth.webac.WebACAuthorization; | ||
|
||
/** | ||
* @author acoburn | ||
* @since 9/2/15 | ||
*/ | ||
public class WebACAuthorizationImpl implements WebACAuthorization { | ||
|
||
private final Set<String> agents = new HashSet<>(); | ||
|
||
private final Set<String> agentClasses = new HashSet<>(); | ||
|
||
private final Set<URI> modes = new HashSet<>(); | ||
|
||
private final Set<String> accessTo = new HashSet<>(); | ||
|
||
private final Set<String> accessToClass = new HashSet<>(); | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param agents The acl:agent values | ||
* @param agentClasses the acl:agentClass values | ||
* @param modes the acl:mode values | ||
* @param accessTo the acl:accessTo values | ||
* @param accessToClass the acl:accessToClass values | ||
*/ | ||
public WebACAuthorizationImpl(final Collection<String> agents, final Collection<String> agentClasses, | ||
final Collection<URI> modes, final Collection<String> accessTo, final Collection<String> accessToClass) { | ||
this.agents.addAll(agents); | ||
this.agentClasses.addAll(agentClasses); | ||
this.modes.addAll(modes); | ||
this.accessTo.addAll(accessTo); | ||
this.accessToClass.addAll(accessToClass); | ||
} | ||
|
||
@Override | ||
public Set<String> getAgents() { | ||
return agents; | ||
} | ||
|
||
@Override | ||
public Set<String> getAgentClasses() { | ||
return agentClasses; | ||
} | ||
|
||
@Override | ||
public Set<URI> getModes() { | ||
return modes; | ||
} | ||
|
||
@Override | ||
public Set<String> getAccessToURIs() { | ||
return accessTo; | ||
} | ||
|
||
@Override | ||
public Set<String> getAccessToClassURIs() { | ||
return accessToClass; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/test/java/org/fcrepo/auth/webac/impl/WebACAuthorizationImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* 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.webac.impl; | ||
|
||
import static org.fcrepo.auth.webac.URIConstants.WEBAC_MODE_READ; | ||
import static org.fcrepo.auth.webac.URIConstants.WEBAC_MODE_WRITE; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.fcrepo.auth.webac.WebACAuthorization; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* @author acoburn | ||
* @since 9/2/15 | ||
*/ | ||
public class WebACAuthorizationImplTest { | ||
|
||
private final String AGENT1 = "me"; | ||
private final String AGENT2 = "you"; | ||
private final String AGENT_CLASS1 = "this"; | ||
private final String AGENT_CLASS2 = "that"; | ||
private final String ACCESS_TO1 = "/foo"; | ||
private final String ACCESS_TO2 = "/bar"; | ||
private final String ACCESS_TO3 = "/baz"; | ||
private final String ACCESS_TO_CLASS1 = "ex:Image"; | ||
private final String ACCESS_TO_CLASS2 = "ex:Archive"; | ||
|
||
@Test | ||
public void testLists() { | ||
final List<String> agents = Arrays.asList(AGENT1, AGENT2, AGENT1); | ||
final List<String> agentClasses = Arrays.asList(AGENT_CLASS1, AGENT_CLASS2, AGENT_CLASS2); | ||
final List<URI> modes = Arrays.asList(WEBAC_MODE_READ, WEBAC_MODE_WRITE, WEBAC_MODE_READ); | ||
final List<String> accessTo = Arrays.asList(ACCESS_TO1, ACCESS_TO2, ACCESS_TO3); | ||
final List<String> accessToClass = Arrays.asList(ACCESS_TO_CLASS1, ACCESS_TO_CLASS2); | ||
|
||
final WebACAuthorization auth = new WebACAuthorizationImpl(agents, agentClasses, | ||
modes, accessTo, accessToClass); | ||
|
||
assertEquals(2, auth.getAgents().size()); | ||
assertTrue(auth.getAgents().contains(AGENT1)); | ||
assertEquals(2, auth.getAgentClasses().size()); | ||
assertTrue(auth.getAgentClasses().contains(AGENT_CLASS2)); | ||
assertEquals(2, auth.getModes().size()); | ||
assertTrue(auth.getModes().contains(WEBAC_MODE_READ)); | ||
assertEquals(3, auth.getAccessToURIs().size()); | ||
assertTrue(auth.getAccessToURIs().contains(ACCESS_TO3)); | ||
assertEquals(2, auth.getAccessToClassURIs().size()); | ||
assertTrue(auth.getAccessToClassURIs().contains(ACCESS_TO_CLASS2)); | ||
} | ||
|
||
@Test | ||
public void testSets() { | ||
final Set<String> agents = new HashSet<>(Arrays.asList(AGENT1, AGENT2)); | ||
final Set<String> agentClasses = new HashSet<>(Arrays.asList(AGENT_CLASS1, AGENT_CLASS2)); | ||
final Set<URI> modes = new HashSet<>(Arrays.asList(WEBAC_MODE_WRITE, WEBAC_MODE_READ)); | ||
final Set<String> accessTo = new HashSet<>(Arrays.asList(ACCESS_TO1, ACCESS_TO2, ACCESS_TO3)); | ||
final Set<String> accessToClass = new HashSet<>(Arrays.asList(ACCESS_TO_CLASS1, ACCESS_TO_CLASS2)); | ||
|
||
final WebACAuthorization auth = new WebACAuthorizationImpl(agents, agentClasses, | ||
modes, accessTo, accessToClass); | ||
|
||
assertEquals(2, auth.getAgents().size()); | ||
assertTrue(auth.getAgents().contains(AGENT1)); | ||
assertEquals(2, auth.getAgentClasses().size()); | ||
assertTrue(auth.getAgentClasses().contains(AGENT_CLASS2)); | ||
assertEquals(2, auth.getModes().size()); | ||
assertTrue(auth.getModes().contains(WEBAC_MODE_READ)); | ||
assertEquals(3, auth.getAccessToURIs().size()); | ||
assertTrue(auth.getAccessToURIs().contains(ACCESS_TO3)); | ||
assertEquals(2, auth.getAccessToClassURIs().size()); | ||
assertTrue(auth.getAccessToClassURIs().contains(ACCESS_TO_CLASS2)); | ||
} | ||
|
||
|
||
} |