Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update user store REST API to test connection for both JDBC and LDAP types #392

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public class UserStoreConstants {
public static final String USER_STORE_PROPERTIES = "/properties/";
public static final String USER_STORE_PROPERTY_MASK = "************";
public static final String CLAIM_MANAGEMENT_PREFIX = "CMT-";
public static final String URL = "url";
public static final String DRIVER_NAME = "driverName";
public static final String USER_NAME = "userName";
public static final String PASSWORD = "password";
public static final String JDBC_USER_STORE_TYPE_ID = "SkRCQ1VzZXJTdG9yZU1hbmFnZXI=";
public static final String CONNECTION_URL = "ConnectionURL";
public static final String CONNECTION_NAME = "ConnectionName";
public static final String CONNECTION_PASSWORD = "ConnectionPassword";


/**
* Enum for user store related errors in the format of
Expand Down Expand Up @@ -118,8 +127,10 @@ public enum ErrorMessage {
ERROR_CODE_EMPTY_ATTRIBUTE_MAPPINGS("60014", "Attribute mapping not specified.",
"Attribute mapping cannot be empty."),
ERROR_CODE_INVALID_USERSTORE_TYPE("60015", "UserStore type is not allowed",
"Requested UserStore type is not allowed", Response.Status.BAD_REQUEST);

"Requested UserStore type is not allowed", Response.Status.BAD_REQUEST),
ERROR_CODE_INVALID_USER_STORE_TYPE("60016", "Invalid user store type",
"Incorrect user store type.",
Response.Status.BAD_REQUEST);
private final String code;
private final String message;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import java.util.List;
import org.wso2.carbon.identity.api.server.userstore.v1.model.MetaUserStoreType;
import org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument;
import org.wso2.carbon.identity.api.server.userstore.v1.model.RDBMSConnectionReq;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConfigurationsRes;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConnectionReq;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreReq;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse;
Expand Down Expand Up @@ -263,7 +263,7 @@ public Response patchUserStore(@ApiParam(value = "The unique name of the user st
@Path("/test-connection")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Test the connection to the datasource used by a JDBC user store manager.", notes = "This API provides the capability to test the connection to the datasource used by a JDBC user store manager. <b>Permission required:</b> *_/permission/admin ", response = ConnectionEstablishedResponse.class, authorizations = {
@ApiOperation(value = "Test the connection to the datasource used by a user store manager.", notes = "This API provides the capability to test the connection to the datasource used by a user store manager. <b>Permission required:</b> *_/permission/admin ", response = ConnectionEstablishedResponse.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

Expand All @@ -275,9 +275,9 @@ public Response patchUserStore(@ApiParam(value = "The unique name of the user st
@ApiResponse(code = 401, message = "Unauthorized.", response = Void.class),
@ApiResponse(code = 500, message = "Internal Server Error.", response = Error.class)
})
public Response testRDBMSConnection(@ApiParam(value = "RDBMS connection properties used to connect to the datasource used by a JDBC user store manager." ) @Valid RDBMSConnectionReq rdBMSConnectionReq) {
public Response testUserStoreConnection(@ApiParam(value = "RDBMS connection properties used to connect to the datasource used by a JDBC user store manager." ) @Valid UserStoreConnectionReq userStoreConnectionReq) {

return delegate.testRDBMSConnection(rdBMSConnectionReq );
return delegate.testUserStoreConnection(userStoreConnectionReq );
}

@Valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import java.util.List;
import org.wso2.carbon.identity.api.server.userstore.v1.model.MetaUserStoreType;
import org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument;
import org.wso2.carbon.identity.api.server.userstore.v1.model.RDBMSConnectionReq;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConfigurationsRes;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConnectionReq;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreReq;
import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse;
Expand All @@ -58,7 +58,7 @@ public interface UserstoresApiService {

public Response patchUserStore(String userstoreDomainId, List<PatchDocument> patchDocument);

public Response testRDBMSConnection(RDBMSConnectionReq rdBMSConnectionReq);
public Response testUserStoreConnection(UserStoreConnectionReq userStoreConnectionReq);

public Response updateAttributeMappings(String userstoreDomainId, List<ClaimAttributeMapping> claimAttributeMapping);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wso2.carbon.identity.api.server.userstore.v1.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
import org.wso2.carbon.identity.api.server.userstore.v1.model.Property;
import javax.validation.constraints.*;

/**
* User Store Connection Request.
**/

import io.swagger.annotations.*;
import java.util.Objects;
import javax.validation.Valid;
import javax.xml.bind.annotation.*;
@ApiModel(description = "User Store Connection Request.")
public class UserStoreConnectionReq {

private String typeId;
private String domain;
private String driverName;
private String connectionURL;
private String username;
private String connectionPassword;
private List<Property> properties = null;


/**
* The id of the user store manager class type.
**/
public UserStoreConnectionReq typeId(String typeId) {

this.typeId = typeId;
return this;
}

@ApiModelProperty(example = "VW5pcXVlSURKREJDVXNlclN0b3JlTWFuYWdlcg", value = "The id of the user store manager class type.")
@JsonProperty("typeId")
@Valid
public String getTypeId() {
return typeId;
}
public void setTypeId(String typeId) {
this.typeId = typeId;
}

/**
* User store domain name.
**/
public UserStoreConnectionReq domain(String domain) {

this.domain = domain;
return this;
}

@ApiModelProperty(example = "PRIMARY", value = "User store domain name.")
@JsonProperty("domain")
@Valid
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}

/**
* Driver Name.
**/
public UserStoreConnectionReq driverName(String driverName) {

this.driverName = driverName;
return this;
}

@ApiModelProperty(example = "com.mysql.jdbc.Driver", value = "Driver Name.")
@JsonProperty("driverName")
@Valid
public String getDriverName() {
return driverName;
}
public void setDriverName(String driverName) {
this.driverName = driverName;
}

/**
* The Connection URL.
**/
public UserStoreConnectionReq connectionURL(String connectionURL) {

this.connectionURL = connectionURL;
return this;
}

@ApiModelProperty(example = "jdbc:mysql://192.168.48.154:3306/test", value = "The Connection URL.")
@JsonProperty("connectionURL")
@Valid
public String getConnectionURL() {
return connectionURL;
}
public void setConnectionURL(String connectionURL) {
this.connectionURL = connectionURL;
}

/**
* The username.
**/
public UserStoreConnectionReq username(String username) {

this.username = username;
return this;
}

@ApiModelProperty(example = "root", value = "The username.")
@JsonProperty("username")
@Valid
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

/**
* The password.
**/
public UserStoreConnectionReq connectionPassword(String connectionPassword) {

this.connectionPassword = connectionPassword;
return this;
}

@ApiModelProperty(example = "root", value = "The password.")
@JsonProperty("connectionPassword")
@Valid
public String getConnectionPassword() {
return connectionPassword;
}
public void setConnectionPassword(String connectionPassword) {
this.connectionPassword = connectionPassword;
}

/**
* Properties related to the user store.
**/
public UserStoreConnectionReq properties(List<Property> properties) {

this.properties = properties;
return this;
}

@ApiModelProperty(value = "Properties related to the user store.")
@JsonProperty("properties")
@Valid
public List<Property> getProperties() {
return properties;
}
public void setProperties(List<Property> properties) {
this.properties = properties;
}

public UserStoreConnectionReq addPropertiesItem(Property propertiesItem) {
if (this.properties == null) {
this.properties = new ArrayList<>();
}
this.properties.add(propertiesItem);
return this;
}



@Override
public boolean equals(java.lang.Object o) {

if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
UserStoreConnectionReq userStoreConnectionReq = (UserStoreConnectionReq) o;
return Objects.equals(this.typeId, userStoreConnectionReq.typeId) &&
Objects.equals(this.domain, userStoreConnectionReq.domain) &&
Objects.equals(this.driverName, userStoreConnectionReq.driverName) &&
Objects.equals(this.connectionURL, userStoreConnectionReq.connectionURL) &&
Objects.equals(this.username, userStoreConnectionReq.username) &&
Objects.equals(this.connectionPassword, userStoreConnectionReq.connectionPassword) &&
Objects.equals(this.properties, userStoreConnectionReq.properties);
}

@Override
public int hashCode() {
return Objects.hash(typeId, domain, driverName, connectionURL, username, connectionPassword, properties);
}

@Override
public String toString() {

StringBuilder sb = new StringBuilder();
sb.append("class UserStoreConnectionReq {\n");

sb.append(" typeId: ").append(toIndentedString(typeId)).append("\n");
sb.append(" domain: ").append(toIndentedString(domain)).append("\n");
sb.append(" driverName: ").append(toIndentedString(driverName)).append("\n");
sb.append(" connectionURL: ").append(toIndentedString(connectionURL)).append("\n");
sb.append(" username: ").append(toIndentedString(username)).append("\n");
sb.append(" connectionPassword: ").append(toIndentedString(connectionPassword)).append("\n");
sb.append(" properties: ").append(toIndentedString(properties)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {

if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n");
}
}

Loading