Cannot create Asterisk Stasis App using ari4java library - java

I am using ari4java library and I have a problem with registering a stasis application.
If I use the command line to connect to Asterisk and listen for events for a specific application name it works. It creates the application and everything is OK. The problem appears when I do it by using the ari4java library in Java. Actually, I'm trying the example from the library's github repository (i.e. - ConnectAndDial.java)[1]. I understand that the ARI.build(...) call:
ari = ARI.build(
ASTERISK_ADDRESS,
"app_test",
ASTERISK_USER,
ASTERISK_PASS,
AriVersion.ARI_3_0_0
);
must create an application named "app_test". The reality is that it does not.
for (Application app : ari.applications().list()) {
System.out.print(app.getName() + " ");
}
The code above, executed after ARI.build(...) prints nothing. That means there is no application registered in Asterisk. Running "ari show apps" in Asterisk CLI also tells me that there is no app registered.
I can't understand, where is the problem? Can somebody, please, help me with this?
Thanks in advance.
P.S.: I am using Asterisk 15.4.0
[1] https://github.com/l3nz/ari4java/blob/master/tests/ch/loway/oss/ari4java/sandbox/sample/ConnectAndDial.java

First of all you need to create an instance of ARI using ARI.build, as you did. For example:
ARI ari = ARI.build(asteriskUrl, "stasisApp", "userid", "secret", AriVersion.ARI_3_0_0);
Besides that you need to define configuration files as follows:
ari.conf - a configuration file that defines user and asterisk properties:
[general]
enabled = yes
pretty = yes
[userid]
type = user
read_only = no
password = secret
extensions.conf - define a dialpan for the application you want to run:
[general]
enabled = yes
pretty = yes
[userid]
type = user
read_only = no
password = secret
http.conf - HTTP server configuration:
[general]
enabled = yes
bindaddr = 0.0.0.0
bindport = 8088
In addition, after creating ARI instance you can open a websocket to listen to ARI events, using: ari.events().eventWebsocket("stasisApp", true, ariCallback);

Related

Getting all users from Openfire server using smack 4.2.2

Well, I'm trying to get all users from Openfire server using Smack, unfortunately I don't know how - I'm using Smack 4.2.2.
UserSearchManager usm= new UserSearchManager(connection);
DomainBareJid domainJid =
JidCreate.domainBareFrom(connection.getServiceName());
Form searchForm = usm.getSearchForm(domainJid);
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", "*");
ReportedData data = usm.getSearchResults(answerForm, domainJid);
if (data.getRows() != null) {
for (ReportedData.Row row: data.getRows()) {
for (String jid:row.getValues("jid")) {
System.out.println(jid);
}
}
}
This code doesn't work because of:
java.lang.IllegalArgumentException: Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once
You can't get all users through XEP-0055: Jabber Search, just can be used with a filter you sure that the users don't have it (like a special character). Only way I know is to use Rest API Plugin of openfire. You can read more about this plugin from the link. Good luck.
Error is obvious. Either you did not connect at least once (or got disconnected and did not reconnect) or your username is wrong.
Maybe you are trying to connect without local jid. Please check this explanation of XMPP address formats:
https://xmpp.org/rfcs/rfc6122.html#addressing-localpart
hope you have solved the problem. I got my code working with this little change
DomainBareJid domainJid =
JidCreate.domainBareFrom("search." + connection.getServiceName());
in your openfire go to Plugins and select available-plugins > then choose rest Api > then you can use following url to Get All users in Group:
http://localhost:9090/plugins/restapi/v1/users
Note: All Rest EndPoints you can find in following link:
https://www.igniterealtime.org/projects/openfire/plugins/1.2.1/restAPI/readme.html

How to programmatically logout from websphere portal 8.5 application using Java code?

I have a websphere portal application running very well. The current logout command is available in default theme.
I wanted to know how to logout the portal from java/spring source code? Can we call the same command method e.g. "logout" from server side java code?
I have functionality of change password. After change password, I want to logout user.
Below is the list of items which you need to try from your portlet
final PortletStateManager mgr = getPortletStateManager(request, response);
urlFactory = mgr.getURLFactory();
url = urlFactory.newURL(com.ibm.portal.state.Constants.EMPTY_COPY); //If no state from the current request to be preserved
LogoutActionAccessorFactory logoutFct = mgr.getAccessorFactory(LogoutActionAccessorFactory.class);
LogoutActionAccessorController logoutCtrl = logoutFct.newLogoutActionController(url.getState());logoutCtrl.dispose();
finalUrl = url.writeDispose(new StringWriter()).toString();
The same can be done from a Servlet also. You will see corresponding AccessorFactory and AccessorController in the portal documentation.
EDITED
PortletStateManager is obtained from PortletStateManagerService which again is obtained from PortletServiceHome using a JNDI lookup.
The right way to find out this is by going through the Java docs of Portal. Refer the interface PortletStateManagerService. The comment section clearly tells how to get it.
You can fine the Java docs of Portal here <portal-install-root>\WebSphere\PortalServer\doc\Javadoc\spi_docs

Single Sign-On with Java Client

