use of org.wso2.carbon.apimgt.persistence.dto.Organization in project airavata by apache.
the class MigrationManager method getUserProfilesFromWso2IS.
/* Method used to fetch all the user profiles from the registered tenants */
public List<UserProfileDAO> getUserProfilesFromWso2IS() {
ArrayList<UserProfileDAO> userProfileList = new ArrayList<UserProfileDAO>();
for (Wso2ISLoginCredentialsDAO creds : adminCredentials) {
RemoteUserStoreManagerServiceStub isClient = Wso2IdentityServerClient.getAdminServiceClient(creds.getLoginUserName(), creds.getLoginPassword(), "RemoteUserStoreManagerService");
String[] userList;
System.out.println("Fetching User Profiles for " + creds.getGateway() + " tenant ...");
try {
userList = isClient.getUserList("http://wso2.org/claims/givenname", "*", "default");
System.out.println("FirstName\tLastName\tEmail\t\t\tuserName\tCountry\tOrganization\tphone\tRoles");
String[] claims = { "http://wso2.org/claims/givenname", "http://wso2.org/claims/lastname", "http://wso2.org/claims/emailaddress", "http://wso2.org/claims/country", "http://wso2.org/claims/organization", "http://wso2.org/claims/mobile", "http://wso2.org/claims/telephone", "http://wso2.org/claims/streetaddress", "http://wso2.org/claims/role", "http://wso2.org/claims/identity/accountLocked" };
for (String user : userList) {
UserProfileDAO userProfile = new UserProfileDAO();
ClaimValue[] retrievedClaimValues = isClient.getUserClaimValuesForClaims(user, claims, null);
List<String> phones = new ArrayList<String>();
for (ClaimValue claim : retrievedClaimValues) {
if (claim.getClaimURI().equals(claims[0])) {
userProfile.setFirstName(claim.getValue());
} else if (claim.getClaimURI().equals(claims[1])) {
userProfile.setLastName(claim.getValue());
} else if (claim.getClaimURI().equals(claims[2])) {
userProfile.setEmail(claim.getValue());
} else if (claim.getClaimURI().equals(claims[3])) {
userProfile.setCountry(claim.getValue());
} else if (claim.getClaimURI().equals(claims[4])) {
userProfile.setOrganization(claim.getValue());
} else if (claim.getClaimURI().equals(claims[5]) || claim.getClaimURI().equals(claims[6])) {
phones.add(claim.getValue());
} else if (claim.getClaimURI().equals(claims[7])) {
userProfile.setAddress(claim.getValue());
} else if (claim.getClaimURI().equals(claims[8])) {
userProfile.setRoles(convertCommaSeparatedRolesToList(claim.getValue()));
} else if (claim.getClaimURI().equals(claims[9])) {
userProfile.setAccountLocked(claim.getValue().equals("true"));
}
}
// Lowercase all usernames as required by Keycloak and User Profile service
userProfile.setUserName(user.toLowerCase());
userProfile.setGatewayID(creds.getGateway());
userProfile.setPhones(phones);
if (!userProfile.isAccountLocked()) {
System.out.println(userProfile.getFirstName() + "\t" + userProfile.getLastName() + "\t" + userProfile.getUserName() + "\t" + userProfile.getEmail() + "\t" + userProfile.getCountry() + "\t" + userProfile.getOrganization() + "\t" + userProfile.getAddress() + "\t" + userProfile.getRoles());
userProfileList.add(userProfile);
} else {
System.out.println("Skipping locked account for user " + user + "!");
}
}
} catch (RemoteException e) {
System.out.println(e.getMessage());
System.out.println(e.getCause());
e.printStackTrace();
} catch (RemoteUserStoreManagerServiceUserStoreExceptionException e) {
System.out.println(e.getMessage());
System.out.println(e.getCause());
e.printStackTrace();
}
}
System.out.println("User profiles from all the tenant are retrieved ...");
return userProfileList;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class OrganizationPurgeDAO method getAPIIdList.
/**
* Get API data for given organization
*
* @param orgId organization Id
* @return ArrayList<APIIdentifier>
* @throws APIManagementException
*/
public ArrayList<APIIdentifier> getAPIIdList(String orgId) throws APIManagementException {
ArrayList<APIIdentifier> apiList = new ArrayList<>();
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(OrganizationPurgeConstants.GET_API_LIST_SQL_BY_ORG_SQL)) {
ps.setString(1, orgId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
int apiId = rs.getInt("API_ID");
String apiUuid = rs.getString("API_UUID");
String apiName = rs.getString("API_Name");
String apiProvider = rs.getString("API_Provider");
String apiVersion = rs.getString("API_Version");
APIIdentifier apiIdentifier = new APIIdentifier(apiProvider, apiName, apiVersion, apiUuid);
apiIdentifier.setId(apiId);
apiList.add(apiIdentifier);
}
}
} catch (SQLException e) {
log.error("Error while getting apiUuid list of organization" + orgId, e);
handleException("Failed to get API apiUuid list of organization " + orgId, e);
}
return apiList;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class OrganizationPurgeDAO method deleteKeyManagerConfigurationList.
public void deleteKeyManagerConfigurationList(List<KeyManagerConfigurationDTO> kmList, String organization) throws APIManagementException {
List<String> kmIdList = kmList.stream().map(KeyManagerConfigurationDTO::getUuid).collect(Collectors.toList());
List<String> collectionList = Collections.nCopies(kmIdList.size(), "?");
try (Connection conn = APIMgtDBUtil.getConnection()) {
conn.setAutoCommit(false);
String deleteKMQuery = OrganizationPurgeConstants.DELETE_BULK_KEY_MANAGER_LIST_SQL.replaceAll(OrganizationPurgeConstants.KM_UUID_REGEX, String.join(",", collectionList));
try (PreparedStatement preparedStatement = conn.prepareStatement(deleteKMQuery)) {
preparedStatement.setString(1, organization);
int index = 1;
for (String uuid : kmIdList) {
preparedStatement.setString(index + 1, uuid);
index++;
}
preparedStatement.execute();
conn.commit();
} catch (SQLException e) {
conn.rollback();
throw e;
}
} catch (SQLException e) {
throw new APIManagementException("Error while deleting key managers: " + kmIdList + " in organization " + organization, e);
}
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByName.
private KeyManagerConfigurationDTO getKeyManagerConfigurationByName(Connection connection, String organization, String name) throws SQLException, IOException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE NAME = ? AND ORGANIZATION = ?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, name);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
String uuid = resultSet.getString("UUID");
keyManagerConfigurationDTO.setUuid(uuid);
keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
keyManagerConfigurationDTO.setOrganization(organization);
keyManagerConfigurationDTO.setTokenType(resultSet.getString("TOKEN_TYPE"));
keyManagerConfigurationDTO.setExternalReferenceId(resultSet.getString("EXTERNAL_REFERENCE_ID"));
try (InputStream configuration = resultSet.getBinaryStream("CONFIGURATION")) {
String configurationContent = IOUtils.toString(configuration);
Map map = new Gson().fromJson(configurationContent, Map.class);
keyManagerConfigurationDTO.setAdditionalProperties(map);
}
return keyManagerConfigurationDTO;
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class SAMLGroupIDExtractorImpl method getOrganizationClaim.
/**
* Get the organization claim from authenticators configuration
*
* @return OrganizationClaimAttribute value configured in authenticators.xml
*/
private String getOrganizationClaim() {
AuthenticatorsConfiguration authenticatorsConfiguration = AuthenticatorsConfiguration.getInstance();
AuthenticatorsConfiguration.AuthenticatorConfig authenticatorConfig = authenticatorsConfiguration.getAuthenticatorConfig(APIConstants.SAML2_SSO_AUTHENTICATOR_NAME);
if (authenticatorConfig != null) {
Map<String, String> configParameters = authenticatorConfig.getParameters();
if (configParameters.containsKey(APIConstants.ORGANIZATION_CLAIM_ATTRIBUTE)) {
return configParameters.get(APIConstants.ORGANIZATION_CLAIM_ATTRIBUTE);
}
}
return APIConstants.DEFAULT_ORGANIZATION_CLAIM_NAME;
}
Aggregations