use of com.intel.mtwilson.ApiClient in project OpenAttestation by OpenAttestation.
the class RevokeTagCertificate method revokeCert.
@POST
public //@RequiresPermissions("tag_certificates:delete")
void revokeCert(@QueryParam("certId") String certId) {
log.debug("RPC: RevokeTagCertificate - Got request to revocation of certificate: {}", certId);
setCertificateId(UUID.valueOf(certId));
try (CertificateDAO dao = TagJdbi.certificateDao()) {
CertificateLocator locator = new CertificateLocator();
locator.id = certificateId;
Certificate obj = dao.findById(certificateId);
if (obj != null) {
// tries jvm properties, environment variables, then mtwilson.properties; you can set location of mtwilson.properties with -Dmtwilson.home=/path/to/dir
org.apache.commons.configuration.Configuration conf = ConfigurationUtil.getConfiguration();
ApiClient mtwilson = new ApiClient(conf);
log.debug("RPC: RevokeTagCertificate - Sha1 of the certificate about to be revoked is {}.", obj.getSha1());
dao.updateRevoked(certificateId, true);
AssetTagCertRevokeRequest request = new AssetTagCertRevokeRequest();
request.setSha1OfAssetCert(obj.getSha1().toByteArray());
mtwilson.revokeAssetTagCertificate(request);
//Global.mtwilson().revokeAssetTagCertificate(request);
log.info("RPC: RevokeTagCertificate - Certificate with id {} has been revoked successfully.");
} else {
log.error("RPC: RevokeTagCertificate - Certificate with id {} does not exist.", certificateId);
throw new RepositoryInvalidInputException(locator);
}
} catch (RepositoryException re) {
throw re;
} catch (Exception ex) {
log.error("RPC: RevokeTagCertificate - Error during certificate revocation.", ex);
throw new RepositoryException(ex);
}
}
use of com.intel.mtwilson.ApiClient in project OpenAttestation by OpenAttestation.
the class Global method mtwilson.
//public static MtWilson mtwilson() {
public static ApiClient mtwilson() {
if (mtwilson == null) {
// the mtwilson api client keystore is stored in our database as a file
log.debug("Preparing Mt Wilson Web Service API Client...");
FileDAO fileDao = null;
//ByteArrayResource keystoreResource = null; //292 and 293 Variable is not being used after assigned
try {
fileDao = TagJdbi.fileDao();
File mtwilsonKeystoreFile = fileDao.findByName("mtwilson-client-keystore");
if (mtwilsonKeystoreFile == null) {
log.debug("Cannot find 'mtwilson-client-keystore' file");
}
// else {
// keystoreResource = new ByteArrayResource(mtwilsonKeystoreFile.getContent());
// }
} catch (Exception e) {
log.error("Cannot load mtwilson-client-keystore", e);
} finally {
if (fileDao != null) {
fileDao.close();
}
}
try {
if (mtwilson == null) {
// tries jvm properties, environment variables, then mtwilson.properties; you can set location of mtwilson.properties with -Dmtwilson.home=/path/to/dir
org.apache.commons.configuration.Configuration conf = ConfigurationUtil.getConfiguration();
mtwilson = new ApiClient(conf);
}
//mtwilson = factory.clientForUserInResource(keystoreResource, keystoreUsername, keystorePassword, url);
} catch (Exception e) {
log.error("Cannot create MtWilson client", e);
}
}
return mtwilson;
}
use of com.intel.mtwilson.ApiClient in project OpenAttestation by OpenAttestation.
the class CheckLoginController method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
logger.info("CheckLoginController >>");
//Creating ModelAndView Object with Login page to return to user if Login is not successful.
ModelAndView view = new ModelAndView("Login");
//RsaCredential credential = null;
File keystoreFile = null;
SimpleKeystore keystore = null;
String username = "admin";
URL baseURL = new URL(WLMPConfig.getConfiguration().getString("mtwilson.api.baseurl"));
final String keystoreFilename = WLMPConfig.getConfiguration().getString("mtwilson.wlmp.keystore.dir") + File.separator + "portal.jks";
final String keystorePassword = WLMPConfig.getConfiguration().getString("mtwilson.wlmp.keystore.password");
try {
//this line will throw exception if file with username is not present in specific dir.
keystoreFile = new File(keystoreFilename);
} catch (Exception e) {
logger.severe("File Not found on server >> " + keystoreFilename);
view.addObject("message", "Key store is not configured/saved correctly in " + keystoreFilename + ".");
return view;
}
try {
keystore = new SimpleKeystore(keystoreFile, keystorePassword);
//credential = keystore.getRsaCredentialX509(username, keystorePassword);
} catch (Exception e) {
view.addObject("result", false);
view.addObject("message", "Username or Password does not match. Please try again.");
return view;
}
try {
Properties p = new Properties();
// must be secure out of the box!
p.setProperty("mtwilson.api.ssl.policy", WLMPConfig.getConfiguration().getString("mtwilson.api.ssl.policy", "TRUST_CA_VERIFY_HOSTNAME"));
// must be secure out of the box!
p.setProperty("mtwilson.api.ssl.requireTrustedCertificate", WLMPConfig.getConfiguration().getString("mtwilson.api.ssl.requireTrustedCertificate", "true"));
// must be secure out of the box!
p.setProperty("mtwilson.api.ssl.verifyHostname", WLMPConfig.getConfiguration().getString("mtwilson.api.ssl.verifyHostname", "true"));
// Instantiate the API Client object and store it in the session. Otherwise either we need
// to store the password in the session or the decrypted RSA key
ApiClient rsaApiClient = new ApiClient(baseURL, keystore, new MapConfiguration(p));
//Storing variable into a session object used while calling into RESt Services.
HttpSession session = req.getSession();
session.setAttribute("logged-in", true);
session.setAttribute("username", username);
session.setAttribute("apiClientObject", rsaApiClient);
session.setMaxInactiveInterval(WLMPConfig.getConfiguration().getInt("mtwilson.wlmp.sessionTimeOut"));
X509Certificate[] trustedCertificates = keystore.getTrustedCertificates(SimpleKeystore.SAML);
session.setAttribute("trustedCertificates", trustedCertificates);
//Redirecting user to a home page after successful login.
res.sendRedirect("home.html");
} catch (Exception e) {
view.addObject("message", "The username or password you entered is incorrect.");
return view;
}
return null;
}
use of com.intel.mtwilson.ApiClient in project OpenAttestation by OpenAttestation.
the class GetHostTrust method execute.
@Override
public void execute(String[] args) throws Exception {
ApiClient api = getClient();
HostTrustResponse response = api.getHostTrust(new Hostname(args[0]));
System.out.println(toJson(response));
}
Aggregations