Skip to content

Commit 7f56828

Browse files
authored
DDF-04481 Removed realm support from the Web Context Policy Manager (#715)
1 parent c588d8f commit 7f56828

File tree

13 files changed

+68
-111
lines changed

13 files changed

+68
-111
lines changed

catalog/nsili/catalog-nsili-endpoint/src/main/java/org/codice/alliance/nsili/endpoint/NsiliEndpoint.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.codice.alliance.nsili.orb.api.CorbaServiceListener;
3535
import org.codice.ddf.security.common.Security;
3636
import org.codice.ddf.security.handler.api.AuthenticationHandler;
37-
import org.codice.ddf.security.handler.api.BaseAuthenticationToken;
3837
import org.codice.ddf.security.handler.api.GuestAuthenticationToken;
3938
import org.omg.CORBA.ORB;
4039
import org.omg.CORBA.ORBPackage.InvalidName;
@@ -385,8 +384,7 @@ public static synchronized Subject getGuestSubject() throws SecurityServiceExcep
385384
}
386385

387386
String guestTokenId = ip;
388-
GuestAuthenticationToken guestToken =
389-
new GuestAuthenticationToken(BaseAuthenticationToken.ALL_REALM, guestTokenId);
387+
GuestAuthenticationToken guestToken = new GuestAuthenticationToken(guestTokenId);
390388
guestSubject = securityManager.getSubject(guestToken);
391389
}
392390

