I have seen multiple threads regarding the use of XStorable.storeToURL and vnd.sun.star.webdav://domain:8080//path/to/document_library to save OO documents to a webdav library folder. However, I have not seen a posting where someone has successfully used this in Java. While the use of the UCB vnd.sun.star.webdav://domain:8080//path/to/document_library/doc.odt works when using the File, Save menu options within OO Writer, I am prompted for a username and password. Supplying user and password via vnd.sun.star.webdav://user:password#domain:8080/ has not worked for me. I need to use this method from within a Java class to save a OO document. Has anyone had success using the following or something similar?
xStorable.storeToURL("vnd.sun.star.webdav://domain:8080/path/to/document_library/doc.odt", storeProps)
In the OO Developer's Guide, there is a paragraph regarding WebDav authentication:
DAV resources that require authentication are accessed using the interaction handler mechanism of the UCB. The DAV content calls an interaction handler supplied by the client to let it handle an authentication request. The implementation of the interaction handler collects the user name or password from a location, for example, a login dialog, and supplies this data as an interaction response.
Maybe this is related to the issue? If so, how to use an interaction handler for the authentication when trying to storeToURL via webdav?
Adding InteractionHandler was the issue. With this added, documents can be saved via storeToURL and passing the handler in as an argument:
String oooExeFolder = "C:/OpenOffice/program";
XComponentContext xLocalContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
Object serviceManager = xLocalServiceManager.createInstanceWithContext("com.sun.star.task.InteractionHandler", xLocalContext);
XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface( XInteractionHandler.class, serviceManager);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "InteractionHandler";
storeProps[0].Value = xHandler;
xStorable.storeToURL("vnd.sun.star.webdav://domain:8080/path/to/document_library/doc.odt", storeProps);
Related
I'm trying to use twitter4j (in Java) to grab the list of users following a particular user who happen to have direct messaging enabled. Something like this...
IDs followerIDs = twitter.getFollowersIDs(someTwitterScreenName, -1);
long[] ids = followerIDs.getIDs();
for (long id : ids) {
twitter4j.User user = twitter.showUser(id);
String userScreenName = user.getScreenName();
String realName = user.getName();
//I'm hoping for something like...
///Boolean directMessagingEnabled = user.messagingEnabled();
}
The only problem is that I can't find any attributes associated with the twitter4j.User object that sound suitable (and also can't find any reference to it in the API documentation). Does anyone know if there's some way to programmatically find these types of users? Or perhaps twitter have deliberately excluded it? Thanks for any thoughts at all.
------EDIT-----
The documentation link from Yuri led me to this response from a twitter employee: "Determining if a user accepts DMs from all is not available via the public API. If you are a trusted partner please reach out via your direct Twitter contacts for details."
(https://twittercommunity.com/t/how-can-i-tell-which-users-the-current-user-can-send-messages-to/36127/4)
Also noticed that it IS possible to get the DM status for an already authenticated user using "AccountSettings.getAccountSettings().allow_dms_from"
This is discussed here
https://dev.twitter.com/rest/reference/post/direct_messages/new
There is apparently a whitelist for access you can apply for.
However it seems you mostly have all you need. The users following your account can usually receive DMs from you already. This doesn't cover the cases where the user either DMed you first, or accepts DMs from anyone.
But it is probably simplest to try sending and inspect the failures.
I have a java-agent from which I can call another agent with the parameter passed through it which contains NoteId, and using that NoteId, I am successfully able to get the work done the that document.Till here every thing is clear.
The main question regarding this is , Is it possible to run the agent of another database on same server from the current database agent?
To be more clear for an example
I have two databases, "ABC.nsf" and "XYZ.nsf", JavaAgent "A" is in "ABC.nsf" and JavaAgent "B" is in "XYZ.nsf". In my xpage I have a button running Agent "A", and even Agent "A" can run any other javaAgent from the same database.
Code:
Document mainDoc = db.getDocumentByUNID(tempDoc.getItemValueString("mainDocId"));
String noteID = mainDoc.getNoteID();
String agentName = "NotificationManager";
Agent agent = db.getAgent(agentName);
if (agent != null)
agent.runOnServer(noteID);
else
System.err.println("Something is wrong");
But Actually I want run the JavaAgent "B" Located in "XYZ.nsf" from JavaAgent "A" which is in "ABC.nsf".
After some research I have referd this code.
Code
Database db=session.getDatabase(current_server, "path/to/XYZ.nsf");
Agent myAgent=db.getAgent("B");
myAgent.run();
And yes I am unsuccessfull there,
Need some idea to acheive this.Any suggession will be really appretiated.
The example code is correct in principle. Just some things you have to know:
First of all the name of server can either be "" or the real name of the server. BUT if there is a server, then you have to check the Trusted servers:- section in the server document (Security Tab - Server Access section). There the server himself has to be member of the field (as name or in a group), otherwise you might not be able to open the other database.
Second thing: the path to the target database is relative to data directory and has to be in the right format for the given operating system.
e.g. C:\IBM\Domino\Data\first\xyz.nsf would be first\xyz.nsf and /local/notesdata/second/abc.nsfwould be second/abc.nsf
Third: the noteid that you get is from a document from the calling database. In the "target"- agent you have to go and get the document from the source database, otherwise it will either throw an error or -as the noteid is just a sequential number- return a document from target database that has nothing to do with the document you are searching for.
The calling agent A would have code like this:
Session session = getSession();
AgentContext agentContext =
session.getAgentContext();
Database dbCurrent = agentContext.getCurrentDatabase();
Database dbTarget = session.getDatabase(dbCurrent.Server, "XYZ.nsf");
Agent myAgent=dbTarget.getAgent("B");
myAgent.runOnServer(noteID);
The called agent B could look like this
Session session = getSession();
AgentContext agentContext =
session.getAgentContext();
Database dbCurrent = agentContext.getCurrentDatabase();
Database dbSource = session.getDatabase(dbCurrent.Server, "ABC.nsf");
Document doc = dbSource.getDocumentByID(agentContext.getCurrentAgent().getParameterDocID())
This should work (if security is ok on the server).
As Paul mentioned in the comments security also means that the agent signer or web user (depending on the settings in agent A) has to have sufficient access to the target database AND the target server (if it is different).
If it does not work despite of correct security: Show us the exact error / trace.
May I suggest a different approach? If you don't need an immediate reply from the agent, as a return value in the code, why don't you send the other database a special mail? Create a mail agent (triggered after new mail has been received), at the sender side create a NotesDocument object, add the values you need to reference the document you want the agent to work on, like the name of the server, the replicaId of the database, and the uniqueId. The agent receives the mail and inspects the fields for what it's supposed to do. The receiving database should be mentioned in the N&A book as Mail-in database.
Advantages are manifold: no hassle with rights, a clear interface, no need to open the other database, the agent is executed by the agent manager at a convenient time, you can easily add more functionality the same way, etc.
I'm trying to create an authenticate database in MongoDB 2.6 using java driver v 2.12.
In particular I need to create a user accessing to admin collection.
Any suggestion?
Thanks.
Here my solution:
MongoClient mcAdmin = new MongoClient(
configuration.getServerAddresses(),
Arrays.asList(MongoCredential.createMongoCRCredential(
MONGODB_ADMIN_USERNAME, "admin",
MONGODB_ADMIN_PASSWORD.toCharArray())));
try {
mcAdmin.setWriteConcern(WriteConcern.JOURNALED);
DB db = mcAdmin.getDB(userDbName);
BasicDBObject commandArguments = new BasicDBObject();
commandArguments.put("user", userUsername);
commandArguments.put("pwd", userPassword);
String[] roles = { "readWrite" };
commandArguments.put("roles", roles);
BasicDBObject command = new BasicDBObject("createUser",
commandArguments);
db.command(command);
} finally {
mcAdmin.close();
}
Doing this in Java code is not the best way to do it, and except for very rare use cases (writing an admin application for MongoDB) even one I would strongly advice against.
Security risk
First of all, your application would need extremely high privileges, namely userAdminAnyDatabase or userAdmin on the admin database, which more or less grants the same rights: creating a superuser at will. To put it in other words: this code would be a high security risk.
Granting roles and rights on a database is an administrative task and for good reasons should be decoupled from an application accessible by arbitrary users.
Technical problems
Activating authentication from a client simply is impossible. The mongod instance in question has to be started with authentication enabled. Furthermore, you would have to save to create a user with the mentioned roles before you could have your app administer users. The problem: you would have to store the password for that user somewhere. Unless you encrypt it, you basically store the most powerful password for your MongoDB databases and cluster in cleartext. And if you encrypt it, you have to pass the key for decryption to your application at some point in a secure manner. And all this to break best practices ("Separation of concerns")?
So I have a java program running within an Amazon EC2 instance. Is there a way to programatically get its own tags? I have tried instantiating a new AmazonEC2Client to us the describeTags() function but it only gives me null. Any help would be appreciated thank you.
Edit: To make things clearer, the instances are going to be unmanned worker machines spun up to solely do some computations
This should help you get started...
String instanceId = EC2MetadataUtils.getInstanceId();
AmazonEC2 client = AmazonEC2ClientBuilder.standard()
.withCredentials(new DefaultAWSCredentialsProviderChain())
.build();
DescribeTagsRequest req = new DescribeTagsRequest()
.withFilters(new Filter("resource-id", Collections.singletonList(instanceId)));
DescribeTagsResult describeTagsResult = client.describeTags(req);
List<TagDescription> tags = describeTagsResult.getTags()
You should be able to get the current instance id by sending a request to: http://169.254.169.254/latest/meta-data/instance-id. This only works within ec2. With this you can access quite a bit of information about the instance. However, tags do not appear to be included.
You should be able to take the instance id along with the correct authentication to get the instance tags. If you are going to run this on an instance, you may want to provide an IAM user with limited access instead of a user which has access to everything in case the instance is compromised.
While using user-data may be the simplest solution, the OP was asking specifically about the tagging, and unfortunately amazon hasn't made this as easy as it could be. However, It can be done. You want to use a combination of 2 amazon services.
First you need to retrieve the Instance ID. This can be achieved by hitting the URL from within your instance:
http://169.254.169.254/latest/meta-data/instance-id
Once you have the resource ID, you'll want to use Amazon's EC2 API to access the tags. Since you said you're using Java, I would suggest the Using the AWS SDK amazon makes available. Within this SDK you'll find a method called describeTags (documentation). You can use a Resource ID as one of the filters to get the specific tags to your instance. Supported filters are
tag key
resource-id
resource-type
I suggest doing this retrieval at boot using something like cloud-init and caching the tags on your server for use later if necessary.
I'm working on a Java application which uses the Ektorp Framework to communicate with a CouchDB. I use the following code to create a new CouchDbInstance:
HttpClient httpClient = new StdHttpClient.Builder()
.host("localhost")
.port("5984")
.username("")
.password("");
/* no user name and password required because, its admin party */
CouchDbInstance couchDbInstance = new StdCouchDbInstance(httpClient);
Now I want to test the connection to the CouchDB before I create/modify etc. documents. There is no method for testing the connection. Do you have a tip for me?
I'm using Ektorp in my current project and we're testing this with couchDbConnector.getAllDatabases(), catching DbAccessExceptions.
This has the slight advantage over checkIfDbExists() of being totally agnostic of the actual databases configured on the CouchDB server, and not referencing any application-specific configuration for connection checking just feels a little cleaner.
You can use CouchDbConnector#getDbInfo()
I'm currently working on a project using ektorp and I am testing my database connection like this.
Step 1 -- Connect to the HttpClient as you have done
HttpClient httpClient = new StdHttpClient.Builder()
.host("localhost")
.port("5984")
.username("")
.password("");
/* no user name and password required because, its admin party */
CouchDbInstance couchDbInstance = new StdCouchDbInstance(httpClient);
Step 2 -- Create a CouchDbInstance
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
Step 3 -- Use CouchDbConnector to connect to a specific database in your localhost CouchDB (in this example my database is called albums but you just put in the name for whatever database you are connecting to in place of albums from where you are coding)
CouchDbConnector albums = dbInstance.createConnector("albums", true);
Step 4 -- You can print off the name of the database you are connected to like this.
System.out.println(albums.getDatabaseName());
You could also create an endpoint that would print the name of the database you are connected to in the browser by creating a method of type string with
return albums.getDatabaseName();
I hope this is helpful. I used ektorp's reference documentation to learn this. It took me a while to figure out how to use ektorp like this and I am still learning!