|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.cloudstack.api.command; |
| 20 | + |
| 21 | +import com.cloud.exception.ConcurrentOperationException; |
| 22 | +import com.cloud.exception.InsufficientCapacityException; |
| 23 | +import com.cloud.exception.NetworkRuleConflictException; |
| 24 | +import com.cloud.exception.ResourceAllocationException; |
| 25 | +import com.cloud.exception.ResourceUnavailableException; |
| 26 | +import com.cloud.user.Account; |
| 27 | +import org.apache.cloudstack.api.APICommand; |
| 28 | +import org.apache.cloudstack.api.ApiConstants; |
| 29 | +import org.apache.cloudstack.api.BaseCmd; |
| 30 | +import org.apache.cloudstack.api.Parameter; |
| 31 | +import org.apache.cloudstack.api.ServerApiException; |
| 32 | +import org.apache.cloudstack.api.response.SuccessResponse; |
| 33 | +import org.apache.cloudstack.api.response.DomainResponse; |
| 34 | +import org.apache.cloudstack.ldap.LdapManager; |
| 35 | + |
| 36 | +import javax.inject.Inject; |
| 37 | + |
| 38 | +@APICommand(name = "unlinkDomainFromLdap", description = "remove the linkage of a cloudstack domain to group or OU in ldap", |
| 39 | + responseObject = SuccessResponse.class, since = "4.23.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) |
| 40 | +public class UnlinkDomainFromLdapCmd extends BaseCmd { |
| 41 | + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, |
| 42 | + description = "The id of the domain which has to be linked to LDAP.") |
| 43 | + private Long domainId; |
| 44 | + |
| 45 | + @Inject |
| 46 | + private LdapManager _ldapManager; |
| 47 | + |
| 48 | + public Long getDomainId() { |
| 49 | + return domainId; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { |
| 54 | + boolean rc = _ldapManager.unlinkDomainFromLdap(this); |
| 55 | + SuccessResponse response = new SuccessResponse(); |
| 56 | + if (rc) { |
| 57 | + response.setDisplayText("Domain unlinked from LDAP successfully"); |
| 58 | + response.setSuccess(true); |
| 59 | + } else { |
| 60 | + response.setDisplayText("Failed to unlink domain from LDAP"); |
| 61 | + response.setSuccess(false); |
| 62 | + } |
| 63 | + setResponseObject(response); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public long getEntityOwnerId() { |
| 68 | + return Account.ACCOUNT_ID_SYSTEM; |
| 69 | + } |
| 70 | +} |
0 commit comments