| .. | .. |
|---|
| 7 | 7 | import java.nio.file.Paths; |
|---|
| 8 | 8 | import java.nio.file.StandardOpenOption; |
|---|
| 9 | 9 | |
|---|
| 10 | +import net.curisit.securis.ConnectionManager.Command; |
|---|
| 10 | 11 | import net.curisit.securis.beans.LicenseBean; |
|---|
| 11 | 12 | import net.curisit.securis.beans.RequestBean; |
|---|
| 12 | 13 | import net.curisit.securis.beans.SignedLicenseBean; |
|---|
| .. | .. |
|---|
| 29 | 30 | |
|---|
| 30 | 31 | private static LicenseManager singleton = new LicenseManager(); |
|---|
| 31 | 32 | |
|---|
| 32 | | - String serverUrl = null; |
|---|
| 33 | | - |
|---|
| 33 | + public static final String PING_MESSAGE = "SeCuris API OK"; |
|---|
| 34 | + |
|---|
| 34 | 35 | private LicenseManager() { |
|---|
| 35 | | - serverUrl = Params.get(Params.KEYS.LICENSE_SERVER_URL); |
|---|
| 36 | 36 | } |
|---|
| 37 | 37 | |
|---|
| 38 | 38 | public static LicenseManager getInstance() { |
|---|
| .. | .. |
|---|
| 88 | 88 | */ |
|---|
| 89 | 89 | public LicenseBean requestLicense() throws SeCurisException { |
|---|
| 90 | 90 | RequestBean req = ReqGenerator.getInstance().createRequest(Params.get(Params.KEYS.APPLICATION_CODE), Params.get(Params.KEYS.CUSTOMER_CODE)); |
|---|
| 91 | | - if (true) { |
|---|
| 92 | | - throw new SeCurisException("Action not implemented yet"); |
|---|
| 93 | | - } |
|---|
| 91 | + |
|---|
| 94 | 92 | LicenseBean lic = requestLicenseToServer(req); |
|---|
| 95 | 93 | return lic; |
|---|
| 96 | 94 | } |
|---|
| .. | .. |
|---|
| 120 | 118 | |
|---|
| 121 | 119 | } |
|---|
| 122 | 120 | |
|---|
| 123 | | - private LicenseBean requestLicenseToServer(RequestBean req) { |
|---|
| 124 | | - // TODO Prepare call to server sending the request bean to get a valid license |
|---|
| 125 | | - return null; |
|---|
| 121 | + private SignedLicenseBean requestLicenseToServer(RequestBean req) throws SeCurisException { |
|---|
| 122 | + SignedLicenseBean lic = ConnectionManager.getInstance().executePost(Command.CREATE_LIC, SignedLicenseBean.class, req); |
|---|
| 123 | + |
|---|
| 124 | + return lic; |
|---|
| 126 | 125 | } |
|---|
| 127 | 126 | |
|---|
| 128 | 127 | /** |
|---|
| .. | .. |
|---|
| 149 | 148 | * @return New license bean if server creates a new one, otherwise the same current License bean will be returned |
|---|
| 150 | 149 | * @throws SeCurisException |
|---|
| 151 | 150 | */ |
|---|
| 152 | | - public LicenseBean renew(File licenseFile) throws SeCurisException { |
|---|
| 151 | + public SignedLicenseBean renew(File licenseFile) throws SeCurisException { |
|---|
| 153 | 152 | LicenseBean lic = validateLicense(licenseFile); |
|---|
| 154 | | - if (true) { |
|---|
| 155 | | - throw new SeCurisException("Action not implemented yet"); |
|---|
| 156 | | - } |
|---|
| 157 | | - // TODO: Send the current LicenseBean to server to check if a new one is prepared. |
|---|
| 158 | | - return lic; |
|---|
| 153 | + |
|---|
| 154 | + SignedLicenseBean newLic = ConnectionManager.getInstance().executePost(Command.RENEW_LIC, SignedLicenseBean.class, lic); |
|---|
| 155 | + |
|---|
| 156 | + return newLic; |
|---|
| 159 | 157 | } |
|---|
| 160 | 158 | |
|---|
| 159 | + public void testServer() throws SeCurisException { |
|---|
| 160 | + String pingMsg = ConnectionManager.getInstance().executeGet(Command.RENEW_LIC, String.class); |
|---|
| 161 | + if (!PING_MESSAGE.equals(pingMsg)) { |
|---|
| 162 | + throw new SeCurisException("SeCuris Server is not running in given URL"); |
|---|
| 163 | + } |
|---|
| 164 | + } |
|---|
| 165 | + |
|---|
| 161 | 166 | } |
|---|