无图形化界面下WebLogic第三方API

部署

1
2
3
4
5
6
7
java -cp weblogic.jar weblogic.Deployer \
-adminurl t3://127.0.0.1:7001 \
-user 用户名 \
-password 密码 \
-redeploy \
-name 自定义名字 \
-source war包

更改中心的锁定并编辑 -> 释放配置

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
import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.util.Map;

public class FuckWebLogic {
public static void main(String[] args) {
try {
String SERVER = "http://127.0.0.1:7001/console";

Connection connection = Jsoup.connect(SERVER + "/j_security_check")
.method(Connection.Method.POST)
.data("j_username", "username")
.data("j_password", "password")
.followRedirects(false);//不自动重定向, 为了下面根据状态码判断是否登录成功, 不然都是返回200

Connection.Response response = connection.execute();
int statusCode = response.statusCode();
switch (statusCode) {
case 200:
System.out.println("login err");
break;
case 302:
System.out.println("login ok");

//登录成功的Cookie
Map<String, String> cookies = response.cookies();
System.out.println("Cookie -> " + cookies);

//获取页面的防CSRF隐藏参数(这里类似验证码的效果)
String token = connection.url(SERVER + "/console.portal")
.method(Connection.Method.GET)
.cookies(cookies)
.followRedirects(true)//这里就要设置true了
.execute()
.parse()
.select("input[name=ChangeManagerPortletfrsc]").val();

System.out.println("Token -> " + token);

//这时要刷新Cookie, 和上面的隐藏参数要对得上
cookies = response.cookies();
System.out.println("new Cookie -> " + cookies);

//模拟点击操作
response = connection.url(SERVER + "/console.portal")
.method(Connection.Method.POST)
.data("ChangeManagerPortlet_actionOverride", "/StopEditAction")
.data("ChangeManagerPortletfrsc", token)
.cookies(cookies)
.execute();

//如果标题没有指定字符串, 说明Cookie错误, 跳到登录页了
System.out.println(response.body().contains("dmz") ? "ok" : "err");
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}