Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.demo.kerberos.kerberos.controller;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.io.IOException;
- import java.net.Authenticator;
- import java.net.PasswordAuthentication;
- import java.net.URI;
- import java.net.http.HttpClient;
- import java.net.http.HttpRequest;
- import java.net.http.HttpResponse;
- @RestController
- public class AuthController {
- @GetMapping("/kerberosDemo")
- String demo() throws IOException, InterruptedException {
- HttpClient client = HttpClient.newBuilder()
- .authenticator(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("postman", "password".toCharArray());
- }
- })
- .build();
- HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(uri))
- .build();
- HttpResponse<String> response =
- client.send(request, HttpResponse.BodyHandlers.ofString());
- return "Ok";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement