use of org.codice.alliance.video.security.principal.videographer.VideographerPrincipal in project alliance by codice.
the class VideographerClaimsHandlerTest method testOtherClaim.
@Test
public void testOtherClaim() throws URISyntaxException {
claimsHandler = new VideographerClaimsHandler();
requestClaims = new ClaimCollection();
Claim requestClaim = new Claim();
URI fooURI = new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/foobar");
requestClaim.setClaimType(fooURI);
requestClaim.setOptional(true);
requestClaims.add(requestClaim);
claimsParameters = new ClaimsParameters();
claimsParameters.setPrincipal(new VideographerPrincipal(IP_ADDR));
claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
assertThat(claimsCollection, contains(getIpClaim()));
}
use of org.codice.alliance.video.security.principal.videographer.VideographerPrincipal in project alliance by codice.
the class VideographerClaimsHandlerTest method testNameClaim.
@SuppressWarnings("unchecked")
@Test
public void testNameClaim() throws URISyntaxException {
claimsHandler = new VideographerClaimsHandler();
claimsHandler.setAttributes(Collections.singletonList(CLAIM1));
requestClaims = new ClaimCollection();
Claim requestClaim = new Claim();
URI nameURI = new URI(CLAIM_URI_1);
requestClaim.setClaimType(nameURI);
requestClaims.add(requestClaim);
claimsParameters = new ClaimsParameters();
claimsParameters.setPrincipal(new VideographerPrincipal(IP_ADDR));
claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
assertThat(claimsCollection, containsInAnyOrder(getNameClaim(nameURI), getIpClaim()));
}
use of org.codice.alliance.video.security.principal.videographer.VideographerPrincipal in project alliance by codice.
the class VideographerClaimsHandler method retrieveClaimValues.
@Override
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, ClaimsParameters parameters) {
ProcessedClaimCollection claimsColl = new ProcessedClaimCollection();
Principal principal = parameters.getPrincipal();
if (principal instanceof VideographerPrincipal) {
for (Claim claim : claims) {
URI claimType = claim.getClaimType();
List<String> value = claimsMap.get(claimType);
if (value != null) {
ProcessedClaim c = new ProcessedClaim();
c.setClaimType(claimType);
c.setPrincipal(principal);
value.forEach(c::addValue);
claimsColl.add(c);
}
}
String ipAddress = ((VideographerPrincipal) principal).getAddress();
if (ipAddress != null) {
try {
ProcessedClaim ipClaim = new ProcessedClaim();
ipClaim.setClaimType(new URI(IP_ADDRESS_CLAIMS_KEY));
ipClaim.setPrincipal(principal);
ipClaim.addValue(ipAddress);
claimsColl.add(ipClaim);
} catch (URISyntaxException e) {
LOGGER.debug("Claims mapping cannot be converted to a URI. Ip claim will be excluded", e);
}
}
}
return claimsColl;
}
use of org.codice.alliance.video.security.principal.videographer.VideographerPrincipal in project alliance by codice.
the class VideographerValidator method validateToken.
@Override
public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParameters) {
TokenValidatorResponse response = new TokenValidatorResponse();
ReceivedToken validateTarget = tokenParameters.getToken();
validateTarget.setState(ReceivedToken.STATE.INVALID);
VideographerAuthenticationToken videographerToken = getVideographerTokenFromTarget(validateTarget);
response.setToken(validateTarget);
if (videographerToken != null) {
response.setPrincipal(new VideographerPrincipal(videographerToken.getIpAddress()));
if (videographerToken.getRealm() != null) {
if ((supportedRealms.contains(videographerToken.getRealm()) || WILDCARD.equals(videographerToken.getRealm())) && videographerToken.getCredentials().equals(VideographerAuthenticationToken.VIDEOGRAPHER_CREDENTIALS) && validIpAddress(videographerToken.getIpAddress())) {
validateTarget.setState(ReceivedToken.STATE.VALID);
validateTarget.setPrincipal(new VideographerPrincipal(videographerToken.getIpAddress()));
}
} else if (videographerToken.getCredentials().equals(VideographerAuthenticationToken.VIDEOGRAPHER_CREDENTIALS) && validIpAddress(videographerToken.getIpAddress())) {
validateTarget.setState(ReceivedToken.STATE.VALID);
validateTarget.setPrincipal(new VideographerPrincipal(videographerToken.getIpAddress()));
}
}
return response;
}
use of org.codice.alliance.video.security.principal.videographer.VideographerPrincipal in project alliance by codice.
the class VideographerClaimsHandlerTest method testEmailClaim.
@SuppressWarnings("unchecked")
@Test
public void testEmailClaim() throws URISyntaxException {
claimsHandler = new VideographerClaimsHandler();
claimsHandler.setAttributes(Collections.singletonList(CLAIM_URI_2 + "=" + CLAIM_VALUE_2A + "|" + CLAIM_VALUE_2B + "|" + CLAIM_VALUE_2C));
requestClaims = new ClaimCollection();
Claim requestClaim = new Claim();
URI emailURI = new URI(CLAIM_URI_2);
requestClaim.setClaimType(emailURI);
requestClaims.add(requestClaim);
claimsParameters = new ClaimsParameters();
claimsParameters.setPrincipal(new VideographerPrincipal(IP_ADDR));
claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
assertThat(claimsCollection, containsInAnyOrder(getEmailClaim(emailURI), getIpClaim()));
}
Aggregations