"com.hierynomus.mssmb2.SMBApiException: STATUS_ACCESS_DENIED: Authentication failed ..." on authenticate call - java

I'm trying to connect to an SMB server using com.hierynomus.smbj v0.10.0. Connection is ok but as soon as I try to authenticate I'm getting this exception:
com.hierynomus.mssmb2.SMBApiException: STATUS_ACCESS_DENIED (0xc0000022): Authentication failed for 'USERNAME' using com.hierynomus.smbj.auth.NtlmAuthenticator#4152d38d
at com.hierynomus.smbj.connection.Connection.authenticate(Connection.java:194)
at MyTest.smbj(MyTest.java:...)
Here is the test code to see what I'm doing:
#Test
void smbj() throws Exception {
SMBClient client = new SMBClient();
try (Connection connection = client.connect("my-smb-server.de")) {
AuthenticationContext ac = new AuthenticationContext("USERNAME", "PASSWORD".toCharArray(), "DOMAIN");
Session session = connection.authenticate(ac);
// ... do more here ...
}
}
The SMB server and connection is perfectly fine since I'm able to connect from the same machine the test is running using multiple GUI tools (e.g. ForkLift) without any customized settings.
connection.getConnectionInfo() returns this before doing the authentication:
Successfully connected to: my-smb-server.de
ConnectionInfo{
serverGuid=975b39d3-55c0-4490-84e7-80371b734ce7,
serverName='my-smb-server.de',
negotiatedProtocol=NegotiatedProtocol{dialect=SMB_2_1, maxTransactSize=8388608, maxReadSize=8388608, maxWriteSize=8388608},
clientGuid=85863c1f-0328-4c21-9a72-b3d907b23a1d,
clientCapabilities=[SMB2_GLOBAL_CAP_DFS],
serverCapabilities=[SMB2_GLOBAL_CAP_DFS, SMB2_GLOBAL_CAP_LEASING, SMB2_GLOBAL_CAP_LARGE_MTU], > clientSecurityMode=0,
serverSecurityMode=3,
server='null' }
Any help is highly appreciated.

Related

Issue with connecting tfs using java tfs sdk programatically

