use of javax.xml.bind.JAXBElement in project ddf by codice.
the class FederationAdminServiceImplTest method testGetLocalRegistryObjects.
@Test
public void testGetLocalRegistryObjects() throws Exception {
Metacard localMetacardOne = testMetacard;
Metacard localMetacardTwo = testMetacard;
List<Metacard> localMetacards = new ArrayList<>();
localMetacards.add(localMetacardOne);
localMetacards.add(localMetacardTwo);
doReturn(localMetacards).when(federationAdminServiceImpl).getLocalRegistryMetacards();
JAXBElement<RegistryPackageType> jaxbRegistryPackage = EbrimConstants.RIM_FACTORY.createRegistryPackage(getTestRegistryPackage());
when(parser.unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class))).thenReturn(jaxbRegistryPackage);
List<RegistryPackageType> packages = federationAdminServiceImpl.getLocalRegistryObjects();
assertThat(packages, hasSize(2));
verify(parser, times(2)).unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class));
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryObjects.
@Test
public void testGetRegistryObjects() throws Exception {
Metacard metacardOne = testMetacard;
Metacard metacardTwo = testMetacard;
JAXBElement<RegistryPackageType> jaxbRegistryPackage = EbrimConstants.RIM_FACTORY.createRegistryPackage(getTestRegistryPackage());
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, metacardOne, metacardTwo);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
when(parser.unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class))).thenReturn(jaxbRegistryPackage);
List<RegistryPackageType> regObjects = federationAdminServiceImpl.getRegistryObjects();
assertThat(regObjects, hasSize(2));
verify(catalogFramework).query(any(QueryRequest.class));
verify(parser, times(2)).unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class));
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class TestCswEndpoint method testMarshallDescribeRecord.
/**
* Tests to see that JAXB configuration is working
*/
@Test
public void testMarshallDescribeRecord() {
DescribeRecordResponseType response = new DescribeRecordResponseType();
List<SchemaComponentType> schemas = new ArrayList<>();
SchemaComponentType schemaComponentType = new SchemaComponentType();
schemas.add(schemaComponentType);
response.setSchemaComponent(schemas);
JAXBContext context;
try {
context = JAXBContext.newInstance("net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1");
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
StringWriter sw = new StringWriter();
JAXBElement<DescribeRecordResponseType> wrappedResponse = new JAXBElement<>(cswQnameOutPutSchema, DescribeRecordResponseType.class, response);
marshaller.marshal(wrappedResponse, sw);
LOGGER.info("Response: {}", sw.toString());
} catch (JAXBException e) {
fail("Could not marshall message, Error: " + e.getMessage());
}
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class TestCswEndpoint method testPostGetRecordsValidElementSetNames.
@Test
public void testPostGetRecordsValidElementSetNames() throws CswException {
GetRecordsType grr = createDefaultPostRecordsRequest();
QueryType query = new QueryType();
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
ElementSetNameType elsnt = new ElementSetNameType();
elsnt.setValue(ElementSetType.BRIEF);
query.setElementSetName(elsnt);
grr.setAbstractQuery(jaxbQuery);
csw.getRecords(grr);
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class UsernameTokenValidator method validateToken.
/**
* Validate a Token using the given TokenValidatorParameters.
*/
public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParameters) {
LOGGER.debug("Validating UsernameToken");
if (parser == null) {
throw new IllegalStateException("XMLParser must be configured.");
}
if (failedLoginDelayer == null) {
throw new IllegalStateException("Failed Login Delayer must be configured");
}
STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
Crypto sigCrypto = stsProperties.getSignatureCrypto();
CallbackHandler callbackHandler = stsProperties.getCallbackHandler();
RequestData requestData = new RequestData();
requestData.setSigVerCrypto(sigCrypto);
WSSConfig wssConfig = WSSConfig.getNewInstance();
requestData.setWssConfig(wssConfig);
requestData.setCallbackHandler(callbackHandler);
TokenValidatorResponse response = new TokenValidatorResponse();
ReceivedToken validateTarget = tokenParameters.getToken();
validateTarget.setState(ReceivedToken.STATE.INVALID);
response.setToken(validateTarget);
if (!validateTarget.isUsernameToken()) {
return response;
}
//
// Turn the JAXB UsernameTokenType into a DOM Element for validation
//
UsernameTokenType usernameTokenType = (UsernameTokenType) validateTarget.getToken();
JAXBElement<UsernameTokenType> tokenType = new JAXBElement<>(QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameTokenType);
Document doc = DOMUtils.createDocument();
Element rootElement = doc.createElement("root-element");
List<String> ctxPath = new ArrayList<>(1);
ctxPath.add(UsernameTokenType.class.getPackage().getName());
Element usernameTokenElement = null;
ParserConfigurator configurator = parser.configureParser(ctxPath, UsernameTokenValidator.class.getClassLoader());
try {
parser.marshal(configurator, tokenType, rootElement);
usernameTokenElement = (Element) rootElement.getFirstChild();
} catch (ParserException ex) {
LOGGER.info("Unable to parse username token", ex);
return response;
}
//
try {
boolean allowNamespaceQualifiedPasswordTypes = requestData.isAllowNamespaceQualifiedPasswordTypes();
UsernameToken ut = new UsernameToken(usernameTokenElement, allowNamespaceQualifiedPasswordTypes, new BSPEnforcer());
// The parsed principal is set independent whether validation is successful or not
response.setPrincipal(new CustomTokenPrincipal(ut.getName()));
if (ut.getPassword() == null) {
failedLoginDelayer.delay(ut.getName());
return response;
}
Credential credential = new Credential();
credential.setUsernametoken(ut);
//Only this section is new, the rest is copied from the apache class
Set<Map.Entry<String, Validator>> entries = validators.entrySet();
for (Map.Entry<String, Validator> entry : entries) {
try {
entry.getValue().validate(credential, requestData);
validateTarget.setState(ReceivedToken.STATE.VALID);
break;
} catch (WSSecurityException ex) {
LOGGER.debug("Unable to validate user against {}" + entry.getKey(), ex);
}
}
if (ReceivedToken.STATE.INVALID.equals(validateTarget.getState())) {
failedLoginDelayer.delay(ut.getName());
return response;
}
//end new section
Principal principal = createPrincipal(ut.getName(), ut.getPassword(), ut.getPasswordType(), ut.getNonce(), ut.getCreated());
response.setPrincipal(principal);
response.setTokenRealm(null);
validateTarget.setState(ReceivedToken.STATE.VALID);
validateTarget.setPrincipal(principal);
} catch (WSSecurityException ex) {
LOGGER.debug("Unable to validate token.", ex);
}
return response;
}
Aggregations