Advertisement
nicb

Untitled

Jun 3rd, 2022
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.demo.kerberos.kerberos.controller;
  2.  
  3. import org.springframework.web.bind.annotation.GetMapping;
  4. import org.springframework.web.bind.annotation.RestController;
  5.  
  6. import java.io.IOException;
  7. import java.net.Authenticator;
  8. import java.net.PasswordAuthentication;
  9. import java.net.URI;
  10. import java.net.http.HttpClient;
  11. import java.net.http.HttpRequest;
  12. import java.net.http.HttpResponse;
  13.  
  14. @RestController
  15. public class AuthController {
  16.     @GetMapping("/kerberosDemo")
  17.     String demo() throws IOException, InterruptedException {
  18.         HttpClient client = HttpClient.newBuilder()
  19.                 .authenticator(new Authenticator() {
  20.                     @Override
  21.                     protected PasswordAuthentication getPasswordAuthentication() {
  22.                         return new PasswordAuthentication("postman", "password".toCharArray());
  23.                     }
  24.                 })
  25.                 .build();
  26.         HttpRequest request = HttpRequest.newBuilder()
  27.                 .uri(URI.create(uri))
  28.                 .build();
  29.         HttpResponse<String> response =
  30.                 client.send(request, HttpResponse.BodyHandlers.ofString());
  31.         return "Ok";
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement