Skip to content

Commit

Permalink
Update session auth;
Browse files Browse the repository at this point in the history
Remove manual setting
  • Loading branch information
extempl committed Aug 24, 2020
1 parent accdccc commit 7ce1c94
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 108 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "1.2.8"
version = "1.2.9"

ext {
guiceVersion = "4.0"
Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/org/f0w/k2i/core/ConfigValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public static Config checkValid(Config config) {
validator.checkLogLevel();

validator.checkAuthAtMain();
validator.checkAuthXMain();
validator.checkAuthSessionId();
validator.checkAuthSessionToken();
validator.checkAuthUbidMain();
validator.checkAuthControl();
validator.checkMode();
Expand Down Expand Up @@ -164,6 +166,17 @@ private void checkAuthAtMain() {
checkArgument(auth.length() > 10, "auth string (at-main) length is less than or equal to 10!");
}

/**
* Checks the auth x-main string
*
* @throws IllegalArgumentException If not valid
*/
private void checkAuthXMain() {
val auth = config.getString("authXMain");

checkArgument(auth.length() > 10, "auth string (x-main) length is less than or equal to 10!");
}

/**
* Checks the auth session id string
*
Expand All @@ -175,6 +188,17 @@ private void checkAuthSessionId() {
checkArgument(auth.length() > 10, "auth string (sessionId) length is less than or equal to 10!");
}

/**
* Checks the auth session token string
*
* @throws IllegalArgumentException If not valid
*/
private void checkAuthSessionToken() {
val auth = config.getString("authSessionToken");

checkArgument(auth.length() > 10, "auth string (sessionToken) length is less than or equal to 10!");
}

/**
* Checks the auth ubid-main string
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public ExchangeObject<Integer> prepare(@NonNull Movie movie) throws IOException
.userAgent(config.getString("user_agent"))
.timeout(config.getInt("timeout"))
.cookie("session-id", config.getString("authSessionId"))
.cookie("session-token", config.getString("authSessionToken"))
.cookie("at-main", config.getString("authAtMain"))
.cookie("x-main", config.getString("authXMain"))
.cookie("ubid-main", config.getString("authUbidMain"))
.header("Content-Type", "application/x-www-form-urlencoded")
.ignoreContentType(true)
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"mode": "COMBINED",
"list": "",
"curlText": "",
"authXMain": "",
"authAtMain": "",
"authSessionId": "",
"authSessionToken": "",
"authUbidMain": "",
"authControlKey": "",
"authControlValue": "",
Expand Down
2 changes: 1 addition & 1 deletion gui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

mainClassName = 'org.f0w.k2i.gui.Main'
version = '1.2.8'
version = '1.2.9'

dependencies {
compile project(':k2i-core')
Expand Down
42 changes: 3 additions & 39 deletions gui/src/main/java/org/f0w/k2i/gui/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,6 @@ public class Controller {
@FXML
private TextArea curlText;

@FXML
private TextField authId;

@FXML
private TextField authAtMain;

@FXML
private TextField authSessionId;

@FXML
private TextField authUbidMain;

@FXML
private TextField authControlKey;

@FXML
private TextField authControlValue;

@FXML
private TextField listId;

Expand Down Expand Up @@ -158,21 +140,6 @@ void initialize() {

curlText.setText(config.getString("curlText"));

authAtMain.focusedProperty().addListener(o -> configMap.put("authAtMain", authAtMain.getText()));
authAtMain.setText(config.getString("authAtMain"));

authSessionId.focusedProperty().addListener(o -> configMap.put("authSessionId", authSessionId.getText()));
authSessionId.setText(config.getString("authSessionId"));

authUbidMain.focusedProperty().addListener(o -> configMap.put("authUbidMain", authUbidMain.getText()));
authUbidMain.setText(config.getString("authUbidMain"));

authControlKey.focusedProperty().addListener(o -> configMap.put("authControlKey", authControlKey.getText()));
authControlKey.setText(config.getString("authControlKey"));

authControlValue.focusedProperty().addListener(o -> configMap.put("authControlValue", authControlValue.getText()));
authControlValue.setText(config.getString("authControlValue"));

listId.focusedProperty().addListener(o -> configMap.put("list", listId.getText()));
listId.setText(config.getString("list"));

Expand Down Expand Up @@ -239,7 +206,7 @@ void initialize() {
}

private void parseCurlText(String plainCurlText) {
Pattern p = Pattern.compile(".*-H 'cookie: ([^']+)'.*--data '(\\w+)=(\\w+)'.*");
Pattern p = Pattern.compile(".*-H 'cookie: ([^']+)'.*--data-raw '(\\w+)=(\\w+)'.*");
Matcher m = p.matcher(plainCurlText.replace("\n", ""));
while (m.find()) {
String cookies = m.group(1);
Expand All @@ -253,15 +220,12 @@ private void parseCurlText(String plainCurlText) {
cookiesMap.put(cookieMap[0], cookieMap[1]);
}

authAtMain.setText(cookiesMap.get("at-main"));
configMap.put("authXMain", cookiesMap.get("x-main"));
configMap.put("authAtMain", cookiesMap.get("at-main"));
authSessionId.setText(cookiesMap.get("session-id"));
configMap.put("authSessionId", cookiesMap.get("session-id"));
authUbidMain.setText(cookiesMap.get("ubid-main"));
configMap.put("authSessionToken", cookiesMap.get("session-token"));
configMap.put("authUbidMain", cookiesMap.get("ubid-main"));
authControlKey.setText(authControlKeyString);
configMap.put("authControlKey", authControlKeyString);
authControlValue.setText(authControlValueString);
configMap.put("authControlValue", authControlValueString);
}
}
Expand Down
78 changes: 11 additions & 67 deletions gui/src/main/resources/fxml/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -70,75 +70,19 @@
<RowConstraints minHeight="40.0"/>
</rowConstraints>
<children>
<Label text="Настройки авторизации IMDB"/>
<Label text="Настройки авторизации IMDB (cURL)"/>
</children>
</GridPane>
<GridPane hgap="10.0" vgap="2.0" layoutX="20.0" layoutY="210.0" prefHeight="225.0">
<children>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<TextArea fx:id="curlText" layoutX="10.0" layoutY="10.0" prefWidth="530.0" prefHeight="200.0"
wrapText="true" />
</children>
</AnchorPane>
</children>
</GridPane>
<Accordion prefWidth="550.0" layoutX="20.0" layoutY="210.0" prefHeight="185.0">
<panes>
<!--Start basic-->
<TitledPane fx:id="nestedBasePane" animated="false" text="Генерация из cURL">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<TextArea fx:id="curlText" layoutX="10.0" layoutY="10.0" prefWidth="530.0" prefHeight="110.0"
wrapText="true" />
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Установить вручную">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<GridPane hgap="10.0" layoutX="16.0" vgap="2.0">
<columnConstraints>
<ColumnConstraints prefWidth="162.0"/>
<ColumnConstraints prefWidth="345.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints prefHeight="40.0"/>
<RowConstraints prefHeight="40.0"/>
<RowConstraints prefHeight="40.0"/>
</rowConstraints>
<children>
<Label text="at-main"/>
<TextField fx:id="authAtMain" GridPane.columnIndex="1"/>
<Label text="session-id" GridPane.rowIndex="1"/>
<TextField fx:id="authSessionId"
GridPane.columnIndex="1"
GridPane.rowIndex="1"/>
<Label text="ubid-main" GridPane.rowIndex="2"/>
<TextField fx:id="authUbidMain"
GridPane.columnIndex="1"
GridPane.rowIndex="2"/>
</children>
</GridPane>
<GridPane hgap="10.0" layoutX="16.0" layoutY="165.0">
<columnConstraints>
<ColumnConstraints prefWidth="290.0"/>
<ColumnConstraints prefWidth="103.0"/>
<ColumnConstraints prefWidth="103.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="40.0"/>
</rowConstraints>
<children>
<Label text="Пара ключ-значение в тестовом запросе"/>
<TextField fx:id="authControlKey"
GridPane.columnIndex="1"/>
<TextField fx:id="authControlValue"
GridPane.columnIndex="2"/>
</children>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
</panes>
<expandedPane>
<fx:reference source="nestedBasePane"/>
</expandedPane>
</Accordion>
</children>
</AnchorPane>
</content>
Expand Down

0 comments on commit 7ce1c94

Please sign in to comment.