|
| 1 | +//Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +//or more contributor license agreements. See the NOTICE file |
| 3 | +//distributed with this work for additional information |
| 4 | +//regarding copyright ownership. The ASF licenses this file |
| 5 | +//to you under the Apache License, Version 2.0 (the |
| 6 | +//"License"); you may not use this file except in compliance |
| 7 | +//with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +//http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +//Unless required by applicable law or agreed to in writing, |
| 12 | +//software distributed under the License is distributed on an |
| 13 | +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +//KIND, either express or implied. See the License for the |
| 15 | +//specific language governing permissions and limitations |
| 16 | +//under the License. |
| 17 | +package org.apache.cloudstack.api.command.user.vpn; |
| 18 | + |
| 19 | +import javax.inject.Inject; |
| 20 | + |
| 21 | +import org.apache.cloudstack.acl.RoleType; |
| 22 | +import org.apache.cloudstack.api.APICommand; |
| 23 | +import org.apache.cloudstack.api.ApiConstants; |
| 24 | +import org.apache.cloudstack.api.BaseCmd; |
| 25 | +import org.apache.cloudstack.api.Parameter; |
| 26 | +import org.apache.cloudstack.api.response.CertificateResponse; |
| 27 | +import org.apache.cloudstack.pki.PkiDetail; |
| 28 | +import org.apache.cloudstack.pki.PkiManager; |
| 29 | + |
| 30 | +import com.cloud.domain.Domain; |
| 31 | +import com.cloud.exception.RemoteAccessVpnException; |
| 32 | +import com.cloud.user.Account; |
| 33 | +import com.cloud.user.DomainService; |
| 34 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 35 | + |
| 36 | +/** |
| 37 | +* @author Khosrow Moossavi |
| 38 | +* @since 4.12.0.0 |
| 39 | +*/ |
| 40 | +@APICommand( |
| 41 | + name = ListRemoteAccessVpnCaCertificatesCmd.APINAME, |
| 42 | + description = "Lists the CA public certificate(s) as support by the configured/provided CA plugin", |
| 43 | + responseObject = CertificateResponse.class, |
| 44 | + requestHasSensitiveInfo = false, |
| 45 | + responseHasSensitiveInfo = false, |
| 46 | + since = "4.12.0.0", |
| 47 | + authorized = { |
| 48 | + RoleType.Admin, |
| 49 | + RoleType.ResourceAdmin, |
| 50 | + RoleType.DomainAdmin, |
| 51 | + RoleType.User |
| 52 | + } |
| 53 | +) |
| 54 | +public class ListRemoteAccessVpnCaCertificatesCmd extends BaseCmd { |
| 55 | + public static final String APINAME = "listVpnCaCertificate"; |
| 56 | + |
| 57 | + @Inject private DomainService domainService; |
| 58 | + @Inject private PkiManager pkiManager; |
| 59 | + |
| 60 | + ///////////////////////////////////////////////////// |
| 61 | + //////////////// API parameters ///////////////////// |
| 62 | + ///////////////////////////////////////////////////// |
| 63 | + |
| 64 | + @Parameter(name = ApiConstants.DOMAIN, type = CommandType.STRING, description = "Name of the CA service provider, otherwise the default configured provider plugin will be used") |
| 65 | + private String domain; |
| 66 | + |
| 67 | + ///////////////////////////////////////////////////// |
| 68 | + /////////////////// Accessors /////////////////////// |
| 69 | + ///////////////////////////////////////////////////// |
| 70 | + |
| 71 | + public String getDomain() { |
| 72 | + return domain; |
| 73 | + } |
| 74 | + |
| 75 | + ///////////////////////////////////////////////////// |
| 76 | + /////////////// API Implementation/////////////////// |
| 77 | + ///////////////////////////////////////////////////// |
| 78 | + |
| 79 | + @Override |
| 80 | + public void execute() { |
| 81 | + final PkiDetail certificate; |
| 82 | + |
| 83 | + try { |
| 84 | + Domain domain = domainService.getDomain(getDomain()); |
| 85 | + certificate = pkiManager.getCertificate(domain); |
| 86 | + } catch (final RemoteAccessVpnException e) { |
| 87 | + throw new CloudRuntimeException("Failed to get CA certificates for given domain"); |
| 88 | + } |
| 89 | + |
| 90 | + final CertificateResponse certificateResponse = new CertificateResponse("cacertificates"); |
| 91 | + certificateResponse.setCertificate(certificate.getIssuingCa()); |
| 92 | + certificateResponse.setResponseName(getCommandName()); |
| 93 | + setResponseObject(certificateResponse); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public String getCommandName() { |
| 98 | + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public long getEntityOwnerId() { |
| 103 | + return Account.ACCOUNT_TYPE_NORMAL; |
| 104 | + } |
| 105 | +} |
0 commit comments