Using impersonation I tried to read a file located on the network in a shared folder. But I got the error "Access is denied". My source code is given below ...
This works fine for local resources. But gives error when access network resources. line
\sever\shared\abc.txt
// Create a provider that implements Windows authentication functions
IWindowsAuthProvider prov = new WindowsAuthProviderImpl();
// Login using different user
IWindowsIdentity identity = prov.logonDomainUser("abc.jim","abc.com", "Xyz#123");
IWindowsImpersonationContext context = identity.impersonate();
// Reading file using new user
readFile(); // It gives error - Access is denied
// Revert back to original logged user
context.revertToSelf();
readFile(); // It is working properly
// Cleanup the Windows identity
identity.dispose();
Finally i am able to solve this problem by creating one native C library using JNI.
Native windows API used are
LogonUser : http://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx
ImpersonateLoggedOnUser : http://msdn.microsoft.com/en-us/library/windows/desktop/aa378612(v=vs.85).aspx
RevertToSelf : http://msdn.microsoft.com/en-us/library/windows/desktop/aa379317(v=vs.85).aspx
Related
I'm trying to use the rename functionality and keep getting this error.
Stacktrace:
3: %RNFR-bad%
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1950)
...
Here's the method I'm using to move the file
private void moveFile(String sourcePath, String destinationPath) {
try {
System.out.println("Move: " + sourcePath + " to: " + destinationPath);
sftp.rename(sourcePath, destinationPath); //sftp = ChannelSftp
} catch (SftpException e) {
e.printStackTrace();
}
}
Here's the output for my println:
Move: /SND/OUTBOUND/TestOutboundFile1.txt to: /SND/OUTBOUND/PROCESSING/TestOutboundFile1.txt
I've tried some other options posted around on here (get then put, multiple connections, etc) but keep getting the same error or it just sits and hangs (this was happening with the get then put method). Everything I've seen on the web says this should be as easy as my method but I just can't seem to get it to work. Can't find anything with the "RNFR-bad" error that is useful either.
The destination directory already exists and it's empty. What am I missing? Any help much appreciated.
EDIT: This ended up being a permissions issue and the code posted above worked perfectly fine after the admin granted my account the correct permissions. I was able to create and delete both files and directories but was unable to rename files until account privs were modified.
3: %RNFR-bad%
SFTP error code 3 means "permission denied". This implies that you're getting an error because you don't have permission on the remote system to perform the file move operation that you're trying to do.
"%RNFR-bad%" doesn't seem to be meaningful. My guess is that the remote SFTP server is using localized messages and it doesn't have a proper message for this case, or it's malfunctioning in some other way.
I need to create an audio file with synthesizeToFile.
It works on Android 6 (with the overloaded version of synthesizeToFile) but in Android 4.1 synthesizeToFile returns -1.
The synthesizeToFile official documentation says:
Synthesizes the given text to a file using the specified parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns.
Then, to know which error caused that -1 I searched in the logcat where I founded this exception:
E/TextToSpeechService: Can't use /data/data/com.domain.my/files/_12345_test.wav due to exception java.io.IOException: open failed: EACCES (Permission denied)
There is some different system configuration/setting between Android 6 and 4.1 which cause this error?
I must pass to synthesizeToFile a different path than the one returned by getFilesDir()?
I must set file permissions?
Code I used for Android 4.1:
TextToSpeech tts = new TextToSpeech(getApplicationContext(), this, "com.google.android.tts");
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
String textToGenerate = "this is a test";
// /data/data/com.domain.my/files is returned by getFilesDir()
String completePathFile = "/data/data/com.domain.my/files/_12345_test.wav";
File fileToGenerate = new File(completePathFile);
String fileName = fileToGenerate.getName();
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, fileName);
int response = tts.synthesizeToFile
(
textToGenerate
, hashMap
, completePathFile
);
Log.d("testTTS", "Generation file " + fileName + " - response = " + response);
}
}
I already checked with getEngines() that "com.google.android.tts" is installed.
I need to save the file in the internal storage so I must not ask for external storage permission (it is true also for Android 4.1? Or for this versione I need to do so?).
If I deliberately pass to synthesizeToFile a path that doesn't exists, the error in the logcat changes to file not found exception so that method checks correctly that the path completePathFile exists.
I came across your issue searching for a solution to my issue.
Use of sound files in TTS on Marshmallow (Android 6) fails with permission issues
For me, it's addspeech() in TTS.
I think permission issues on TTS come from the fact that TTS in a device is a separate application and the TTS app doesn't have permissions to write or read files in the external or internal storage of your app.
It's funny that I call the instance of TTS in my app code and use all its functions but they can't access my app's storage. TTS is not my app, so there's no way I can request permissions on behalf of TTS. I think it's a kind of bug Google has to handle.
Anyway, I let the Google team know the issue in the link below. They didn't respond yet though.
https://issuetracker.google.com/issues/152671139
You can support me in the link above, or you can post your own issue to let them know that there're multiple developers hoping TTS permission issues are taken care of.
I am trying to access the DataStore of one app from another GAE project using Remote API.
I am using the following code:
String serverString = "http://example.com";//this should be the target appengine
RemoteApiOptions options;
if (serverString.equals("localhost")) {
options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential();
} else {
options = new RemoteApiOptions().server(serverString, 80).useApplicationDefaultCredential();
}
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
datastore = DatastoreServiceFactory.getDatastoreService();
try {
results = datastore.get(KeyFactory.createKey("some key"));
} catch (EntityNotFoundException e) {
e.printStackTrace();
return null;
}
when I run this locally, i get a nullpointerexception at installer.install(options);.
and when deployed, the error seen from error reporting on the appengine is :HttpResponseException: 401 You must be logged in as an administrator, or access from an approved application.
That being said, I made a small java application with the follwing code:
String serverString = "http://example.com";//same string as the one used in the above code
RemoteApiOptions options;
if (serverString.equals("localhost")) {
options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential();
} else {
options = new RemoteApiOptions().server(serverString, 80).useApplicationDefaultCredential();
}
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!")));
and this one works!! Hello Remote API entity is added.
The reason it does not work when running on App Engine vs running locally has to do with the credentials that are being picked up. When running locally, it is likely using your own credentials (which has access to both projects); by contrast, when running on App Engine, you are likely picking up the App Engine default service account, which only has access to that App Engine project.
Try fixing this by opening the Cloud IAM section of Cloud Console for the project containing the Cloud Datastore that you wish to access. There, grant the appropriate level of access to the default App Engine service account that is being used by the other project.
If you don't want all App Engine services in the other project to have this kind of access, you might also consider, instead, generating a service account for this cross-project access that you grant the appropriate access to (rather than granting that access to the default App Engine service account). Then, in your code that calls the API, you would explicitly use that service account by calling the useServiceAccountCredential() method of RemoteApiOptions to ensure that the API requests that are issued use the specified service account rather than the default App Engine service account.
I'm experiencing some problems when trying to retrieve the slot information for VMware clusters with admission failover level control policy enabled. I use the VI Java API.
When calling the following method:
clusterComputeResource.retrieveDasAdvancedRuntimeInfo()
I either get the following Exception:
java.rmi.RemoteException: VI SDK invoke exception:java.rmi.RemoteException: Exception in
WSClient.invoke:; nested exception is:
java.lang.NoSuchFieldException: slotInfo
at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:122)
at com.vmware.vim25.ws.VimStub.retrieveDasAdvancedRuntimeInfo(VimStub.java:269)
or I get the result which is of type ClusterDasAdvancedRuntimeInfo
but I need the subclass ClusterDasFailoverLevelAdvancedRuntimeInfo in order to get the SlotInfo field (casting to the required sublcass doesn't work either).
I tried to access the web service of a vcenter directly via Soap UI and it worked without any problems, but with the vijava API it just doesn't.
Thanks in advance for any help!!!
After a lot of of debugging to see what the VI Java API does internally, I found out that if the web service client (wsc) is invoked with the name of the sublcass instead of the name of the superclass (as last parameter), the response will be converted correctly. This way the slot information can be retrieved without any problems. Here is the solution for those experiencing the same problems:
ClusterDasFailoverLevelAdvancedRuntimeInfo clusterDasFailoverLevelAdvancedRuntimeInfo = null;
try {
final Argument[] paras = new Argument[1];
paras[0] = new Argument("_this", "ManagedObjectReference", clusterComputeResource.getMOR());
clusterDasFailoverLevelAdvancedRuntimeInfo = (ClusterDasFailoverLevelAdvancedRuntimeInfo) serviceInstance.getServerConnection().getVimService().getWsc().invoke("RetrieveDasAdvancedRuntimeInfo", paras, "ClusterDasFailoverLevelAdvancedRuntimeInfo");
} catch (final Exception e) {
//error handling
}
(Note that this only works if admission control failover level policy is enabled!!!)
Our In-House Java application launches various http URLs at various times, including URLs to web-pages, MS Word documents, MS Excel documents, PDF files etc.
On over 50+ machines the URL launching works fine and the correct application opens the given page/document correctly. However, on one pesky machine Adobe Acrobat is attempting to open every URL (regardless of whether the target is a pdf or not), and failing (even on pdf documents) with:
There was an error opening this document. The filename, directory name, or volume label syntax is incorrect.
The code to launch the URLs is:
URL url = new URL("http://www.example.com");
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
boolean worked = bs.showDocument(url);
The worked variable is true after the call.
Other points that may be helpful:
The application runs within Java Web-Start.
An applet running on the same machine is able to open URLs correctly using AppletContext.showDocument()
Entering a URL into the Windows "Run..." dialog launches the URL correctly.
We've reinstalled both the JRE and Adobe Acrobat.
Thanks in advance for any advice/help you can offer.
Update:
The following debug code produces the following output:
String[] services = ServiceManager.getServiceNames();
if(services!=null) {
for(int i=0;i<services.length;i++) {
System.out.println("Available Service: "+services[i]);
}
}
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
System.out.println(url);
System.out.println(bs);
System.out.println("bs.getCodeBase():"+bs.getCodeBase());
System.out.println("bs.isOffline():"+bs.isOffline());
System.out.println("bs.isWebBrowserSupported():"+bs.isWebBrowserSupported());
boolean worked = bs.showDocument(url);
System.out.println("bs.showDocument:"+worked);
} catch(UnavailableServiceException ue) {
System.out.println("UnavailableServiceException thrown");
ue.printStackTrace();
}
Available Service: javax.jnlp.BasicService
Available Service: javax.jnlp.FileOpenService
Available Service: javax.jnlp.FileSaveService
Available Service: javax.jnlp.DownloadService
Available Service: javax.jnlp.ClipboardService
Available Service: javax.jnlp.PersistenceService
Available Service: javax.jnlp.PrintService
Available Service: javax.jnlp.ExtendedService
Available Service: javax.jnlp.SingleInstanceService
http://<snip>
com.sun.jnlp.BasicServiceImpl#bbb8b5
bs.getCodeBase():http://xxx.xxxxxx.com:8080/
bs.isOffline():false
bs.isWebBrowserSupported():true
bs.showDocument:true
Have you solved this problem yet? If not, could you try the following?
FileOpenService fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");