Skip to content

Commit 88f7b00

Browse files
Added edit option
1 parent bc899e7 commit 88f7b00

File tree

6 files changed

+41
-2
lines changed

6 files changed

+41
-2
lines changed

engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ CREATE TABLE `cloud`.`oauth_provider` (
580580
`client_id` varchar(255) NOT NULL COMMENT 'client id which is configured in the provider',
581581
`secret_key` varchar(255) NOT NULL COMMENT 'secret key which is configured in the provider',
582582
`redirect_uri` varchar(255) NOT NULL COMMENT 'redirect uri which is configured in the provider',
583+
`enabled` int(1) NOT NULL DEFAULT 1 COMMENT 'Enabled or disabled',
583584
`created` datetime NOT NULL COMMENT 'date created',
584585
`removed` datetime COMMENT 'date removed if not null',
585586
PRIMARY KEY (`id`)

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2AuthManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public OauthProviderVO updateOauthProvider(UpdateOAuthProviderCmd cmd) {
173173
String clientId = cmd.getClientId();
174174
String redirectUri = cmd.getRedirectUri();
175175
String secretKey = cmd.getSecretKey();
176+
Boolean enabled = cmd.getEnabled();
176177

177178
OauthProviderVO providerVO = _oauthProviderDao.findById(id);
178179
if (providerVO == null) {
@@ -191,6 +192,9 @@ public OauthProviderVO updateOauthProvider(UpdateOAuthProviderCmd cmd) {
191192
if (StringUtils.isNotEmpty(secretKey)) {
192193
providerVO.setSecretKey(secretKey);
193194
}
195+
if (enabled != null) {
196+
providerVO.setEnabled(enabled);
197+
}
194198

195199
_oauthProviderDao.update(id, providerVO);
196200

@@ -205,6 +209,7 @@ private OauthProviderVO saveOauthProvider(String provider, String description, S
205209
oauthProviderVO.setClientId(clientId);
206210
oauthProviderVO.setSecretKey(secretKey);
207211
oauthProviderVO.setRedirectUri(redirectUri);
212+
oauthProviderVO.setEnabled(true);
208213

209214
_oauthProviderDao.persist(oauthProviderVO);
210215

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
111111
for (OauthProviderVO result : resultList) {
112112
OauthProviderResponse r = new OauthProviderResponse(result.getUuid(), result.getProvider(),
113113
result.getDescription(), result.getClientId(), result.getSecretKey(), result.getRedirectUri());
114-
if (OAuth2AuthManager.OAuth2IsPluginEnabled.value() && authenticatorPluginNames.contains(result.getProvider())) {
114+
if (OAuth2AuthManager.OAuth2IsPluginEnabled.value() && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
115115
r.setEnabled(true);
116116
} else {
117117
r.setEnabled(false);

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/UpdateOAuthProviderCmd.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.oauth2.api.command;
1818

1919
import org.apache.cloudstack.api.ApiCommandResourceType;
20+
import org.apache.cloudstack.auth.UserOAuth2Authenticator;
2021
import org.apache.cloudstack.oauth2.OAuth2AuthManager;
2122
import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse;
2223
import org.apache.cloudstack.oauth2.vo.OauthProviderVO;
@@ -31,6 +32,8 @@
3132
import org.apache.cloudstack.context.CallContext;
3233

3334
import javax.inject.Inject;
35+
import java.util.ArrayList;
36+
import java.util.List;
3437

3538
@APICommand(name = "updateOauthProvider", description = "Updates the registered OAuth provider details", responseObject = OauthProviderResponse.class,
3639
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0")
@@ -56,6 +59,9 @@ public final class UpdateOAuthProviderCmd extends BaseCmd {
5659
@Parameter(name = ApiConstants.REDIRECT_URI, type = CommandType.STRING, description = "Redirect URI pre-registered in the specific OAuth provider")
5760
private String redirectUri;
5861

62+
@Parameter(name = ApiConstants.ENABLED, type = CommandType.BOOLEAN, description = "OAuth provider will be enabled or disabled based on this value")
63+
private Boolean enabled;
64+
5965
@Inject
6066
OAuth2AuthManager _oauthMgr;
6167

@@ -83,6 +89,9 @@ public String getRedirectUri() {
8389
return redirectUri;
8490
}
8591

92+
public Boolean getEnabled() {
93+
return enabled;
94+
}
8695

8796
/////////////////////////////////////////////////////
8897
/////////////// API Implementation///////////////////
@@ -109,6 +118,19 @@ public void execute() {
109118
if (result != null) {
110119
OauthProviderResponse r = new OauthProviderResponse(result.getUuid(), result.getProvider(),
111120
result.getDescription(), result.getClientId(), result.getSecretKey(), result.getRedirectUri());
121+
122+
List<UserOAuth2Authenticator> userOAuth2AuthenticatorPlugins = _oauthMgr.listUserOAuth2AuthenticationProviders();
123+
List<String> authenticatorPluginNames = new ArrayList<>();
124+
for (UserOAuth2Authenticator authenticator : userOAuth2AuthenticatorPlugins) {
125+
String name = authenticator.getName();
126+
authenticatorPluginNames.add(name);
127+
}
128+
if (OAuth2AuthManager.OAuth2IsPluginEnabled.value() && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
129+
r.setEnabled(true);
130+
} else {
131+
r.setEnabled(false);
132+
}
133+
112134
r.setObjectName(ApiConstants.OAUTH_PROVIDER);
113135
r.setResponseName(getCommandName());
114136
this.setResponseObject(r);

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/vo/OauthProviderVO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public class OauthProviderVO implements Identity, InternalIdentity {
6161
@Column(name = GenericDao.REMOVED_COLUMN)
6262
private Date removed;
6363

64+
@Column(name = "enabled")
65+
private boolean enabled = true;
66+
6467
public OauthProviderVO () {
6568
uuid = UUID.randomUUID().toString();
6669
}
@@ -114,4 +117,12 @@ public String getSecretKey() {
114117
public void setSecretKey(String secretKey) {
115118
this.secretKey = secretKey;
116119
}
120+
121+
public boolean isEnabled() {
122+
return enabled;
123+
}
124+
125+
public void setEnabled(boolean enabled) {
126+
this.enabled = enabled;
127+
}
117128
}

ui/src/config/section/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default {
100100
label: 'label.edit',
101101
dataView: true,
102102
popup: true,
103-
args: ['description', 'clientid', 'redirecturi', 'secretkey']
103+
args: ['description', 'clientid', 'redirecturi', 'secretkey', 'enabled']
104104
},
105105
{
106106
api: 'deleteOauthProvider',

0 commit comments

Comments
 (0)