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: