There is a cross forest trust between two domains a.com and b.com. I'm able to retrieve kerberos ticket for a.com using the below code where the service principal and kdc and realm details are configured for a.com. but the same configurations with b.com credentials are unable to retrieve kerberos ticket for b.com. Is there any extra configuration needs to be done in krb5.conf file ? a.com service account is able to validate the kerberos ticket for b.com due to cross forest trust but unable to generate a kerberos ticket. Please help me with this request
package sample;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOError;
import java.io.IOException;
import java.io.PrintStream;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.util.Set;
import javax.annotation.Resource;
import javax.annotation.Resources;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import javax.sql.DataSource;
import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSCredential;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.GSSManager;
import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;
import com.sun.security.auth.callback.DialogCallbackHandler;
import sun.misc.BASE64Encoder;
/**
* Tool to retrieve a kerberos ticket. This one will not be stored in the
* windows ticket cache.
*/
public final class KerberosTicketRetriever {
private final static Oid KERB_V5_OID;
private final static Oid KRB5_PRINCIPAL_NAME_OID;
static {
try {
KERB_V5_OID = new Oid("1.2.840.113554.1.2.2");
KRB5_PRINCIPAL_NAME_OID = new Oid("1.2.840.113554.1.2.2.1");
} catch (final GSSException ex) {
throw new Error(ex);
}
}
/**
* Not to be instanciated
*/
private KerberosTicketRetriever() {
};
/**
*
*/
private static class TicketCreatorAction implements PrivilegedAction<Object> {
final String userPrincipal;
final String applicationPrincipal;
private StringBuffer outputBuffer;
/**
*
* #param userPrincipal
* p.ex. <tt>MuelleHA#MYFIRM.COM</tt>
* #param applicationPrincipal
* p.ex. <tt>HTTP/webserver.myfirm.com</tt>
*/
private TicketCreatorAction(final String userPrincipal, final String applicationPrincipal) {
this.userPrincipal = userPrincipal;
this.applicationPrincipal = applicationPrincipal;
}
private void setOutputBuffer(final StringBuffer newOutputBuffer) {
outputBuffer = newOutputBuffer;
}
/**
* Only calls {#link #createTicket()}
*
* #return <tt>null</tt>
*/
public Object run() {
try {
createTicket();
} catch (final GSSException ex) {
throw new Error(ex);
}
return null;
}
/**
*
* #throws GSSException
*/
private void createTicket() throws GSSException {
final GSSManager manager = GSSManager.getInstance();
final GSSName clientName = manager.createName(userPrincipal, KRB5_PRINCIPAL_NAME_OID);
final GSSCredential clientCred = manager.createCredential(clientName, 8 * 3600, KERB_V5_OID,
GSSCredential.INITIATE_ONLY);
final GSSName serverName = manager.createName(applicationPrincipal, KRB5_PRINCIPAL_NAME_OID);
final GSSContext context = manager.createContext(serverName, KERB_V5_OID, clientCred,
GSSContext.DEFAULT_LIFETIME);
context.requestMutualAuth(true);
context.requestConf(false);
context.requestInteg(true);
final byte[] outToken = context.initSecContext(new byte[0], 0, 0);
if (outputBuffer != null) {
// outputBuffer.append(String.format("Src Name: %s\n",
// context.getSrcName()));
// outputBuffer.append(String.format("Target : %s\n",
// context.getTargName()));
outputBuffer.append(new BASE64Encoder().encode(outToken));
// outputBuffer.append("\n");
}
context.dispose();
}
}
/**
*
* #param realm
* p.ex. <tt>MYFIRM.COM</tt>
* #param kdc
* p.ex. <tt>kerbserver.myfirm.com</tt>
* #param applicationPrincipal
* cf. {#link #TicketCreatorAction(String, String)}
* #throws GSSException
* #throws LoginException
*/
static public String retrieveTicket(final String realm, final String kdc, final String applicationPrincipal)
throws GSSException, LoginException {
// create the jass-config-file
final File jaasConfFile;
try {
jaasConfFile = File.createTempFile("jaas.conf", null);
final PrintStream bos = new PrintStream(new FileOutputStream(jaasConfFile));
bos.print(String.format(
"Krb5LoginContext { com.sun.security.auth.module.Krb5LoginModule required useTicketCache=false doNotPrompt=false debug=true; };"));
bos.close();
jaasConfFile.deleteOnExit();
} catch (final IOException ex) {
throw new IOError(ex);
}
String krb5ConfigFilePath = "krb5.ini";
// System.setProperty("java.security.krb5.conf", krb5ConfigFilePath);
// set the properties
System.setProperty("java.security.krb5.realm", realm);
System.setProperty("java.security.krb5.kdc", kdc);
System.setProperty("java.security.auth.login.config", jaasConfFile.getAbsolutePath());
// get the Subject(), i.e. the current user under Windows
final Subject subject = new Subject();
final LoginContext lc = new LoginContext("Krb5LoginContext", subject, new DialogCallbackHandler());
lc.login();
// extract our principal
final Set<Principal> principalSet = subject.getPrincipals();
if (principalSet.size() != 1)
throw new AssertionError("No or several principals: " + principalSet);
final Principal userPrincipal = principalSet.iterator().next();
// now try to execute the SampleAction as the authenticated Subject
// action.run() without doAsPrivileged leads to
// No valid credentials provided (Mechanism level: Failed to find any
// Kerberos tgt)
final TicketCreatorAction action = new TicketCreatorAction(userPrincipal.getName(), applicationPrincipal);
final StringBuffer outputBuffer = new StringBuffer();
action.setOutputBuffer(outputBuffer);
Subject.doAsPrivileged(lc.getSubject(), action, null);
return outputBuffer.toString();
}
public static void main (final String args[]) throws Throwable
{
final String ticket = retrieveTicket("a.com", "a.com", "a_service"_account);
System.out.println(ticket);
}
}
Debug is true storeKey false useTicketCache false useKeyTab false doNotPrompt false ticketCache is null isInitiator true KeyTab is null refreshKrb5Config is false principal is null tryFirstPass is false useFirstPass is false storePass is false clearPass is false
[Krb5LoginModule] user entered username: testuser-b_7#b.com
Java config name: null
Native config name: C:\Windows\krb5.ini
>>> KdcAccessibility: reset
Using builtin default etypes for default_tkt_enctypes
default etypes for default_tkt_enctypes: 17 16 23.
>>> KrbAsReq creating message
getKDCFromDNS using UDP
>>> KrbKdcReq send: kdc=m.b.com. UDP:88, timeout=30000, number of retries =3, #bytes=154
>>> KDCCommunication: kdc=m.b.com. UDP:88, timeout=30000,Attempt =1, #bytes=154
>>> KrbKdcReq send: #bytes read=197
>>>Pre-Authentication Data:
PA-DATA type = 19
PA-ETYPE-INFO2 etype = 17, salt = b.comtestuser-b_7, s2kparams = null
PA-ETYPE-INFO2 etype = 23, salt = null, s2kparams = null
>>>Pre-Authentication Data:
PA-DATA type = 2
PA-ENC-TIMESTAMP
>>>Pre-Authentication Data:
PA-DATA type = 16
>>>Pre-Authentication Data:
PA-DATA type = 15
>>> KdcAccessibility: remove m.b.com.:88
>>> KDCRep: init() encoding tag is 126 req type is 11
>>>KRBError:
sTime is Mon Jul 04 11:06:17 EDT 2016 1467644777000
suSec is 666515
error code is 25
error Message is Additional pre-authentication required
sname is krbtgt/b.com#b.com
eData provided.
msgType is 30
>>>Pre-Authentication Data:
PA-DATA type = 19
PA-ETYPE-INFO2 etype = 17, salt = b.comtestuser-b_7, s2kparams = null
PA-ETYPE-INFO2 etype = 23, salt = null, s2kparams = null
>>>Pre-Authentication Data:
PA-DATA type = 2
PA-ENC-TIMESTAMP
>>>Pre-Authentication Data:
PA-DATA type = 16
>>>Pre-Authentication Data:
PA-DATA type = 15
KrbAsReqBuilder: PREAUTH FAILED/REQ, re-send AS-REQ
Using builtin default etypes for default_tkt_enctypes
default etypes for default_tkt_enctypes: 17 16 23.
Using builtin default etypes for default_tkt_enctypes
default etypes for default_tkt_enctypes: 17 16 23.
>>> EType: sun.security.krb5.internal.crypto.Aes128CtsHmacSha1EType
>>> KrbAsReq creating message
getKDCFromDNS using UDP
>>> KrbKdcReq send: kdc=m.b.com. UDP:88, timeout=30000, number of retries =3, #bytes=236
>>> KDCCommunication: kdc=m.b.com. UDP:88, timeout=30000,Attempt =1, #bytes=236
>>> KrbKdcReq send: #bytes read=96
>>> KrbKdcReq send: kdc=m.b.com. TCP:88, timeout=30000, number of retries =3, #bytes=236
>>> KDCCommunication: kdc=m.b.com. TCP:88, timeout=30000,Attempt =1, #bytes=236
>>>DEBUG: TCPClient reading 1520 bytes
>>> KrbKdcReq send: #bytes read=1520
>>> KdcAccessibility: remove m.b.com.:88
>>> EType: sun.security.krb5.internal.crypto.Aes128CtsHmacSha1EType
>>> KrbAsRep cons in KrbAsReq.getReply testuser-b_7
principal is testuser-b_7#b.com
Commit Succeeded
Found ticket for testuser-b_7#b.com to go to krbtgt/b.com#b.com expiring on Mon Jul 04 21:06:17 EDT 2016
Entered Krb5Context.initSecContext with state=STATE_NEW
Found ticket for testuser-b_7#b.com to go to krbtgt/b.com#b.com expiring on Mon Jul 04 21:06:17 EDT 2016
Service ticket not found in the subject
>>> Credentials acquireServiceCreds: main loop: [0] tempService=krbtgt/a.com#b.com
Using builtin default etypes for default_tgs_enctypes
default etypes for default_tgs_enctypes: 17 16 23.
>>> CksumType: sun.security.krb5.internal.crypto.RsaMd5CksumType
>>> EType: sun.security.krb5.internal.crypto.ArcFourHmacEType
getKDCFromDNS using UDP
>>> KrbKdcReq send: kdc=m.b.com. UDP:88, timeout=30000, number of retries =3, #bytes=1463
>>> KDCCommunication: kdc=m.b.com. UDP:88, timeout=30000,Attempt =1, #bytes=1463
>>> KrbKdcReq send: #bytes read=1430
>>> KdcAccessibility: remove m.b.com.:88
>>> EType: sun.security.krb5.internal.crypto.ArcFourHmacEType
>>> Credentials acquireServiceCreds: no tgt; searching thru capath
>>> Credentials acquireServiceCreds: inner loop: [1] tempService=krbtgt/com#b.com
Using builtin default etypes for default_tgs_enctypes
default etypes for default_tgs_enctypes: 17 16 23.
>>> CksumType: sun.security.krb5.internal.crypto.RsaMd5CksumType
>>> EType: sun.security.krb5.internal.crypto.ArcFourHmacEType
getKDCFromDNS using UDP
>>> KrbKdcReq send: kdc=m.b.com. UDP:88, timeout=30000, number of retries =3, #bytes=1457
>>> KDCCommunication: kdc=m.b.com. UDP:88, timeout=30000,Attempt =1, #bytes=1457
>>> KrbKdcReq send: #bytes read=89
>>> KdcAccessibility: remove m.b.com.:88
>>> KDCRep: init() encoding tag is 126 req type is 13
>>>KRBError:
sTime is Mon Jul 04 11:06:17 EDT 2016 1467644777000
suSec is 165721
error code is 7
error Message is Server not found in Kerberos database
sname is krbtgt/com#b.com
msgType is 30
>>> Credentials acquireServiceCreds: inner loop: [2] tempService=krbtgt/COM#b.com
Using builtin default etypes for default_tgs_enctypes
default etypes for default_tgs_enctypes: 17 16 23.
>>> CksumType: sun.security.krb5.internal.crypto.RsaMd5CksumType
>>> EType: sun.security.krb5.internal.crypto.ArcFourHmacEType
getKDCFromDNS using UDP
>>> KrbKdcReq send: kdc=bd.b.com. UDP:88, timeout=30000, number of retries =3, #bytes=1455
>>> KDCCommunication: kdc=bd.b.com. UDP:88, timeout=30000,Attempt =1, #bytes=1455
>>> KrbKdcReq send: #bytes read=87
>>> KdcAccessibility: remove bd.b.com.:88
>>> KDCRep: init() encoding tag is 126 req type is 13
>>>KRBError:
sTime is Mon Jul 04 11:06:17 EDT 2016 1467644777000
suSec is 194031
error code is 7
error Message is Server not found in Kerberos database
sname is krbtgt/COM#b.com
msgType is 30
>>> Credentials acquireServiceCreds: no tgt; cannot get creds
KrbException: Fail to create credential. (63) - No service creds
at sun.security.krb5.internal.CredentialsUtil.acquireServiceCreds(CredentialsUtil.java:156)
at sun.security.krb5.Credentials.acquireServiceCreds(Credentials.java:458)
at sun.security.jgss.krb5.Krb5Context.initSecContext(Krb5Context.java:690)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:248)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179)
at sample.KerberosTicketRetriever$TicketCreatorAction.createTicket(KerberosTicketRetriever.java:123)
at sample.KerberosTicketRetriever$TicketCreatorAction.run(KerberosTicketRetriever.java:90)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:483)
at sample.KerberosTicketRetriever.retrieveTicket(KerberosTicketRetriever.java:194)
at sample.KerberosTicketRetriever.main(KerberosTicketRetriever.java:202)
Exception in thread "main" java.lang.Error: GSSException: No valid credentials provided (Mechanism level: Fail to create credential. (63) - No service creds)
at sample.KerberosTicketRetriever$TicketCreatorAction.run(KerberosTicketRetriever.java:94)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:483)
at sample.KerberosTicketRetriever.retrieveTicket(KerberosTicketRetriever.java:194)
at sample.KerberosTicketRetriever.main(KerberosTicketRetriever.java:202)
Caused by: GSSException: No valid credentials provided (Mechanism level: Fail to create credential. (63) - No service creds)
at sun.security.jgss.krb5.Krb5Context.initSecContext(Krb5Context.java:767)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:248)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179)
at sample.KerberosTicketRetriever$TicketCreatorAction.createTicket(KerberosTicketRetriever.java:123)
at sample.KerberosTicketRetriever$TicketCreatorAction.run(KerberosTicketRetriever.java:90)
... 4 more
Caused by: KrbException: Fail to create credential. (63) - No service creds
at sun.security.krb5.internal.CredentialsUtil.acquireServiceCreds(CredentialsUtil.java:156)
at sun.security.krb5.Credentials.acquireServiceCreds(Credentials.java:458)
at sun.security.jgss.krb5.Krb5Context.initSecContext(Krb5Context.java:690)
... 8 more
LSA: Found Ticket
LSA: Made NewWeakGlobalRef
LSA: Found PrincipalName
LSA: Made NewWeakGlobalRef
LSA: Found DerValue
LSA: Made NewWeakGlobalRef
LSA: Found EncryptionKey
LSA: Made NewWeakGlobalRef
LSA: Found TicketFlags
LSA: Made NewWeakGlobalRef
LSA: Found KerberosTime
LSA: Made NewWeakGlobalRef
LSA: Found String
LSA: Made NewWeakGlobalRef
LSA: Found DerValue constructor
LSA: Found Ticket constructor
LSA: Found PrincipalName constructor
LSA: Found EncryptionKey constructor
LSA: Found TicketFlags constructor
LSA: Found KerberosTime constructor
LSA: Finished OnLoad processing
Related
I have a service which has app and it(integration test) modules and for integration, I deploy necessary services to argocd. When I initialize datasource via application.yml and set the password directly there, it works.
datasource:
url: jdbc:postgresql://${POSTGIS_HOST:localhost}:${POSTGIS_PORT:5433}/${POSTGIS_DB:mydb}
username: ${POSTGIS_USER:username}
password: ${POSTGIS_PASSWORD:password}
But, since I need to retrieve password from vault, I need to initialize datasource via code.
#Configuration
#Slf4j
public class DatabaseConfig {
#Value(value = "${spring.datasource.url}")
private String url;
#Value(value = "${spring.datasource.username}")
private String username;
#Bean
#Primary
// #ConfigurationProperties("spring.datasource")
public DataSource dataSource() throws IOException {
String password = getPostgresPasswordFromVault();
log.info("Password retrieved! {}", password);
return DataSourceBuilder.create()
.url(url)
.username(username)
.password(password)
.build();
}
private String getPostgresPasswordFromVault() throws IOException {
// return blabla
}
}
datasource:
url: jdbc:postgresql://${POSTGIS_HOST:localhost}:${POSTGIS_PORT:5433}/${POSTGIS_DB:mydb}
username: ${POSTGIS_USER:username}
password: ${POSTGIS_PASSWORD:password}
Code retrieves password correctly from vault, no issue there. But above initialization does not work.
When I run this code, I see this trace
Caused by: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "some-ip-address", user "postgres", database "mydb", SSL encryption
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:659)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:180)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:247)
at org.postgresql.Driver.makeConnection(Driver.java:434)
at org.postgresql.Driver.connect(Driver.java:291)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:48)
... 60 more
Suppressed: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:659)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:180)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:244)
... 72 more
But like I said, if I remove DatabaseConfig class and only use application.yml with password set explicitly, it works.
I have a problem when I want to create a new session by livy the session dead after their creation, I have installed Livy , spark 3.0.0 , scala 1.12.10 and python 3.7.I followed these steps:
step 01 : start Livy server
./livy-server start
step 02 : start spark shell
spark-shell
step 03 : executing this code using python 3 :
import json, pprint, requests, textwrap
host = 'http://localhost:8998'
data = {'kind': 'spark'}
headers = {'Content-Type': 'application/json'}
r = requests.post(host + '/sessions', data=json.dumps(data), headers=headers)
r.json()
session_url = host + r.headers['location']
r = requests.get(session_url, headers=headers)
r.json()
statements_url = session_url + '/statements'
data = {'code': '1 + 1'}
r = requests.post(statements_url, data=json.dumps(data), headers=headers)
r.json()
statement_url = host + r.headers['location']
r = requests.get(statement_url, headers=headers)
pprint.pprint(r.json())
data = {
'code': textwrap.dedent("""
val NUM_SAMPLES = 100000;
val count = sc.parallelize(1 to NUM_SAMPLES).map { i =>
val x = Math.random();
val y = Math.random();
if (x*x + y*y < 1) 1 else 0
}.reduce(_ + _);
println(\"Pi is roughly \" + 4.0 * count / NUM_SAMPLES)
""")
}
r = requests.post(statements_url, data=json.dumps(data), headers=headers)
pprint.pprint(r.json())
statement_url = host + r.headers['location']
r = requests.get(statement_url, headers=headers)
pprint.pprint(r.json())
this is the log of my session :
stderr:
20/02/17 14:20:06 WARN Utils: Your hostname, zekri-VirtualBox resolves to a loopback address: 127.0.1.1; using 10.0.2.15 instead (on interface enp0s3)
20/02/17 14:20:06 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/usr/local/spark-3.0.0-preview2-bin-hadoop2.7/jars/spark-unsafe_2.12-3.0.0-preview2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
20/02/17 14:20:07 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function0$class
at org.apache.livy.shaded.json4s.ThreadLocal.<init>(Formats.scala:311)
at org.apache.livy.shaded.json4s.DefaultFormats$class.$init$(Formats.scala:318)
at org.apache.livy.shaded.json4s.DefaultFormats$.<init>(Formats.scala:296)
at org.apache.livy.shaded.json4s.DefaultFormats$.<clinit>(Formats.scala)
at org.apache.livy.repl.Session.<init>(Session.scala:66)
at org.apache.livy.repl.ReplDriver.initializeSparkEntries(ReplDriver.scala:41)
at org.apache.livy.rsc.driver.RSCDriver.run(RSCDriver.java:337)
at org.apache.livy.rsc.driver.RSCDriverBootstrapper.main(RSCDriverBootstrapper.java:93)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:928)
at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1007)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1016)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: scala.Function0$class
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 20 more
Hello I have tried to run the java code, but it gives the error "The proxy server is refusing connections"
Web page is not opened. I have checked the proxy setting as well. It is set as auto detect
still getting the error. I checked the firewall setting also. so please let me know what should do to solve the error
This is code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.MarionetteDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
//import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
//import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class sample_google
{
WebDriver driver;
#BeforeTest
public void setUp(){
// FirefoxProfile profile = new FirefoxProfile();
System.setProperty("webdriver.gecko.driver", "D:\\ashwini\\geckodriver.exe");
driver= new MarionetteDriver();
//driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testsample_google() throws Exception{
driver.get("https://www.google.com/");
// WebElement searchBox = driver.findElement(By.name("q"));
// searchBox.sendKeys("fast cars");
// searchBox.submit();
driver.findElement(By.name("q")).sendKeys("Selenium");
System.out.println("Page title : " + driver.getTitle());
WebElement resultCount = driver.findElement(By.id("resultStats"));
System.out.println("Result Count : " + resultCount.getText());
}
#AfterTest
public void teardown()
{
//driver.quit();
}
}
And error:
[TestNG] Running:
C:\Users\Pramod\AppData\Local\Temp\testng-eclipse-33059775\testng-customsuite.xml
1472721257179 Marionette INFO Listening on port 61629
1472721260499 Marionette INFO startBrowser db6c37fd-5fa7-4f5e-a1fd-89f46151f221
1472721260513 Marionette INFO sendAsync db6c37fd-5fa7-4f5e-a1fd-89f46151f221
1472721261196 Marionette INFO sendAsync db6c37fd-5fa7-4f5e-a1fd-89f46151f221
FAILED: testsample_google
java.lang.NullPointerException
at sample_google.testsample_google(sample_google.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 38 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter#5594a1b5: 31 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter#3f3afe78: 21 ms
[TestNG] Time taken by org.testng.reporters.jq.Main#1cd072a9: 141 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2#34ce8af7: 11 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter#6b71769e: 54 ms
Issue for the proxy is resolved by changing the LAN setting of my computer
I build a spring cloud service ,contains eureka, user-service(spring-data-rest user api) and a feign-client service .
In the feign client :
#FeignClient("useraccount")
public interface UserFeign {
#RequestMapping(method=RequestMethod.POST,value="/users",consumes = "application/json")
void createUser(#RequestBody User user);
#RequestMapping(method=RequestMethod.DELETE,value="/users/{id}")
void delById (#PathVariable("id") String id);
I want to implement removing and storing users in feign-client by calling user-service api . So , i create a rest controller (js Transfer data to them) :
#Autowired
private UserFeign userFeign;
//save controller
#RequestMapping(method = RequestMethod.POST, value = "/property/register")
public ResponseEntity<?> createUser(#RequestBody User user) {
userSaveFeign.createUser(user);
return ResponseEntity.ok();
}
// and delete controller
#RequestMapping(method = RequestMethod.DELETE, value = "/property/{id}")
public String hello(#PathVariable("id") String id){
userSaveFeign.delById(id);
}
return "hello";
}
but it always met errors :
2016-04-16 20:05:41.162 .DynamicServerListLoadBalancer DynamicServerListLoadBalancer for client useraccount initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=useraccount,current list of Servers=[192.168.1.101:useraccount:d3fb971b6fe30dc5e9cbfdf0e713cd12],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:192.168.1.101:useraccount:d3fb971b6fe30dc5e9cbfdf0e713cd12; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList#19c54b19
2016-04-16 20:05:41.836[2m[nio-8002-exec-4][36mo.a.c.c.C.[.[.[/].[dispatcherServlet] [0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.netflix.hystrix.exception.HystrixRuntimeException: createUser timed-out and no fallback available.] with root cause
java.util.concurrent.TimeoutException: null
at com.netflix.hystrix.AbstractCommand$9.call(AbstractCommand.java:600) ~[hystrix-core-1.5.1.jar:1.5.1]
at com.netflix.hystrix.AbstractCommand$9.call(AbstractCommand.java:580) ~[hystrix-core-1.5.1.jar:1.5.1]
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:99) ~[rxjava-1.0.14.jar:1.0.14]
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.14.jar:1.0.14]
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.14.jar:1.0.14]
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:955) ~[hystrix-core-1.5.1.jar:1.5.1]
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41) ~[hystrix-core-1.5.1.jar:1.5.1]
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37) ~[hystrix-core-1.5.1.jar:1.5.1]
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57) ~[hystrix-core-1.5.1.jar:1.5.1]
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:972) ~[hystrix-core-1.5.1.jar:1.5.1]
at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99) ~[hystrix-core-1.5.1.jar:1.5.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_40]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[na:1.8.0_40]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_40]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[na:1.8.0_40]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_40]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]
Maybe the above store and delete method have problems ,but who can tell me the right or better ?
It looks like your Hystrix Command is timing out. Assuming you don't specifically have any Hystrix Commands (as not mentioned in your post), Hystrix is a circuit breaker technology that is included free with Feign Client. You can disable this with:
feign.hystrix.enabled=false
(And you can find more information about Feign-Hystrix integration at http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html#spring-cloud-feign-hystrix)
This won't address the route cause that something is taking a long time to complete. You will need to debug and find out whats hanging. It could be the actual endpoint your Feign client is pointed at is connecting but is not responsive, although I would usually expect to see a specific connection timeout exception in that case.
This is not the actual exception, you should find the reason why its timedout. Enable logging, then you can see why it is failing:
import org.springframework.context.annotation.Bean;
import feign.Logger;
public class FeignConfiguration {
#Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
Also look if the server is resolved at all. Your log should have something like below:
DynamicServerListLoadBalancer for client auth-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=auth-service,current list of Servers=[192.168.2.243:7277],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:192.168.2.243:8180; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 06:00:00 BDT 1970; First connection made: Thu Jan 01 06:00:00 BDT 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList#9481a7c
I have two almost identical controllers connecting to two different JPA Spring data repositories. The JPA request work correctly, been tested.
I have other request on the same server that works perfectly. Why two different requests that are almost identical don't response with a correct response?
How I can find tips from Spring trace about this problem? I get a Status not found for a request:
type Status report
message /hospital/EditWard/HOSP1/
description The requested resource is not available.
In the console I see this trace:
2015-03-06 11:45:16,686 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'dispatcher' processing GET request for [/hospital/EditWard/HOSP1/]
2015-03-06 11:45:16,686 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'dispatcher' processing GET request for [/hospital/EditWard/HOSP1/]
2015-03-06 11:45:16,687 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Looking up handler method for path /EditWard/HOSP1/
2015-03-06 11:45:16,687 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Looking up handler method for path /EditWard/HOSP1/
2015-03-06 11:45:16,689 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Did not find handler method for [/EditWard/HOSP1/]
2015-03-06 11:45:16,689 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Did not find handler method for [/EditWard/HOSP1/]
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Matching patterns for request [/EditWard/HOSP1/] are [/**]
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Matching patterns for request [/EditWard/HOSP1/] are [/**]
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - URI Template variables for request [/EditWard/HOSP1/] are {}
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - URI Template variables for request [/EditWard/HOSP1/] are {}
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapping [/EditWard/HOSP1/] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#23c3853d] and 1 interceptor
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapping [/EditWard/HOSP1/] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#23c3853d] and 1 interceptor
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Last-Modified value for [/hospital/EditWard/HOSP1/] is: -1
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Last-Modified value for [/hospital/EditWard/HOSP1/] is: -1
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
This is my controller:
package com.freschelegacy.controller;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.freschelegacy.model.Ward;
import com.freschelegacy.model.WardId;
import com.freschelegacy.service.WardService;
import com.freschelegacy.service.data.EditWardDTO;
import com.freschelegacy.service.ServiceException;
import com.freschelegacy.repository.WardRepository;
#RestController()
public class EditWardController {
#Autowired
private WardRepository wardRepository;
#Autowired
private WardService wardService;
private final Logger logger = LoggerFactory.getLogger(EditWardController.class);
#Transactional(readOnly=true)
#RequestMapping(value = "/EditWard", method=RequestMethod.GET, produces = "application/json;charset=utf-8")
public Page<EditWardDTO> getEditWard(#PathVariable String hospitalCode, #RequestParam(value= "page", required = false, defaultValue = "0" ) int page,
#RequestParam(value = "size", required = false, defaultValue = "10" ) int size){
Pageable pageable = new PageRequest(page, size);
Page<EditWardDTO> pageEditWard = wardRepository.editWard(hospitalCode, pageable);
return pageEditWard;
}
}
I have added this /{hospitalCode) to the value of the #Request mapping. Now it works.
#RequestMapping(value ="/EditWard/{hospitalCode}", method=RequestMethod.GET, produces = "application/json;charset=utf-8")