|
|
@@ -1,8 +1,12 @@
|
|
|
package com.psi.gabontel.mobileapp.thirdparty.helper;
|
|
|
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Hashtable;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Properties;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.ejb.Singleton;
|
|
|
@@ -12,9 +16,15 @@ import javax.naming.InitialContext;
|
|
|
import javax.naming.NamingException;
|
|
|
|
|
|
import org.jboss.logging.Logger;
|
|
|
+import org.wildfly.naming.client.WildFlyInitialContextFactory;
|
|
|
+import org.wildfly.security.auth.client.AuthenticationConfiguration;
|
|
|
+import org.wildfly.security.auth.client.AuthenticationContext;
|
|
|
+import org.wildfly.security.auth.client.MatchRule;
|
|
|
+import org.wildfly.security.sasl.SaslMechanismSelector;
|
|
|
|
|
|
import com.psi.common.db.DataRow;
|
|
|
import com.psi.common.db.DataRowCollection;
|
|
|
+import com.psi.common.db.DbQuery;
|
|
|
import com.psi.common.db.DbWrapper;
|
|
|
import com.psi.common.util.StringUtil;
|
|
|
import com.psi.ussd.interfaces.UssdReceiverFunction;
|
|
|
@@ -24,8 +34,10 @@ import com.psi.ussd.interfaces.UssdReceiverFunction;
|
|
|
public class InitializerBean {
|
|
|
private static final Logger log = Logger.getLogger(InitializerBean.class);
|
|
|
private static final Hashtable<String,String> ussdgwmenuejb = new Hashtable<String,String>();
|
|
|
- private static final Hashtable<String, String> jndiProperties = new Hashtable<>();
|
|
|
- private static Context context;
|
|
|
+ private static final Properties jndiProperties = new Properties();
|
|
|
+ private static AuthenticationConfiguration commonconfig = AuthenticationConfiguration.empty().setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("DIGEST-MD5"));
|
|
|
+ private static AuthenticationConfiguration userconfig = AuthenticationConfiguration.empty().setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("DIGEST-MD5"));
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void initialize() {
|
|
|
DbWrapper db = new DbWrapper("java:jboss/datasources/UssdDbClient");
|
|
|
@@ -36,7 +48,7 @@ public class InitializerBean {
|
|
|
DataRow row = iterator.next();
|
|
|
|
|
|
String paramname = row.getString("PARAMNAME");
|
|
|
- String ejbname = row.getString("EJBNAME").replace("java:jboss/exported", "ejb:");
|
|
|
+ String ejbname = row.getString("EJBNAME").replace("java:jboss/exported", "");
|
|
|
ussdgwmenuejb.put(paramname, ejbname);
|
|
|
}
|
|
|
db = DbWrapper.getInstance();
|
|
|
@@ -45,16 +57,16 @@ public class InitializerBean {
|
|
|
String url = row.getString("URL");
|
|
|
String extra = row.getString("PARAMS");
|
|
|
Map<String, String> extraparam = StringUtil.json2Map(extra);
|
|
|
-
|
|
|
+ String username = extraparam.getOrDefault("username", "");
|
|
|
+ String password = extraparam.getOrDefault("password", "");
|
|
|
+ password = DbQuery.dbDecrypt(password, name);
|
|
|
//jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
|
|
|
- jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
|
|
|
+ jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
|
|
|
jndiProperties.put(Context.PROVIDER_URL, url);
|
|
|
- try {
|
|
|
- log.info("url: " + url);
|
|
|
- context = new InitialContext(jndiProperties);
|
|
|
- } catch (NamingException e) {
|
|
|
- log.error(e,e);
|
|
|
- }
|
|
|
+ //jndiProperties.put(Context.SECURITY_PRINCIPAL, username);
|
|
|
+ //jndiProperties.put(Context.SECURITY_CREDENTIALS, password);
|
|
|
+ //jndiProperties.put("org.jboss.ejb.client.scoped.context", "true");
|
|
|
+ userconfig = commonconfig.useName(username).usePassword(password);
|
|
|
}
|
|
|
|
|
|
public static String getUssdgwmenuejb(String key){
|
|
|
@@ -63,6 +75,9 @@ public class InitializerBean {
|
|
|
public static boolean containsKey(String key) {
|
|
|
return ussdgwmenuejb.containsKey(key);
|
|
|
}
|
|
|
+ public static Properties getJndiProperties() {
|
|
|
+ return jndiProperties;
|
|
|
+ }
|
|
|
public static UssdReceiverFunction getInterface(String jndi) {
|
|
|
try {
|
|
|
final Context context = new InitialContext(jndiProperties);
|
|
|
@@ -73,4 +88,22 @@ public class InitializerBean {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ public static String getPropertiesAsString() {
|
|
|
+ StringWriter writer = new StringWriter();
|
|
|
+ jndiProperties.list(new PrintWriter(writer));
|
|
|
+ return writer.getBuffer().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String callUssd(final String key, final String ... params) {
|
|
|
+ try {
|
|
|
+ final Properties prop = jndiProperties;
|
|
|
+ final String jndi = ussdgwmenuejb.get(key);
|
|
|
+ final AuthenticationContext auth = AuthenticationContext.empty().with(MatchRule.ALL, userconfig);
|
|
|
+ return auth.runCallable(new BeanCaller(prop,jndi,Arrays.asList(params)));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(key,e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|