I am looking for a Single Sign-On authentication in a Java client.
Since I am logged in to Windows using an AD, the main goal is that I do not have to enter username and password again. I want Java to use the Ticket I recieved at Windows-login. This code is the best I have for the purpose:
LoginContext lc = new LoginContext("com.sun.security.jgss.krb5.initiate", new DialogCallbackHandler());
lc.login();
Subject.doAs(lc.getSubject(), (PrivilegedExceptionAction<Void>) () -> {
System.out.println("This is privileged");
return null;
});
I've set the java.security.krb5.conf and java.security.auth.login.config properties with corresponding conf-files, but still a dialog asking for Username and Password pops up.
I also tried working with GSSName, but GSSManager.createCredential() is also asking for Username and Password (probably using the TextCallbackHandler()).
I tried to get along with Waffle, but did not get it working. Most examples and explanations are Server sided (I only found one example combining server and client side, but I was not able to split it up).
I know, there are Similar questions (e.g. this), but i did not get that working without entering a password.
PS: i know, that DialogCallbackHandler is depricated, I use it for test purposes only.
Ok, after several tries I found a solution. The problem was not in the code, but in the registry. As stated on this page, since Java 7 You can't access the ticket of Windows natively. To change this, You have to set an additional registry key. For this, go into the registry folder
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters
and add the key
Value Name: AllowTgtSessionKey
Value Type: REG_DWORD
Value: 0x01
To fully make this work you will need some additional settings:
The jaas configuration file
In the jaas configuration file you have to set up which security modules jaas should use. The part in front of the brackets names your configuration. If you use the GSS libraries you must name it com.sun.security.jgss.krb5.initiate. When you use the LoginContext you just pass the name of the configuration as first parameter. My jaas.conf look as follows:
com.sun.security.jgss.krb5.initiate {
com.sun.security.auth.module.Krb5LoginModule required
useTicketCache = true;
};
The kerberos configuration
You will also need a configuration for the Kerberos module. This mainly contains the realm address, but can hold additional information. A minimal working example:
[realms]
YOUR.REALM.COM = {
kdc = your.realm.com:88
default_domain = REALM.COM
}
Note, that this is case sensitive!
The System Properties
Finally, you have to set up Java to find this files. You do this either by giving the properties on startup or by calling System.setProperty():
System.setProperty("java.security.krb5.conf", "src/resources/krb5.conf");
System.setProperty("java.security.auth.login.config", "src/resources/jaas.conf");

How to set a value to a key in application.conf file in Play Framework (Java) 2.3.x

I have Play mailer configured on application.conf file with one email id . how can i change the email dynamically during run time ? The idea is to configure multiple email IDs on a single play application . eg ; for sales , the email must be sent from sale#abc.com and for purchase , purchase#abc.com
smtp.host=smtp.zoho.com
smtp.port=465
smtp.ssl=true
smtp.user= "info#abc.com"
smtp.password= "something"
i can get the string value using Play.application().configuration().getString("smtp.host"); ; how do we set it during run time ?
Play Configuration wraps Typesafe Config, which is immutable. So you cannot modify a config after creation. You can only create another config based on this one, overriding some properties.
The recipients of emails are set in your code, using the addTo method on a play.libs.mailer.Email object :
https://github.com/playframework/play-mailer/blob/2.x/sample/app/controllers/ApplicationJava.java#L18
Not to be confused with the login and password of your SMTP provider. These are sets in application.conf :
https://github.com/playframework/play-mailer/blob/2.x/sample/conf/application.conf#L65

Using Azure Service Bus in java

I'm trying to subscribe to an Azure service bus topic in java. To do that, I need to create a ServiceBusContract instance. In every example I found, they do it like this:
String issuer = "<obtained from portal>";
String key = "<obtained from portal>";
Configuration config =
ServiceBusConfiguration.configureWithWrapAuthentication(
“HowToSample”,
issuer,
key);
ServiceBusContract service = ServiceBusService.create(config);
from: link
However if you take a look at the javadoc, there is no configureWithWrapAuthentication method with 3 String parameters!
I'm using the 0.3.1 version jar of the azure api.
How do I create a ServiceBusContract using these new(?) configureWithWrapAuthentication methods? Or is there something I overlooked?
Here are the parameters that we included in the configuration method.
String namespace, namespace is the name of your service bus subscription, such as johndoeservicebus.
String authenticationName, authentication name is the name of the login for WRAP, typically, it is called owner.
String authenticationPassword, authentication password is the key which you can obtain from your Azure Portal.
String serviceBusRootUri, service bus root URI is the root of the service bus service, for united states, it is “.servicebus.windows.net”.
String wrapRootUri, WRAP root Uri is the root of the WRAP authentication service, in united states, it is “-sb.accesscontrol.windows.net/WRAPv0.9”.
Apprently there is an issue with the above, tried it and it no longer works. According to github there is an open issue now:
https://github.com/Azure/azure-sdk-for-java/issues/437
The team has triaged this issue and worked on it. We've also reached out to the service bus team on the change from ACS to SAS, and to our documentation team so that we have a full-stop plan for dealing with this change, as it's not just a code issue, it's a communication issue.
This fix will be in the next release of the Java SDK, based on everything I'm hearing from the team.

Categories