use of lombok.NonNull in project metacat by Netflix.
the class HiveConnectorFastPartitionService method getPartitionNames.
/**
* getPartitionNames.
*
* @param uris uris
* @param prefixSearch prefixSearch
* @return partition names
*/
@Override
public Map<String, List<QualifiedName>> getPartitionNames(@Nonnull final ConnectorContext context, @Nonnull final List<String> uris, final boolean prefixSearch) {
final long start = registry.clock().monotonicTime();
final Map<String, String> tags = new HashMap<String, String>();
tags.put("request", HiveMetrics.getPartitionNames.name());
final Map<String, List<QualifiedName>> result = Maps.newHashMap();
// Get data source
final DataSource dataSource = DataSourceManager.get().get(catalogName);
// Create the sql
final StringBuilder queryBuilder = new StringBuilder(SQL_GET_PARTITION_NAMES_BY_URI);
final List<String> params = Lists.newArrayList();
if (prefixSearch) {
queryBuilder.append(" 1=2");
uris.forEach(uri -> {
queryBuilder.append(" or location like ?");
params.add(uri + "%");
});
} else {
queryBuilder.append(" location in (");
Joiner.on(',').appendTo(queryBuilder, uris.stream().map(uri -> "?").collect(Collectors.toList()));
queryBuilder.append(")");
params.addAll(uris);
}
// Handler for reading the result set
final ResultSetHandler<Map<String, List<QualifiedName>>> handler = rs -> {
while (rs.next()) {
final String schemaName = rs.getString("schema_name");
final String tableName = rs.getString("table_name");
final String partitionName = rs.getString("partition_name");
final String uri = rs.getString("location");
final List<QualifiedName> partitionNames = result.get(uri);
final QualifiedName qualifiedName = QualifiedName.ofPartition(catalogName, schemaName, tableName, partitionName);
if (partitionNames == null) {
result.put(uri, Lists.newArrayList(qualifiedName));
} else {
partitionNames.add(qualifiedName);
}
}
return result;
};
try (Connection conn = dataSource.getConnection()) {
new QueryRunner().query(conn, queryBuilder.toString(), handler, params.toArray());
} catch (SQLException e) {
Throwables.propagate(e);
} finally {
final long duration = registry.clock().monotonicTime() - start;
log.debug("### Time taken to complete getPartitionNames is {} ms", duration);
this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
}
return result;
}
use of lombok.NonNull in project metacat by Netflix.
the class HiveConnectorFastTableService method getTableNames.
@Override
public Map<String, List<QualifiedName>> getTableNames(@Nonnull final ConnectorContext context, @Nonnull final List<String> uris, final boolean prefixSearch) {
final long start = registry.clock().monotonicTime();
final Map<String, String> tags = new HashMap<String, String>();
tags.put("request", HiveMetrics.getTableNames.name());
final Map<String, List<QualifiedName>> result = Maps.newHashMap();
// Get data source
final DataSource dataSource = DataSourceManager.get().get(catalogName);
// Create the sql
final StringBuilder queryBuilder = new StringBuilder(SQL_GET_TABLE_NAMES_BY_URI);
final List<String> params = Lists.newArrayList();
if (prefixSearch) {
queryBuilder.append(" and (1=0");
uris.forEach(uri -> {
queryBuilder.append(" or location like ?");
params.add(uri + "%");
});
queryBuilder.append(" )");
} else {
queryBuilder.append(" and location in (");
uris.forEach(uri -> {
queryBuilder.append("?,");
params.add(uri);
});
queryBuilder.deleteCharAt(queryBuilder.length() - 1).append(")");
}
// Handler for reading the result set
ResultSetHandler<Map<String, List<QualifiedName>>> handler = rs -> {
while (rs.next()) {
final String schemaName = rs.getString("schema_name");
final String tableName = rs.getString("table_name");
final String uri = rs.getString("location");
List<QualifiedName> names = result.get(uri);
if (names == null) {
names = Lists.newArrayList();
result.put(uri, names);
}
names.add(QualifiedName.ofTable(catalogName, schemaName, tableName));
}
return result;
};
try (Connection conn = dataSource.getConnection()) {
new QueryRunner().query(conn, queryBuilder.toString(), handler, params.toArray());
} catch (SQLException e) {
throw Throwables.propagate(e);
} finally {
final long duration = registry.clock().monotonicTime() - start;
log.debug("### Time taken to complete getTableNames is {} ms", duration);
this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
}
return result;
}
use of lombok.NonNull in project cas by apereo.
the class SamlIdPObjectSigner method buildSignatureSigningParameters.
/**
* Build signature signing parameters signature signing parameters.
*
* @param descriptor the descriptor
* @param service the service
* @return the signature signing parameters
* @throws SAMLException the saml exception
*/
@SneakyThrows
protected SignatureSigningParameters buildSignatureSigningParameters(final RoleDescriptor descriptor, final SamlRegisteredService service) throws SAMLException {
final CriteriaSet criteria = new CriteriaSet();
final SignatureSigningConfiguration signatureSigningConfiguration = getSignatureSigningConfiguration(descriptor, service);
criteria.add(new SignatureSigningConfigurationCriterion(signatureSigningConfiguration));
criteria.add(new RoleDescriptorCriterion(descriptor));
final SAMLMetadataSignatureSigningParametersResolver resolver = new SAMLMetadataSignatureSigningParametersResolver();
LOGGER.debug("Resolving signature signing parameters for [{}]", descriptor.getElementQName().getLocalPart());
@NonNull final SignatureSigningParameters params = resolver.resolveSingle(criteria);
LOGGER.debug("Created signature signing parameters." + "\nSignature algorithm: [{}]" + "\nSignature canonicalization algorithm: [{}]" + "\nSignature reference digest methods: [{}]", params.getSignatureAlgorithm(), params.getSignatureCanonicalizationAlgorithm(), params.getSignatureReferenceDigestMethod());
return params;
}
use of lombok.NonNull in project cas by apereo.
the class SamlObjectSignatureValidator method validateSignatureOnProfileRequest.
private void validateSignatureOnProfileRequest(final RequestAbstractType profileRequest, final Signature signature, final RoleDescriptorResolver roleDescriptorResolver) throws Exception {
final SAMLSignatureProfileValidator validator = new SAMLSignatureProfileValidator();
LOGGER.debug("Validating profile signature for [{}] via [{}]...", profileRequest.getIssuer(), validator.getClass().getSimpleName());
validator.validate(signature);
LOGGER.debug("Successfully validated profile signature for [{}].", profileRequest.getIssuer());
@NonNull final Set<Credential> credentials = getSigningCredential(roleDescriptorResolver, profileRequest);
if (credentials.isEmpty()) {
throw new SamlException("Signing credentials for validation could not be resolved based on the provided signature");
}
boolean foundValidCredential = false;
final Iterator<Credential> it = credentials.iterator();
while (!foundValidCredential && it.hasNext()) {
try {
final Credential c = it.next();
LOGGER.debug("Validating signature using credentials for [{}]", c.getEntityId());
SignatureValidator.validate(signature, c);
LOGGER.info("Successfully validated the request signature.");
foundValidCredential = true;
} catch (final Exception e) {
LOGGER.debug(e.getMessage(), e);
}
}
if (!foundValidCredential) {
LOGGER.error("No valid credentials could be found to verify the signature for [{}]", profileRequest.getIssuer());
throw new SamlException("No valid signing credentials for validation could not be resolved");
}
}
use of lombok.NonNull in project cas by apereo.
the class SamlProfileSamlSoap11ResponseBuilder method buildResponse.
@Override
protected Envelope buildResponse(final Assertion assertion, final Object casAssertion, final RequestAbstractType authnRequest, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final HttpServletRequest request, final HttpServletResponse response, final String binding) throws SamlException {
LOGGER.debug("Locating the assertion consumer service url for binding [{}]", binding);
@NonNull final AssertionConsumerService acs = adaptor.getAssertionConsumerService(binding);
LOGGER.debug("Located assertion consumer service url [{}]", acs);
final Response ecpResponse = newEcpResponse(acs.getLocation());
final Header header = newSoapObject(Header.class);
header.getUnknownXMLObjects().add(ecpResponse);
final Body body = newSoapObject(Body.class);
final org.opensaml.saml.saml2.core.Response saml2Response = buildSaml2Response(casAssertion, authnRequest, service, adaptor, request, binding);
body.getUnknownXMLObjects().add(saml2Response);
final Envelope envelope = newSoapObject(Envelope.class);
envelope.setHeader(header);
envelope.setBody(body);
SamlUtils.logSamlObject(this.configBean, envelope);
return envelope;
}
Aggregations