Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cookieJar to get super administrator privileges #25

Open
lusains opened this issue May 7, 2022 · 1 comment
Open

use cookieJar to get super administrator privileges #25

lusains opened this issue May 7, 2022 · 1 comment

Comments

@lusains
Copy link

lusains commented May 7, 2022

hello~we can use cookieJar to get super administrator privileges.

public static void main(String[] args) {
        String url = "http://localhost:8070/signin";
        FormBody loginBody = new FormBody.Builder()
                .add("username", "apollo")
                .add("password", "admin")
                .build();
        OkHttpClient client = new OkHttpClient.Builder().cookieJar(new CookieJar() {
            private final HashMap<String, List<okhttp3.Cookie>> cookieStore = new HashMap<>();
            @Override
            public void saveFromResponse(HttpUrl url, List<okhttp3.Cookie> cookies) {
                cookieStore.put(url.host(), cookies);
            }
            @Override
            public List<okhttp3.Cookie> loadForRequest(HttpUrl url) {
                List<okhttp3.Cookie> cookies = cookieStore.get(url.host());
                return cookies != null ? cookies : new ArrayList<>();
            }
        }).build();

        //调用登录接口,刷新cookie到CookieJar
        Request request = new Request.Builder().url(url).post(loginBody).build();
        Response response = client.newCall(request).execute();
        try {
            //调用业务接口,通过loadForRequest请求授权等管理器接口
            String url2 = "http://localhost:8070/consumers/509c8cc78e667529eaaf332c44a845b9c58857b5/assign-role?type=AppRole";
            String json = "{\"appId\":\"sentinel-dashboard\"}";
            RequestBody body2 = RequestBody.create(JSON, json);
            Response response2 = client.newCall(request2).execute();
            System.out.println(response2.body().string());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
@kuaile-zc
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants