tracker issue : CF-4199061

select a category, or use search below
(searches all categories and all time range)
Title:

Delete datasource using Admin API

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): / ()

Created: 07/12/2017

Components: Administrator, Admin API

Versions: 2016

Failure Type: Non Functioning

Found In Build/Fixed In Build: 302561 / 2018.0.0.303933

Priority/Frequency: Normal / Some users will encounter

Locale/System: /

Vote Count: 0

Problem: Issue with Delete datasource using Admin API

Method: Please try the below code:

<cfset cfAdministratorPassword = "admin">
 <cfset cfDatasourceName = "sample"> 


<!--- require login --->
<cfset theUsername = "admin">
<cfset thePassword = "admin">
<cflogin>
	<cfif (NOT (IsDefined("form.username") AND IsDefined("form.password"))) OR (Trim(form.username) EQ "") OR (Trim(form.password) EQ "")>
		<!--- display login form --->
		<cfinclude template="loginForm.cfm">
		<cfabort>
	<cfelse>
		<cfif (form.username EQ theUsername) AND (form.password EQ thePassword)>
			<!--- do the log in --->
			<cfloginuser name="#theUsername#" password="#thePassword#" roles="admin">
		<cfelse>
			<!--- display login form --->
			<cfinclude template="loginForm.cfm">
			<cfabort>
		</cfif>
	</cfif>
</cflogin>

<!--- delete datasource --->
<cfoutput><br>starting...</cfoutput><cfflush>

<cfset administrator = CreateObject("component","cfide.adminapi.administrator")>
<cfoutput><br>created administrator object</cfoutput><cfflush>

<cfset loginSuccess = administrator.login("cfAdministratorPassword")>
<cfoutput><br>loginSuccess=[#loginSuccess#]</cfoutput><cfflush>

<cfset datasource = CreateObject("component","cfide.adminapi.datasource")>
<cfoutput><br>created datasource object</cfoutput><cfflush>

<cftry>
	<cfset datasource.deleteDatasource("cfDatasourceName")>
	<cfcatch type="any">
		<cfdump var="#cfcatch#">
		<cfabort>
	</cfcatch>
</cftry>
<cfoutput><br>deleted datasource</cfoutput><cfflush>


Result: coldfusion.security.SecurityManager$UnauthenticatedCredentialsException at coldfusion.security.SecurityManager.authenticateAdmin(SecurityManager.java:2569)

Expected: Data source should get deleted

Workaround: NA

Note: We tried deleting the data source using deleteDatasource function from admin API and we got the above error. We checked the source code and figured out that deleteDatasource is calling getDatasources.
We tried referencing  getDatasources with the same code and got the same error.
Also, this code is working with CF11 Update 12.

Attachments:

Comments:

Fix at the below location, works. \\blrstore.corp.adobe.com\builds03\ColdFusion\hotfixes\cf2016_hotfixes\DBadminapi
Comment by Anit K.
510 | August 07, 2017 09:20:44 AM GMT
Fix should be merged in CF2016 HF7 & CF2018
Comment by Nitin K.
511 | September 19, 2017 07:16:08 AM GMT