I have code where i'm connecting to TFS using java tfs sdk like below,
*
*Credentials credentials = new UsernamePasswordCredentials( "xxxxxx", "XXXXX"); getConnection(serverURI, credentials, maxDate, buildNo);
}
private static void getConnection(URI serverURI, final Credentials credentials, String maxDate, String buildNo)
{
TFSTeamProjectCollection tpc = null;
try{
tpc = new TFSTeamProjectCollection(serverURI, credentials);
tpc.authenticate();
}catch(Exception e){
System.out.println(e.getMessage());
}*
But its stop authenticating using username and password, what the alternative authentication type like PAT - i need code to authenticate it, please help on this.
I tested with username and password as credentials, and I can connect to TFS normally on my side.
Here is a ticket you can refer to .

Create connection to SQL database using JDBC Driver- SQLException [duplicate]

I am trying to connect to my database by JDBC on localhost. Connecting via windows authentication is no problem, but I want to connect via SQL authentication. Therefore, I created a login and a user corresponding to this login in my database. I can normally log in SSMS:
My connection string for JDBC:
jdbc:sqlserver://localhost:1433;databaseName=TestBazyDanych;user=doszke;password=doszke123
Thrown exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'doszke'. ClientConnectionId:b7005fe3-904d-40c5-a89e-af0cb61250d6
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:258)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:104)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4772)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3581)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:81)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3541)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7240)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2869)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2395)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2042)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1889)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1120)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:700)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
at main.Main.main(Main.java:38)
The username and password are the same, as those used for loging to SSMS.
Here my class code:
package main;
import java.sql.*;
public class Main {
private static ResultSet selectStan(Connection connection) throws SQLException {
String sql_stmt = "SELECT * FROM STAN;";
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(sql_stmt);
System.out.println("Select executed");
return result;
}
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String userName = "doszke";
String password = "doszke123";
String url = "jdbc:sqlserver://localhost:1433;databaseName=TestBazyDanych;user=doszke;password=doszke123";
try (Connection con = DriverManager.getConnection(url)) {
if(con != null){
System.out.println("connected");
} else {
System.out.println("unable to connect");
}
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
As Mark Rotteveel pointed out, I was trying to connect to a LocalDB instance with JDBC, which seemed undoable. (ref: here)
However, I installed jTDS and added to my classpath, changed my connection string to
jdbc:jtds:sqlserver://./TestBazyDanych;instance=LOCALDB#EB7165FD;namedPipe=true
create a connection by the use of this connection string, username and password and it worked. The instance pipe number was taken from cmd line via
sqllocaldb i MSSQLLocalDB
There are few things need to check:
Did you create doszke user under the database and SSMS?
Are you able to login with doszke/doszke123 credentials in SSMS?
Please check 1433 port are open or not in your inbound and outbound firewall.
Trying to telnet on localhost 1433. If it's getting failed change below setting:
Go to Configuration tools -> SQL Server Configuration Manager Select SQL Server Network Configuration -> Select protocol in the right side window enable tcp/ip and restart the services in services.

Connection via SQuirreL works but via own app doesn't. Receive access denied for user

sorry for my broken english, not a native speaker :)
Here is my problem:
I try to connect via JDBC to a DB hosted on a MySQL server (Version: 5.6.37). I don't host the server and can't change any server configs.
When I try to connect using SQuirreL everything works as expected. I get access to the DB.
When I try to connect via self-written app via my IDE (eclipse) I get an Caused by: java.sql.SQLException: Access denied for user ... (using password: YES)
I'm using HikariCP to manage the connections. Tried also non connection pool aproach via DriverManager.getConnection. Both times the same.
The driver I'm using is mysql-connector-java-5.1.44-bin.jar
// DriverManager approach
private static final Properties dbProps = new Properties();
static {
dbProps.put("password", dbPass);
dbProps.put("user", dbUser);
dbProps.put("autoReconnect", "true");
dbProps.put("failOverReadOnly", "false");
dbProps.put("maxReconnects", "1");
}
...
public static Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(connectionString, dbProps);
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
...
// HakiriCP approach
private static HikariConfig config = new HikariConfig();
private static HikariDataSource ds;
private static final Properties dbProps = new Properties();
static {
PropertyLoader.loadPropertiesFromFile(dbProps); // read properties from external source
config.setJdbcUrl(String.format("jdbc:mysql://%s:%s/%s", dbProps.getProperty("db.server"),
dbProps.getProperty("db.port"), dbProps.getProperty("db.database")));
config.setUsername(dbProps.getProperty("db.user"));
config.setPassword(dbProps.getProperty("db.pass"));
config.addDataSourceProperty("cachePrepStmts", dbProps.getProperty("db.cachePrepStmts", "true"));
config.addDataSourceProperty("prepStmtCacheSize", dbProps.getProperty("db.prepStmtCacheSize", "250"));
config.addDataSourceProperty("prepStmtCacheSqlLimit", dbProps.getProperty("db.prepStmtCacheSqlLimit", "2048"));
ds = new HikariDataSource(config);
}
...
public static Connection getConnection() {
Connection con = null;
try {
con = ds.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
...
EDIT - when I wireshark the connection tries, I see different encoded passwords (SQuirreL vs App). But when I print the password to the console it is exactly the one that work with SQuirreL.
EDIT - The connecttion handling is done in one single class. When I test it all alone without any of the other logic (it is a old swing app) everything works fine. But when I make the exact same call from the swing application it fails '(sends different password string).
What am I doing wrong?
I'm thankful for every help.
Cheers!
I found the solution. For all the project I have UTF-8 encoding. But eclipse decided to use UTF-16 when running or debugging code.
Option can be found here: Run Configurations -> Common -> Encoding
Ok, eclipse made some joke with me.
Thanks to wireshark givin me the hint that something is wrong with the encoding.
Thanks to you guys to trying to help (inluding the ones giving me -1, they don't know it better ;))
Cheers!

XMPPError: bad-request - modify error create new user using smack library 4.1.8 and openfire

i have been developing a chat application using smack client library 4.1.8 and xmpp server(openfire server) but while trying to create new user using Accountmanger class it raises and exception "XMPPError: bad-request - modify"
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setHost("127.0.0.1")
.setDebuggerEnabled(true)
.setPort(5222)
.setSendPresence(true)
.setServiceName("127.0.0.1")
.build();
AbstractXMPPConnection conn2 = new XMPPTCPConnection(conf);
//conn2.login();
conn2.connect();
AccountManager accountManager = AccountManager.getInstance(conn2);
if (accountManager.supportsAccountCreation()) {
accountManager.sensitiveOperationOverInsecureConnection(true);
accountManager.createAccount("qidus", "123456");
conn2.login("qidus", "123456");
}
} catch (SmackException | IOException | XMPPException e) {
e.printStackTrace();
}
and the exception is this
04:01:41 AM SENT (0): <iq to='127.0.0.1' id='aYej1-3' type='get'><query xmlns='jabber:iq:register'></query></iq>
04:01:41 AM RECV (0):
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: bad-request - modify
at org.jivesoftware.smack.XMPPException$XMPPErrorException.ifHasErrorThenThrow(XMPPException.java:135)
at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:232)
at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:213)
at org.jivesoftware.smackx.iqregister.AccountManager.getRegistrationInfo(AccountManager.java:332)
at org.jivesoftware.smackx.iqregister.AccountManager.supportsAccountCreation(AccountManager.java:144)
at chat.Chat$1.run(Chat.java:46)
You need to set properly Service Name. You can chek your serviceName in Openfire through admin panel (127.0.0.1:9090) it's in first page in middle of the page, look for "Server Name" after login.
By default it's your machine name.
However your code will run just once: 2nd time AccountManger will throw an exception due to already registered user.
You also get this error or exception when the username which you are passing for account creation has the null value.So check your username also.

java.net.ConnectException while running webservice?

I am developing the web service where in I want to connect to the SOA server. It's giving connection exception.
Code:
public class ConnectSOA{
public static void main(String[] args){
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String> connProperties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();
connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,WorkflowServiceClientFactory.REMOTE_CLIENT);
connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,"t3://10.10.78.79:8001");
connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
try {
workflowServiceClient = WorkflowServiceClientFactory
.getWorkflowServiceClient(connProperties, null, null);
itaskQueryService = workflowServiceClient.getTaskQueryService();
statePredicate = new Predicate(
TableConstants.WFTASK_STATE_COLUMN, Predicate.OP_EQ,
IWorkflowConstants.TASK_STATE_ASSIGNED);
iworkFlowContext = itaskQueryService.authenticate("demouser","demo1".toCharArray(), null);
} catch(Exception e ){
e.printStackTrace();
}
}
}
Exception :
java.net.ConnectException: t3://10.10.78.79:8001 Bootstrap to: hostname/'10.10.78.79:8001' over: 't3' got an error or timed out
I have check the soa server its up and running on the machine.
Can you ping your weblogic?
java weblogic.Admin -url t3://IP:8001 -username xxx -password xxx PING 10
I see that you have 10.10.78.79:8001 and in Exception IP:8001
Could be that your server is not ok. Check the config. See your config.xml and what the listen address for the server is and verify that you can ping it.

Categories