Search in sources :

Example 1 with ApiClient

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);
    }
}
Also used : CertificateLocator(com.intel.mtwilson.datatypes.CertificateLocator) AssetTagCertRevokeRequest(com.intel.mtwilson.datatypes.AssetTagCertRevokeRequest) CertificateDAO(com.intel.mtwilson.tag.dao.jdbi.CertificateDAO) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) ApiClient(com.intel.mtwilson.ApiClient) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) WebApplicationException(javax.ws.rs.WebApplicationException) Certificate(com.intel.mtwilson.datatypes.Certificate) POST(javax.ws.rs.POST)

Example 2 with ApiClient

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;
}
Also used : ApiClient(com.intel.mtwilson.ApiClient) File(com.intel.mtwilson.datatypes.File) IOException(java.io.IOException)

Example 3 with ApiClient

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;
}
Also used : SimpleKeystore(com.intel.mtwilson.util.crypto.SimpleKeystore) HttpSession(javax.servlet.http.HttpSession) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ModelAndView(org.springframework.web.servlet.ModelAndView) Properties(java.util.Properties) ApiClient(com.intel.mtwilson.ApiClient) File(java.io.File) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate)

Example 4 with ApiClient

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));
}
Also used : HostTrustResponse(com.intel.mtwilson.datatypes.HostTrustResponse) Hostname(com.intel.mtwilson.util.net.Hostname) ApiClient(com.intel.mtwilson.ApiClient)

Aggregations

ApiClient (com.intel.mtwilson.ApiClient)4 AssetTagCertRevokeRequest (com.intel.mtwilson.datatypes.AssetTagCertRevokeRequest)1 Certificate (com.intel.mtwilson.datatypes.Certificate)1 CertificateLocator (com.intel.mtwilson.datatypes.CertificateLocator)1 File (com.intel.mtwilson.datatypes.File)1 HostTrustResponse (com.intel.mtwilson.datatypes.HostTrustResponse)1 CertificateDAO (com.intel.mtwilson.tag.dao.jdbi.CertificateDAO)1 RepositoryException (com.intel.mtwilson.tag.repository.RepositoryException)1 RepositoryInvalidInputException (com.intel.mtwilson.tag.repository.RepositoryInvalidInputException)1 SimpleKeystore (com.intel.mtwilson.util.crypto.SimpleKeystore)1 Hostname (com.intel.mtwilson.util.net.Hostname)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 X509Certificate (java.security.cert.X509Certificate)1 Properties (java.util.Properties)1 HttpSession (javax.servlet.http.HttpSession)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MapConfiguration (org.apache.commons.configuration.MapConfiguration)1