use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class DefaultGroupIDExtractorImpl method getGroupingIdentifiers.
public String getGroupingIdentifiers(String loginResponse) {
JSONObject obj;
String username = null;
Boolean isSuperTenant;
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
String claim = config.getFirstProperty(APIConstants.API_STORE_GROUP_EXTRACTOR_CLAIM_URI);
if (StringUtils.isBlank(claim)) {
claim = "http://wso2.org/claims/organization";
}
String organization = null;
try {
obj = new JSONObject(loginResponse);
username = (String) obj.get("user");
isSuperTenant = (Boolean) obj.get("isSuperTenant");
RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
// if the user is not in the super tenant domain then find the domain name and tenant id.
if (!isSuperTenant) {
tenantDomain = MultitenantUtils.getTenantDomain(username);
tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
}
UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
UserStoreManager manager = realm.getUserStoreManager();
organization = manager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername(username), claim, null);
if (organization != null) {
organization = tenantDomain + "/" + organization.trim();
}
} catch (JSONException e) {
log.error("Exception occured while trying to get group Identifier from login response", e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("Error while checking user existence for " + username, e);
}
return organization;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersKeyManagerIdPut.
public Response keyManagersKeyManagerIdPut(String keyManagerId, KeyManagerDTO body, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
try {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = KeyManagerMappingUtil.toKeyManagerConfigurationDTO(organization, body);
keyManagerConfigurationDTO.setUuid(keyManagerId);
KeyManagerConfigurationDTO oldKeyManagerConfigurationDTO = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId);
if (oldKeyManagerConfigurationDTO == null) {
throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);
} else {
if (!oldKeyManagerConfigurationDTO.getName().equals(keyManagerConfigurationDTO.getName())) {
RestApiUtil.handleBadRequest("Key Manager name couldn't able to change", log);
}
KeyManagerConfigurationDTO retrievedKeyManagerConfigurationDTO = apiAdmin.updateKeyManagerConfiguration(keyManagerConfigurationDTO);
APIUtil.logAuditMessage(APIConstants.AuditLogConstants.KEY_MANAGER, new Gson().toJson(keyManagerConfigurationDTO), APIConstants.AuditLogConstants.UPDATED, RestApiCommonUtil.getLoggedInUsername());
return Response.ok(KeyManagerMappingUtil.toKeyManagerDTO(retrievedKeyManagerConfigurationDTO)).build();
}
} catch (APIManagementException e) {
String error = "Error while Retrieving Key Manager configuration for " + keyManagerId + " in organization " + organization;
throw new APIManagementException(error, e, ExceptionCodes.INTERNAL_ERROR);
}
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersKeyManagerIdGet.
public Response keyManagersKeyManagerIdGet(String keyManagerId, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
KeyManagerConfigurationDTO keyManagerConfigurationDTO = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId);
if (keyManagerConfigurationDTO != null) {
KeyManagerDTO keyManagerDTO = KeyManagerMappingUtil.toKeyManagerDTO(keyManagerConfigurationDTO);
return Response.ok(keyManagerDTO).build();
}
throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByUUID.
private KeyManagerConfigurationDTO getKeyManagerConfigurationByUUID(Connection connection, String uuid) throws SQLException, IOException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE UUID = ?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, uuid);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
keyManagerConfigurationDTO.setUuid(resultSet.getString("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(resultSet.getString("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 ApiMgtDAO method getApplicationByUUID.
/**
* Retrieves the Application which is corresponding to the given UUID String
*
* @param uuid UUID of Application
* @return
* @throws APIManagementException
*/
public Application getApplicationByUUID(String uuid) throws APIManagementException {
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
int applicationId = 0;
Application application = null;
try {
connection = APIMgtDBUtil.getConnection();
String query = SQLConstants.GET_APPLICATION_BY_UUID_SQL;
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, uuid);
rs = prepStmt.executeQuery();
if (rs.next()) {
String applicationName = rs.getString("NAME");
String subscriberId = rs.getString("SUBSCRIBER_ID");
String subscriberName = rs.getString("USER_ID");
Subscriber subscriber = new Subscriber(subscriberName);
subscriber.setId(Integer.parseInt(subscriberId));
application = new Application(applicationName, subscriber);
application.setDescription(rs.getString("DESCRIPTION"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setCallbackUrl(rs.getString("CALLBACK_URL"));
applicationId = rs.getInt("APPLICATION_ID");
application.setId(applicationId);
application.setGroupId(rs.getString("GROUP_ID"));
application.setUUID(rs.getString("UUID"));
application.setTier(rs.getString("APPLICATION_TIER"));
application.setTokenType(rs.getString("TOKEN_TYPE"));
application.setOwner(rs.getString("CREATED_BY"));
application.setOrganization(rs.getString("ORGANIZATION"));
subscriber.setId(rs.getInt("SUBSCRIBER_ID"));
if (multiGroupAppSharingEnabled) {
if (application.getGroupId() == null || application.getGroupId().isEmpty()) {
application.setGroupId(getGroupId(connection, application.getId()));
}
}
Timestamp createdTime = rs.getTimestamp("CREATED_TIME");
application.setCreatedTime(createdTime == null ? null : String.valueOf(createdTime.getTime()));
try {
Timestamp updated_time = rs.getTimestamp("UPDATED_TIME");
application.setLastUpdatedTime(updated_time == null ? null : String.valueOf(updated_time.getTime()));
} catch (SQLException e) {
// fixing Timestamp issue with default value '0000-00-00 00:00:00'for existing applications created
application.setLastUpdatedTime(application.getCreatedTime());
}
}
// Get custom attributes of application
if (application != null) {
Map<String, String> applicationAttributes = getApplicationAttributes(connection, applicationId);
application.setApplicationAttributes(applicationAttributes);
}
} catch (SQLException e) {
handleException("Error while obtaining details of the Application : " + uuid, e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
}
return application;
}
Aggregations