|
16 | 16 | // under the License. |
17 | 17 | package org.apache.cloudstack.api.command.admin.user; |
18 | 18 |
|
| 19 | +import com.cloud.exception.InvalidParameterValueException; |
19 | 20 | import com.cloud.server.ResourceIcon; |
20 | 21 | import com.cloud.server.ResourceTag; |
21 | 22 | import com.cloud.user.Account; |
| 23 | +import com.cloud.user.User; |
22 | 24 | import org.apache.cloudstack.acl.RoleType; |
23 | 25 | import org.apache.cloudstack.api.command.user.UserCmd; |
24 | 26 | import org.apache.cloudstack.api.response.ResourceIconResponse; |
|
30 | 32 | import org.apache.cloudstack.api.ResponseObject.ResponseView; |
31 | 33 | import org.apache.cloudstack.api.response.ListResponse; |
32 | 34 | import org.apache.cloudstack.api.response.UserResponse; |
| 35 | +import org.apache.commons.lang3.EnumUtils; |
33 | 36 |
|
34 | 37 | import java.util.List; |
35 | 38 |
|
@@ -63,6 +66,10 @@ public class ListUsersCmd extends BaseListAccountResourcesCmd implements UserCmd |
63 | 66 | description = "flag to display the resource icon for users") |
64 | 67 | private Boolean showIcon; |
65 | 68 |
|
| 69 | + @Parameter(name = ApiConstants.USER_SOURCE, type = CommandType.STRING, since = "4.21.0.0", |
| 70 | + description = "List users by their authentication source. Valid values are: native, ldap, saml2 and saml2disabled.") |
| 71 | + private String userSource; |
| 72 | + |
66 | 73 | ///////////////////////////////////////////////////// |
67 | 74 | /////////////////// Accessors /////////////////////// |
68 | 75 | ///////////////////////////////////////////////////// |
@@ -91,6 +98,23 @@ public Boolean getShowIcon() { |
91 | 98 | return showIcon != null ? showIcon : false; |
92 | 99 | } |
93 | 100 |
|
| 101 | + public User.Source getUserSource() { |
| 102 | + if (userSource == null) { |
| 103 | + return null; |
| 104 | + } |
| 105 | + |
| 106 | + User.Source source = EnumUtils.getEnumIgnoreCase(User.Source.class, userSource); |
| 107 | + if (source == null || List.of(User.Source.OAUTH2, User.Source.UNKNOWN).contains(source)) { |
| 108 | + throw new InvalidParameterValueException(String.format("Invalid user source: %s. Valid values are: native, ldap, saml2 and saml2disabled.", userSource)); |
| 109 | + } |
| 110 | + |
| 111 | + if (source == User.Source.NATIVE) { |
| 112 | + return User.Source.UNKNOWN; |
| 113 | + } |
| 114 | + |
| 115 | + return source; |
| 116 | + } |
| 117 | + |
94 | 118 | ///////////////////////////////////////////////////// |
95 | 119 | /////////////// API Implementation/////////////////// |
96 | 120 | ///////////////////////////////////////////////////// |
|
0 commit comments