Merge pull request #7433 from amit2103/BAEL-16045-9

Bael 16045 9
This commit is contained in:
Loredana Crusoveanu 2019-11-02 17:45:25 +02:00 committed by GitHub
commit 25bc147f30
2 changed files with 13 additions and 1 deletions

View File

@ -71,5 +71,4 @@ public class LoginController {
return "loginSuccess";
}
}

View File

@ -1,8 +1,12 @@
package org.baeldung.web.controller;
import java.nio.charset.Charset;
import org.apache.commons.codec.binary.Base64;
import org.baeldung.web.dto.Bar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -28,4 +32,13 @@ public class BarController {
return new Bar();
}
public HttpHeaders createHeaders(String username, String password){
return new HttpHeaders() {{
String auth = username + ":" + password;
byte[] encodedAuth = Base64.encodeBase64(
auth.getBytes(Charset.forName("US-ASCII")) );
String authHeader = "Basic " + new String( encodedAuth );
set( "Authorization", authHeader );
}};
}
}