Code cleanup
This commit is contained in:
parent
340a61504d
commit
88a046379f
3 changed files with 55 additions and 8 deletions
|
@ -22,29 +22,74 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionSuppor
|
|||
/** Concrete EntityDAO interface of Certificate entities */
|
||||
public interface CertificateDAO extends BulkActionSupportDAO<CertificateInfo> {
|
||||
|
||||
/** Get the certificate with given alias for specified institution.
|
||||
*
|
||||
* @param institutionId Institution identifier
|
||||
* @param alias the alias name of the certificate to get
|
||||
* @return Result refer to the Certificate or to an error when happened. */
|
||||
Result<Certificate> getCertificate(final Long institutionId, String alias);
|
||||
|
||||
/** Get all certificates of a given institution,
|
||||
*
|
||||
* @param institutionId Institution identifier
|
||||
* @return Result to the Certificates or to an error when happend */
|
||||
Result<Certificates> getCertificates(Long institutionId);
|
||||
|
||||
/** Add a new uploaded certificate to the certificate store of the institution.
|
||||
*
|
||||
* @param institutionId Institution identifier
|
||||
* @param alias the alias name of the institution
|
||||
* @param certificate the certificate to add.
|
||||
* @return Result refer to the generated CertificateInfo or to an error when happened */
|
||||
Result<CertificateInfo> addCertificate(
|
||||
Long institutionId,
|
||||
String alias,
|
||||
Certificate certificate);
|
||||
|
||||
/** Add a new uploaded certificate with private key to the certificate store of the institution.
|
||||
*
|
||||
* @param institutionId Institution identifier
|
||||
* @param alias the alias name of the institution
|
||||
* @param certificate the certificate to add.
|
||||
* @param privateKey the private key of the certificate
|
||||
* @return Result refer to the generated CertificateInfo or to an error when happened */
|
||||
Result<CertificateInfo> addCertificate(
|
||||
Long institutionId,
|
||||
String alias,
|
||||
Certificate certificate,
|
||||
PrivateKey privateKey);
|
||||
|
||||
/** Removes specified certificate from the certificate store of a given institution.
|
||||
*
|
||||
* @param institutionId The institution identifier
|
||||
* @param alias the alias name of the certificate
|
||||
* @return Result refer to the entity key of the removed certificate or to an error when happened */
|
||||
Result<EntityKey> removeCertificate(Long institutionId, String alias);
|
||||
|
||||
/** Get all alias names of all certificated that exists for a given institution.
|
||||
*
|
||||
* @param institutionId The institution identifier
|
||||
* @return Result refer to the collection of all certificate alias names or to an error when happened */
|
||||
Result<Collection<String>> getAllIdentityAlias(Long institutionId);
|
||||
|
||||
/** Get the certification information for a specific certificate from the the given Certificates.
|
||||
*
|
||||
* @param certificates The certificates bucket to get the info from
|
||||
* @param alias the alias name of the certificate to get the info from
|
||||
* @return Result refer to the certificate info or to an error when happened. */
|
||||
Result<CertificateInfo> getDataFromCertificate(Certificates certificates, String alias);
|
||||
|
||||
/** Get a collection of all alias names of all identity certificates for a given institution.
|
||||
*
|
||||
* @param institutionId The institution identifier
|
||||
* @return Result refer to the collection of certificate alias or to an error when happened */
|
||||
Result<Collection<String>> getIdentityAlias(Long institutionId);
|
||||
|
||||
String extractAlias(X509Certificate a, String alias);
|
||||
/** Get or extract the alias name of a given certificate. If there is not given a explicit alias name
|
||||
* within the certificate, this will create one generic from the data that is available.
|
||||
*
|
||||
* @param certificate The X509Certificate to extract the alias name from
|
||||
* @return the extracted alias */
|
||||
String extractAlias(X509Certificate certificate);
|
||||
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ public class CertificateDAOImpl implements CertificateDAO {
|
|||
final X509Certificate cert = certificate;
|
||||
|
||||
return new CertificateInfo(
|
||||
extractAlias(cert, alias),
|
||||
StringUtils.isNotBlank(alias) ? alias : extractAlias(cert),
|
||||
new DateTime(cert.getNotBefore()),
|
||||
new DateTime(cert.getNotAfter()),
|
||||
getTypes(certificates, cert));
|
||||
|
@ -224,10 +224,7 @@ public class CertificateDAOImpl implements CertificateDAO {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String extractAlias(final X509Certificate certificate, final String alias) {
|
||||
if (StringUtils.isNotBlank(alias)) {
|
||||
return alias;
|
||||
}
|
||||
public String extractAlias(final X509Certificate certificate) {
|
||||
|
||||
try {
|
||||
final X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
|
||||
|
|
|
@ -41,6 +41,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.dao.CertificateDAO;
|
|||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.SEBClientConfigDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.institution.CertificateService;
|
||||
import io.micrometer.core.instrument.util.StringUtils;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
|
@ -97,14 +98,18 @@ public class CertificateServiceImpl implements CertificateService {
|
|||
return loadCertFromPEM(in)
|
||||
.flatMap(cert -> this.certificateDAO.addCertificate(
|
||||
institutionId,
|
||||
this.certificateDAO.extractAlias(cert, alias),
|
||||
StringUtils.isNotBlank(alias)
|
||||
? alias
|
||||
: this.certificateDAO.extractAlias(cert),
|
||||
cert));
|
||||
|
||||
case PKCS12:
|
||||
return loadCertFromPKC(in, password)
|
||||
.flatMap(pair -> this.certificateDAO.addCertificate(
|
||||
institutionId,
|
||||
this.certificateDAO.extractAlias(pair.a, alias),
|
||||
StringUtils.isNotBlank(alias)
|
||||
? alias
|
||||
: this.certificateDAO.extractAlias(pair.a),
|
||||
pair.a,
|
||||
pair.b));
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue