Skip to content

Commit

Permalink
Updated libs and code to fit java10
Browse files Browse the repository at this point in the history
  • Loading branch information
GodMod committed Mar 27, 2018
1 parent 3dc8b3e commit 722a6e6
Show file tree
Hide file tree
Showing 24 changed files with 340 additions and 62 deletions.
Binary file added lib/bcel-5.2.jar
Binary file not shown.
Binary file added lib/javax.activation.jar
Binary file not shown.
Binary file added lib/jaxb-api.jar
Binary file not shown.
Binary file added lib/jaxb-core.jar
Binary file not shown.
Binary file added lib/jaxb-impl.jar
Binary file not shown.
Binary file added lib/jaxb-jxc.jar
Binary file not shown.
Binary file added lib/jaxb-xjc.jar
Binary file not shown.
Binary file added lib/jersey-client-1.18.jar
Binary file not shown.
Binary file added lib/jersey-core-1.18.jar
Binary file not shown.
Binary file added lib/jna-4.5.1.jar
Binary file not shown.
Binary file added lib/jna-platform-4.5.1.jar
Binary file not shown.
130 changes: 96 additions & 34 deletions src/com/eqdkplus/jdkp/control/DownloadControl.java
Expand Up @@ -18,7 +18,6 @@
package com.eqdkplus.jdkp.control;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
Expand All @@ -32,8 +31,6 @@
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
Expand All @@ -50,6 +47,7 @@
import org.xml.sax.SAXParseException;

import com.eqdkplus.jdkp.gui.AuthDialog;
import com.eqdkplus.jdkp.gui.AuthTokenDialog;
import com.eqdkplus.jdkp.gui.Gui;
import com.eqdkplus.jdkp.gui.Messages;
import com.eqdkplus.jdkp.parse.Parser;
Expand All @@ -72,7 +70,6 @@ public class DownloadControl extends Control<Void, Object> {
private final Gui gui;
private int contentLength;
private String plainPassword;
private String encryptedPassword;
private FileWriter logFile;
private EqdkpRESTClient rest;
private String sid;
Expand Down Expand Up @@ -158,7 +155,8 @@ private void initializeLog() throws IOException {
logFileName.substring(0, logFileName.lastIndexOf(profile.getLocalPath().getName())) + JDKP_LOG);
}