catalog/video/video-mpegts-stream/src/main/java/org/codice/alliance/video/stream/mpegts/netty/RawUdpDataToMTSPacketDecoder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.codice.alliance.libs.mpegts.Constants;
3232
import org.codice.alliance.video.security.token.videographer.VideographerAuthenticationToken;
3333
import org.codice.ddf.security.common.Security;
34-
import org.codice.ddf.security.handler.api.BaseAuthenticationToken;
3534
import org.osgi.framework.Bundle;
3635
import org.osgi.framework.BundleContext;
3736
import org.osgi.framework.FrameworkUtil;
@@ -96,8 +95,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {
9695

9796
private Subject getSecuritySubject(String ipAddress) throws SecurityServiceException {
9897
Subject subject = null;
99-
VideographerAuthenticationToken token =
100-
new VideographerAuthenticationToken(BaseAuthenticationToken.DEFAULT_REALM, ipAddress);
98+
VideographerAuthenticationToken token = new VideographerAuthenticationToken(ipAddress);
10199
LOGGER.debug(
102100
"Getting new videographer user token for ip address {}: token={}", ipAddress, token);
103101

catalog/video/video-security/src/main/java/org/codice/alliance/video/security/token/videographer/VideographerAuthenticationToken.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public class VideographerAuthenticationToken extends BSTAuthenticationToken {
2929
+ BSTAuthenticationToken.TOKEN_VALUE_SEPARATOR
3030
+ BST_VIDEOGRAPHER_LN;
3131

32-
public VideographerAuthenticationToken(String realm, String ip) {
33-
super(new VideographerPrincipal(ip), VIDEOGRAPHER_CREDENTIALS, realm);
32+
public VideographerAuthenticationToken(String ip) {
33+
super(new VideographerPrincipal(ip), VIDEOGRAPHER_CREDENTIALS);
3434
setTokenValueType(BSTAuthenticationToken.BST_NS, BST_VIDEOGRAPHER_LN);
3535
setTokenId(BST_VIDEOGRAPHER_LN);
3636

@@ -59,6 +59,6 @@ public String getIpAddress() {
5959

6060
@Override
6161
public String toString() {
62-
return "Videographer IP: " + getIpAddress() + "; realm: " + realm;
62+
return "Videographer IP: " + getIpAddress();
6363
}
6464
}

catalog/video/video-security/src/main/java/org/codice/alliance/video/security/validator/videographer/VideographerValidator.java

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
package org.codice.alliance.video.security.validator.videographer;
1515

16-
import java.util.List;
1716
import org.apache.commons.validator.routines.InetAddressValidator;
1817
import org.apache.cxf.sts.request.ReceivedToken;
1918
import org.apache.cxf.sts.token.validator.TokenValidator;
@@ -33,8 +32,6 @@ public class VideographerValidator implements TokenValidator {
3332

3433
private static final String WILDCARD = "*";
3534

36-
private List<String> supportedRealms;
37-
3835
private VideographerAuthenticationToken getVideographerTokenFromTarget(
3936
ReceivedToken validateTarget) {
4037

@@ -48,7 +45,6 @@ private VideographerAuthenticationToken getVideographerTokenFromTarget(
4845
try {
4946
BaseAuthenticationToken base = VideographerAuthenticationToken.parse(credential, true);
5047
return new VideographerAuthenticationToken(
51-
base.getRealm(),
5248
VideographerPrincipal.parseAddressFromName(base.getPrincipal().toString()));
5349
} catch (WSSecurityException e) {
5450
LOGGER.debug(
@@ -80,22 +76,12 @@ public boolean canHandleToken(ReceivedToken validateTarget, String realm) {
8076
// based on the web context. So this just looks at the realm passed in the credentials.
8177
// This generic instance just looks for the default realms (DDF and Karaf)
8278
if (videographerToken != null) {
83-
if (videographerToken.getRealm() == null) {
84-
LOGGER.trace("No realm specified in request, canHandletoken = true");
85-
return true;
86-
} else {
87-
if (supportedRealms.contains(videographerToken.getRealm())
88-
|| WILDCARD.equals(videographerToken.getRealm())) {
89-
LOGGER.trace(
90-
"Realm '{}' recognized - canHandleToken = true", videographerToken.getRealm());
91-
return true;
92-
} else {
93-
LOGGER.trace(
94-
"Realm '{}' unrecognized - canHandleToken = false", videographerToken.getRealm());
95-
}
96-
}
79+
LOGGER.trace("canHandletoken = true");
80+
return true;
81+
} else {
82+
LOGGER.trace("canHandleToken = false");
83+
return false;
9784
}
98-
return false;
9985
}
10086

10187
@Override
@@ -112,17 +98,7 @@ public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParame
11298
if (videographerToken != null) {
11399
response.setPrincipal(new VideographerPrincipal(videographerToken.getIpAddress()));
114100

115-
if (videographerToken.getRealm() != null) {
116-
if ((supportedRealms.contains(videographerToken.getRealm())
117-
|| WILDCARD.equals(videographerToken.getRealm()))
118-
&& videographerToken
119-
.getCredentials()
120-
.equals(VideographerAuthenticationToken.VIDEOGRAPHER_CREDENTIALS)
121-
&& validIpAddress(videographerToken.getIpAddress())) {
122-
validateTarget.setState(ReceivedToken.STATE.VALID);
123-
validateTarget.setPrincipal(new VideographerPrincipal(videographerToken.getIpAddress()));
124-
}
125-
} else if (videographerToken
101+
if (videographerToken
126102
.getCredentials()
127103
.equals(VideographerAuthenticationToken.VIDEOGRAPHER_CREDENTIALS)
128104
&& validIpAddress(videographerToken.getIpAddress())) {
@@ -132,14 +108,4 @@ && validIpAddress(videographerToken.getIpAddress())) {
132108
}
133109
return response;
134110
}
135-
136-
/**
137-
* Set the realm that this validator supports. This can be used to differentiate between two
138-
* instances of this validator where each contains a differnent token validator.
139-
*
140-
* @param supportedRealms string representing the realm supported by this validator
141-
*/
142-
public void setSupportedRealms(List<String> supportedRealms) {
143-
this.supportedRealms = supportedRealms;
144-
}
145111
}

catalog/video/video-security/src/main/resources/OSGI-INF/blueprint/blueprint.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,7 @@
3030

3131
<service ref="videographerClaimsHandler" interface="org.apache.cxf.sts.claims.ClaimsHandler"/>
3232

33-
<bean id="videographerValidator" class="org.codice.alliance.video.security.validator.videographer.VideographerValidator">
34-
35-
<cm:managed-properties persistent-id="org.codice.alliance.video.security.validator.videographer.VideographerValidator"
36-
update-strategy="container-managed"/>
37-
38-
<property name="supportedRealms">
39-
<list>
40-
<value>karaf</value>
41-
<value>ldap</value>
42-
</list>
43-
</property>
44-
</bean>
33+
<bean id="videographerValidator" class="org.codice.alliance.video.security.validator.videographer.VideographerValidator"/>
4534

4635
<service ref="videographerValidator" interface="org.apache.cxf.sts.token.validator.TokenValidator"/>
4736

catalog/video/video-security/src/main/resources/OSGI-INF/metatype/metatype.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@
2525

2626
</OCD>
2727

28-
<OCD description="Videographer Validator"
29-
name="Videographer Validator"
30-
id="org.codice.alliance.video.security.validator.videographer.VideographerValidator">
31-
32-
<AD description="Supported Realms"
33-
name="Supported Realms" id="supportedRealms" required="true" type="String"
34-
default="karaf,ldap"
35-
cardinality="100"/>
36-
37-
</OCD>
38-
3928
<Designate pid="org.codice.alliance.video.security.claims.videographer.VideographerClaimsHandler">
4029
<Object ocdref="org.codice.alliance.video.security.claims.videographer.VideographerClaimsHandler"/>
4130
</Designate>

catalog/video/video-security/src/test/java/org/codice/alliance/video/security/token/videographer/VideographerAuthenticationTokenTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ public class VideographerAuthenticationTokenTest {
2424

2525
@Test
2626
public void testConstructor() {
27-
final String realm = "someRealm";
28-
VideographerAuthenticationToken token = new VideographerAuthenticationToken(realm, "127.0.0.1");
27+
VideographerAuthenticationToken token = new VideographerAuthenticationToken("127.0.0.1");
2928
assertThat(token.getPrincipal(), is(instanceOf(VideographerPrincipal.class)));
3029
assertThat(
3130
token.getCredentials(), is(VideographerAuthenticationToken.VIDEOGRAPHER_CREDENTIALS));
32-
assertThat(token.getRealm(), is(realm));
3331
assertThat(
3432
token.getTokenValueType(),
3533
is(VideographerAuthenticationToken.VIDEOGRAPHER_TOKEN_VALUE_TYPE));

catalog/video/video-security/src/test/java/org/codice/alliance/video/security/validator/videographer/VideographerValidatorTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.hamcrest.core.IsInstanceOf.instanceOf;
1919

2020
import java.util.Base64;
21-
import java.util.Collections;
2221
import javax.xml.bind.JAXBElement;
2322
import javax.xml.bind.JAXBException;
2423
import javax.xml.namespace.QName;
@@ -59,21 +58,20 @@ public class VideographerValidatorTest {
5958
@Before
6059
public void setup() {
6160
validator = new VideographerValidator();
62-
validator.setSupportedRealms(Collections.singletonList("DDF"));
6361
VideographerAuthenticationToken videographerAuthenticationToken =
64-
new VideographerAuthenticationToken("DDF", "127.0.0.1");
62+
new VideographerAuthenticationToken("127.0.0.1");
6563

6664
VideographerAuthenticationToken videographerAuthenticationTokenAnyRealm =
67-
new VideographerAuthenticationToken("*", "127.0.0.1");
65+
new VideographerAuthenticationToken("127.0.0.1");
6866

6967
VideographerAuthenticationToken videographerAuthenticationTokenIpv6 =
70-
new VideographerAuthenticationToken("*", "0:0:0:0:0:0:0:1");
68+
new VideographerAuthenticationToken("0:0:0:0:0:0:0:1");
7169

7270
VideographerAuthenticationToken videographerAuthenticationTokenBadIp =
73-
new VideographerAuthenticationToken("*", "123.abc.45.def");
71+
new VideographerAuthenticationToken("123.abc.45.def");
7472

7573
VideographerAuthenticationToken videographerAuthenticationTokenIpv6Reachability =
76-
new VideographerAuthenticationToken("*", "0:0:0:0:0:0:0:1%4");
74+
new VideographerAuthenticationToken("0:0:0:0:0:0:0:1%4");
7775

7876
BinarySecurityTokenType binarySecurityTokenType = new BinarySecurityTokenType();
7977
binarySecurityTokenType.setValueType(

distribution/test/itests/test-itests-alliance/src/test/java/org/codice/alliance/test/itests/BannerMarkingsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class BannerMarkingsTest extends AbstractAllianceIntegrationTest {
5757
public void beforeAllianceTest() throws Exception {
5858
try {
5959
waitForSystemReady();
60+
getSecurityPolicy().configureRestForGuest();
61+
waitForSystemReady();
6062

6163
} catch (Exception e) {
6264
LOGGER.error("Failed in @BeforeExam: ", e);

distribution/test/itests/test-itests-alliance/src/test/java/org/codice/alliance/test/itests/ImagingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class ImagingTest extends AbstractAllianceIntegrationTest {
6767
@BeforeExam
6868
public void beforeAllianceTest() throws Exception {
6969
try {
70+
waitForSystemReady();
71+
getSecurityPolicy().configureRestForGuest();
7072
waitForSystemReady();
7173
getServiceManager().startFeature(true, "nitf-render-plugin");
7274
} catch (Exception e) {

distribution/test/itests/test-itests-alliance/src/test/java/org/codice/alliance/test/itests/NsiliEndpointTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public class NsiliEndpointTest extends AbstractAllianceIntegrationTest {
8181
public void beforeNsiliEndpointTest() throws Exception {
8282
try {
8383
waitForSystemReady();
84-
84+
getSecurityPolicy().configureRestForGuest();
85+
waitForSystemReady();
8586
System.setProperty(CORBA_DEFAULT_PORT_PROPERTY, CORBA_DEFAULT_PORT.getPort());
8687

8788
startHttpListener();

distribution/test/itests/test-itests-alliance/src/test/java/org/codice/alliance/test/itests/NsiliSourceTest.java

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public class NsiliSourceTest extends AbstractAllianceIntegrationTest {
7575
public void beforeAllianceTest() throws Exception {
7676
try {
7777
waitForSystemReady();
78+
getSecurityPolicy().configureRestForGuest();
79+
waitForSystemReady();
7880

7981
System.setProperty(CORBA_DEFAULT_PORT_PROPERTY, CORBA_DEFAULT_PORT.getPort());
8082

@@ -103,20 +105,26 @@ public void beforeAllianceTest() throws Exception {
103105
*/
104106
@Test
105107
public void testNsiliHttpSourceAvailable() throws Exception {
106-
// @formatter:off
107-
given()
108-
.auth()
109-
.basic("admin", "admin")
110-
.header("X-Requested-With", "XMLHttpRequest")
111-
.header("Origin", ADMIN_ALL_SOURCES_PATH.getUrl())
112-
.when()
113-
.get(ADMIN_ALL_SOURCES_PATH.getUrl())
114-
.then()
115-
.log()
116-
.all()
117-
.assertThat()
118-
.body(containsString("\"id\":\"httpNsiliSource\""));
119-
// @formatter:on
108+
try {
109+
getSecurityPolicy().configureRestForBasic();
110+
111+
// @formatter:off
112+
given()
113+
.auth()
114+
.basic("admin", "admin")
115+
.header("X-Requested-With", "XMLHttpRequest")
116+
.header("Origin", ADMIN_ALL_SOURCES_PATH.getUrl())
117+
.when()
118+
.get(ADMIN_ALL_SOURCES_PATH.getUrl())
119+
.then()
120+
.log()
121+
.all()
122+
.assertThat()
123+
.body(containsString("\"id\":\"httpNsiliSource\""));
124+
// @formatter:on
125+
} finally {
126+
getSecurityPolicy().configureRestForGuest();
127+
}
120128
}
121129

122130
/**
@@ -126,20 +134,26 @@ public void testNsiliHttpSourceAvailable() throws Exception {
126134
*/
127135
@Test
128136
public void testNsiliFtpSourceAvailable() throws Exception {
129-
// @formatter:off
130-
given()
131-
.auth()
132-
.basic("admin", "admin")
133-
.header("X-Requested-With", "XMLHttpRequest")
134-
.header("Origin", ADMIN_ALL_SOURCES_PATH.getUrl())
135-
.when()
136-
.get(ADMIN_ALL_SOURCES_PATH.getUrl())
137-
.then()
138-
.log()
139-
.all()
140-
.assertThat()
141-
.body(containsString("\"id\":\"ftpNsiliSource\""));
142-
// @formatter:on
137+
try {
138+
getSecurityPolicy().configureRestForBasic();
139+
140+
// @formatter:off
141+
given()
142+
.auth()
143+
.basic("admin", "admin")
144+
.header("X-Requested-With", "XMLHttpRequest")
145+
.header("Origin", ADMIN_ALL_SOURCES_PATH.getUrl())
146+
.when()
147+
.get(ADMIN_ALL_SOURCES_PATH.getUrl())
148+
.then()
149+
.log()
150+
.all()
151+
.assertThat()
152+
.body(containsString("\"id\":\"ftpNsiliSource\""));
153+
// @formatter:on
154+
} finally {
155+
getSecurityPolicy().configureRestForGuest();
156+
}
143157
}
144158

145159
/**

distribution/test/itests/test-itests-alliance/src/test/java/org/codice/alliance/test/itests/VideoTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class VideoTest extends AbstractAllianceIntegrationTest {
7474

7575
@BeforeExam
7676
public void beforeExam() throws Exception {
77+
waitForSystemReady();
78+
getSecurityPolicy().configureRestForBasic();
7779
waitForSystemReady();
7880
udpPort = new DynamicPort(6);
7981
udpPortNum = Integer.parseInt(udpPort.getPort());

0 commit comments

Comments
 (0)