| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.io.File; |
|---|
| 4 | 4 | import java.io.IOException; |
|---|
| 5 | +import java.io.UnsupportedEncodingException; |
|---|
| 6 | +import java.nio.file.Files; |
|---|
| 7 | +import java.nio.file.Paths; |
|---|
| 8 | +import java.nio.file.StandardOpenOption; |
|---|
| 5 | 9 | import java.security.InvalidKeyException; |
|---|
| 6 | 10 | import java.security.NoSuchAlgorithmException; |
|---|
| 7 | 11 | import java.security.NoSuchProviderException; |
|---|
| .. | .. |
|---|
| 14 | 18 | |
|---|
| 15 | 19 | import net.curisit.securis.beans.LicenseBean; |
|---|
| 16 | 20 | import net.curisit.securis.beans.RequestBean; |
|---|
| 21 | +import net.curisit.securis.utils.JsonUtils; |
|---|
| 17 | 22 | |
|---|
| 18 | 23 | import org.apache.commons.net.util.Base64; |
|---|
| 19 | 24 | import org.slf4j.Logger; |
|---|
| .. | .. |
|---|
| 62 | 67 | } |
|---|
| 63 | 68 | |
|---|
| 64 | 69 | /** |
|---|
| 70 | + * Generate a license file using a {@link LicenseBean} |
|---|
| 71 | + * |
|---|
| 72 | + * @param license |
|---|
| 73 | + * @param file |
|---|
| 74 | + * @throws SeCurisException |
|---|
| 75 | + */ |
|---|
| 76 | + public void save(LicenseBean license, File file) throws SeCurisException { |
|---|
| 77 | + byte[] json; |
|---|
| 78 | + try { |
|---|
| 79 | + json = JsonUtils.toJSON(license, true).getBytes("utf-8"); |
|---|
| 80 | + Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE); |
|---|
| 81 | + } catch (UnsupportedEncodingException e) { |
|---|
| 82 | + log.error("Error creating json doc from license: " + license, e); |
|---|
| 83 | + throw new SeCurisException("Error creating json doc from license: " + license, e); |
|---|
| 84 | + } catch (IOException e) { |
|---|
| 85 | + log.error("Error creating license file: " + file, e); |
|---|
| 86 | + throw new SeCurisException("Error creating json doc from license: " + license, e); |
|---|
| 87 | + } |
|---|
| 88 | + |
|---|
| 89 | + log.info("License saved in {}", file); |
|---|
| 90 | + |
|---|
| 91 | + } |
|---|
| 92 | + |
|---|
| 93 | + /** |
|---|
| 65 | 94 | * TODO: This method should be removed from client code. |
|---|
| 66 | 95 | * |
|---|
| 67 | 96 | * @param licBean |
|---|