public void download() throws IOException {
@SuppressWarnings("unused")
public void download() throws IOException {
initializeLog();
log("JDKP download log file"); //$NON-NLS-1$
log("System time: " + DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date())); //$NON-NLS-1$
Expand Down Expand Up @@ -247,18 +245,50 @@ public void download() throws IOException {
if (data.getStatus().equals("0") && data.getError().equals("access denied")) { //$NON-NLS-1$ //$NON-NLS-2$

publish(Messages.getString("DownloadControl.authenticating")); //$NON-NLS-1$

if (!profile.getUsername().equals(Control.EMPTY_STRING)
&& profile.getPassword().equals(Control.EMPTY_STRING)) {
// <obsolete> if (!plainPassword.equals(Control.EMPTY_STRING)) {
try {
profile.setPassword(
getEncryptedPassword(profile.getEncoding(), rest, profile.getUsername(), plainPassword));
} catch (Exception e) {
publish(FAILED);
pendingErr = e;
return;
}

Boolean blnUseToken = false;

if(!profile.getToken().equals(Control.EMPTY_STRING)) {
url = new URL(url.toString() + "&atoken=" + profile.getToken() + "&atype=api"); //$NON-NLS-1$
blnUseToken = true;
} else {

//Try if there is an salt method first (< EQdkp Plus 2.3)
Boolean blnThereIsSalt = false;
try {
String testsalt = rest.getSalt("test");
blnThereIsSalt = true;
} catch(Exception e) {

if(e.getMessage().equals("function not found")){
//We need an API Token here
blnUseToken = true;

boolean a = false;
try {
a = getTokenAuth(rest, url);
} catch (Exception ex) {
publish(FAILED);
pendingErr = ex;
return;
}
url = new URL(url.toString() + "&atoken=" + profile.getToken() + "&atype=api"); //$NON-NLS-1$
gui.setToken(profile.getToken());
}
}


if(blnThereIsSalt) {
if (!profile.getUsername().equals(Control.EMPTY_STRING) && profile.getPassword().equals(Control.EMPTY_STRING)) {

try {
profile.setPassword(
getEncryptedPassword(profile.getEncoding(), rest, profile.getUsername(), plainPassword));
} catch (Exception e) {
publish(FAILED);
pendingErr = e;
return;
}
}
try {
sid = rest.login().getV1();
Expand Down Expand Up @@ -352,6 +382,9 @@ public void download() throws IOException {
* .getString("DownloadControl.notApprPerm")); //$NON-NLS-1$ return;
* } **********************************************
*/

}// end there is salt
} //end if there is no token
publish(String.format(Messages.getString("DownloadControl.downloadFrom"), url.getHost())); //$NON-NLS-1$

try {
Expand Down Expand Up @@ -392,12 +425,19 @@ public void download() throws IOException {
publish(Messages.getString("DownloadControl.authFailed")); //$NON-NLS-1$
publish(FAILED);
pendingErr = new EQDKPException(Messages.getString("DownloadControl.notApprPerm")); //$NON-NLS-1$

if(blnUseToken) {
profile.setToken(Control.EMPTY_STRING);
gui.setToken("");
}

return;
}
}

if (gui.getLastUsedProfile() != null) {
gui.getLastUsedProfile().setPassword(profile.getPassword());
gui.getLastUsedProfile().setToken(profile.getToken());
gui.getLastUsedProfile().save(Control.PROFILE_PATH, true);
}
profile.save(Control.PROFILE_PATH, true);
Expand Down Expand Up @@ -509,24 +549,46 @@ public static String getEncryptedPassword(String encoding, EqdkpRESTClient rest,

private boolean getAuth(EqdkpRESTClient rest, URL url)
throws NoSuchAlgorithmException, UnsupportedEncodingException, JAXBException, SAXException, EQDKPException {
AuthDialog ad = new AuthDialog(gui, url.getHost(), profile.getUsername());
ad.setVisible(true);
String user = ad.getUsername();
String pw = ad.getPassword();
// Pair<String, String> authInfo = ad.getAuthentication(); unsafe
if (user.equals(Control.EMPTY_STRING) || pw.equals(Control.EMPTY_STRING)) {
user = null;
pw = null;
return false;
}
profile.setUsername(user);
profile.setPassword(getEncryptedPassword(profile.getEncoding(), rest, user, pw));

ad.dispose();
user = null;
pw = null;
return true;

AuthDialog ad = new AuthDialog(gui, url.getHost(), profile.getUsername());
ad.setVisible(true);
String user = ad.getUsername();
String pw = ad.getPassword();
// Pair<String, String> authInfo = ad.getAuthentication(); unsafe
if (user.equals(Control.EMPTY_STRING) || pw.equals(Control.EMPTY_STRING)) {
user = null;
pw = null;
return false;
}
profile.setUsername(user);
profile.setPassword(getEncryptedPassword(profile.getEncoding(), rest, user, pw));

ad.dispose();
user = null;
pw = null;
return true;
}

private boolean getTokenAuth(EqdkpRESTClient rest, URL url)
throws NoSuchAlgorithmException, UnsupportedEncodingException, JAXBException, SAXException, EQDKPException {

AuthTokenDialog ad = new AuthTokenDialog(gui, url.getHost(), profile.getToken());
ad.setVisible(true);

String token = ad.getToken();
if(token.equals(Control.EMPTY_STRING)) {
token = null;
return false;
}
profile.setToken(token);

ad.dispose();
token = null;

return true;
}



@Override
protected void done() {
Expand Down
11 changes: 9 additions & 2 deletions src/com/eqdkplus/jdkp/control/ImportControl.java
Expand Up @@ -21,6 +21,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.swing.Icon;
Expand Down Expand Up @@ -114,8 +115,14 @@ private void addInterfaceFile(File f) throws IOException, InstantiationException
.getString("ImportControl.cannotImportAlreadyLoaded"), f.getName()), //$NON-NLS-1$
Messages.getString("Gui.error"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
} else if (GameInterface.class.isAssignableFrom(newInterface)) {
GameInterface gi = (GameInterface) newInterface.newInstance();
gui.addInterface(gi);
GameInterface gi = null;
try {
gi = (GameInterface) newInterface.getConstructor().newInstance();
gui.addInterface(gi);
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
publish(CHECKED);
publish(String.format(Messages.getString("ImportControl.importSuccess"), gi.getName())); //$NON-NLS-1$
} else {
Expand Down
135 changes: 135 additions & 0 deletions src/com/eqdkplus/jdkp/gui/AuthTokenDialog.java
@@ -0,0 +1,135 @@
/*
* Project: EQdkp-Plus jdkp
* License: Creative Commons - Attribution Non-Commercial No Derivatives 3.0 Unported
* Link: http://creativecommons.org/licenses/by-nc-nd/3.0/
*
* Began: 2010
* Date: $Date$
*
* Author: $Author$
* Copyright: 2010-2011 kirax (kirax@eqdkp-plus.com)
* Link: http://eqdkp-plus.com
* Package: jdkp
* Version: $Rev$
*
* $Id$
*/

package com.eqdkplus.jdkp.gui;

import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.eqdkplus.jdkp.control.Control;
import com.eqdkplus.jdkp.util.Pair;

@SuppressWarnings("serial")
public class AuthTokenDialog extends JDialog {

private JLabel head;
private JLabel tokenLabel;
private JTextField tokenField;

private JPanel buttonBar;
private JButton okButton;
private JButton cancelButton;

private boolean cancelled = false;

public synchronized Pair<String, String> getAuthentication() {
this.setVisible(true);
Pair<String, String> auth = new Pair<String, String>(tokenField.getText(), "");
tokenField.setText(Control.EMPTY_STRING);

this.dispose();
if (cancelled) {
return null;
}
return auth;
}

public boolean getCancelled() {
return cancelled;
}

public String getToken() {
return tokenField.getText();
}


public AuthTokenDialog(Window owner, String site, String username) {
super(owner, Messages.getString("AuthDialog.authNeeded"), ModalityType.APPLICATION_MODAL); //$NON-NLS-1$
setLocationByPlatform(true);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.head = new JLabel(Control.HTML_OPEN_TAG+String.format(Messages.getString("AuthDialog.pleaseEnterToken"), site)+Control.HTML_CLOSE_TAG); //$NON-NLS-1$ //$NON-NLS-2$
this.tokenLabel = new JLabel(Messages.getString("Gui.token")); //$NON-NLS-1$
this.tokenField = new JTextField(username);
this.buttonBar = new JPanel(new FlowLayout());
this.okButton = new JButton(Messages.getString("ExceptionDialog.ok")); //$NON-NLS-1$
this.cancelButton = new JButton(Messages.getString("AuthDialog.cancel")); //$NON-NLS-1$
getRootPane().setDefaultButton(okButton);

tokenLabel.setIcon(Control.PASSICON);

GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();

setLayout(gbl);

gbc.insets = new Insets(5, 5, 5, 5);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.gridwidth = 2;

gbl.setConstraints(head, gbc);
add(head);

gbc.gridy = 1;
gbc.gridwidth = 1;
gbl.setConstraints(tokenLabel, gbc);
add(tokenLabel);

gbc.weightx = 0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbl.setConstraints(tokenField, gbc);
add(tokenField);


gbc.gridy = 2;
buttonBar.add(okButton);
buttonBar.add(cancelButton);

gbl.setConstraints(buttonBar, gbc);
add(buttonBar);

pack();

this.okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
AuthTokenDialog.this.setVisible(false);

}
});

this.cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelled = true;
AuthTokenDialog.this.setVisible(false);
}
});
}
}

0 comments on commit 722a6e6

Please sign in to comment.