Java - autologin web externas

   
Vista:

autologin web externas

Publicado por Jose Arnoldo arnoldovargas1981@gmail.com (2 intervenciones) el 23/07/2016 22:39:54
Saludos esto es javaFX tengo el siguiente codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
4.94 KB
 
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package webengine;
 
import javafx.application.Application;
import javafx.beans.property.*;
import javafx.beans.value.*;
import javafx.event.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.web.*;
import javafx.stage.Stage;
import org.w3c.dom.*;
import org.w3c.dom.html.*;
 
/**
 *
 * @author jose
 */
public class formulario extends Application {
 
    public static void main(String[] args) {
        launch(args);
    }
 
    @Override
    public void start(Stage stage) {
        final TextField fxUsername = new TextField();
        fxUsername.setPrefColumnCount(20);
        final TextField fxPassword = new PasswordField();
 
        final BooleanProperty loginAttempted = new SimpleBooleanProperty(false);
        final WebView webView = new WebView();
        webView.setPrefWidth(1000);
        final WebEngine engine = webView.getEngine();
        engine.documentProperty().addListener(new ChangeListener<Document>() {
            @Override
            public void changed(ObservableValue<? extends Document> ov, Document oldDoc, Document doc) {
                if (doc != null && !loginAttempted.get()) {
                    if (doc.getElementsByTagName("form").getLength() > 0) {
                    }
                    HTMLFormElement form = (HTMLFormElement) doc.getElementsByTagName("form").item(0);
                     if ("/oam/server/sso/auth_cred_submit".equals(form.getAttribute("action"))) {
                        HTMLInputElement username = null;
                        HTMLInputElement password = null;
                        NodeList nodes = form.getElementsByTagName("input");
                        for (int i = 0; i < nodes.getLength(); i++) {
                            HTMLInputElement input = (HTMLInputElement) nodes.item(i);
                            switch (input.getName()) {
                                    case "ssousername":
                                        username = input;
                                        break;
                                    case "password":
                                        password = input;
                                        break;
                                }
                        }
 
                        if (username != null && password != null) {
                            loginAttempted.set(true);
                            username.setValue(fxUsername.getText());
                            password.setValue(fxPassword.getText());
                            form.submit();
                        }
                    }
                }
            }
        });
        engine.getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {
            @Override
            public void changed(ObservableValue<? extends Throwable> ov, Throwable oldException, Throwable exception) {
                System.out.println("Load Exception: " + exception);
            }
        });
 
        GridPane inputGrid = new GridPane();
        inputGrid.setHgap(10);
        inputGrid.setVgap(10);
        inputGrid.addRow(0, new Label("Username: "), fxUsername);
        inputGrid.addRow(0, new Label("Password: "), fxPassword);
 
        Button fxLoginButton = new Button("Login");
        fxLoginButton.setOnAction(new EventHandler<ActionEvent>() {
 
            @Override
            public void handle(ActionEvent t) {
                if (notEmpty(fxPassword.getText()) && notEmpty(fxPassword.getText())) {
                    loginAttempted.set(false);
                    engine.load("https://forums.oracle.com/community/developer/english/java/javafx/login.jspa");
                }
            }
        });
        fxLoginButton.setDefaultButton(true);
        ProgressIndicator fxLoadProgress = new ProgressIndicator(0);
        fxLoadProgress.progressProperty().bind(webView.getEngine().getLoadWorker().progressProperty());
        fxLoadProgress.visibleProperty().bind(webView.getEngine().getLoadWorker().runningProperty());
 
        HBox loginPane = new HBox(10);
        loginPane.getChildren().setAll(
                fxLoginButton,
                fxLoadProgress
        );
 
        final VBox layout = new VBox(10);
        layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
        layout.getChildren().addAll(
                new Label("Enter your Oracle Credencial"),
                inputGrid,
                loginPane,
                webView
        );
        VBox.setVgrow(webView, Priority.ALWAYS);
 
        stage.setScene(new Scene(layout));
        stage.show();
 
        fxUsername.requestFocus();
    }
 
    private boolean notEmpty(String s) {
        return s != null && !"".equals(s);
    }
 
}

Lo que pasa con este codigo es que no funciona para autologarse en cualquier pagina, algo le falta al codigo??, necesito logearme de este modo a la pagina http://www.SII.CL es para una aplicacion de escritorio y no lo consigo, de antemano, gracias a los que leen...
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder