use of org.springframework.boot.web.client.RestTemplateBuilder in project sw360portal by sw360.
the class Sw360AuthenticationProvider method isAuthorized.
private boolean isAuthorized(String email, String password) {
// Solution 1:
// UserLocalServiceUtil.authenticateForBasic
// userId = UserLocalServiceUtil.authenticateForBasic(companyId, authType, login, current);
// this need a dependency to liferay
// Solution 2:
// Liferay json webservice call to verify username and password
String liferayParameterURL = "/api/jsonws/user/get-user-id-by-email-address?companyId=%s&emailAddress=%s";
String url = sw360PortalServerURL + String.format(liferayParameterURL, sw360LiferayCompanyId, email);
RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder();
String encodedPassword;
try {
encodedPassword = URLDecoder.decode(password, "US-ASCII");
} catch (UnsupportedEncodingException e) {
return false;
}
RestTemplate restTemplate = restTemplateBuilder.basicAuthorization(email, encodedPassword).build();
ResponseEntity<String> response = restTemplate.postForEntity(url, null, String.class);
try {
// The user exits in liferay if the body contains a number
Integer.parseInt(response.getBody());
} catch (NumberFormatException e) {
return false;
}
return true;
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RestTemplateMetricsConfigurationTests method restTemplateCanBeCustomizedManually.
@Test
void restTemplateCanBeCustomizedManually() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(MetricsRestTemplateCustomizer.class);
RestTemplateBuilder customBuilder = new RestTemplateBuilder().customizers(context.getBean(MetricsRestTemplateCustomizer.class));
MeterRegistry registry = context.getBean(MeterRegistry.class);
validateRestTemplate(customBuilder, registry);
});
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RestTemplateMetricsConfigurationTests method restTemplateWithRootUriIsInstrumented.
@Test
void restTemplateWithRootUriIsInstrumented() {
this.contextRunner.run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
RestTemplateBuilder builder = context.getBean(RestTemplateBuilder.class);
builder = builder.rootUri("/root");
validateRestTemplate(builder, registry, "/root");
});
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class CloudFoundrySecurityServiceTests method skipSslValidationWhenTrue.
@Test
void skipSslValidationWhenTrue() {
RestTemplateBuilder builder = new RestTemplateBuilder();
this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, true);
RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(this.securityService, "restTemplate");
assertThat(restTemplate.getRequestFactory()).isInstanceOf(SkipSslVerificationHttpRequestFactory.class);
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class CloudFoundrySecurityServiceTests method setup.
@BeforeEach
void setup() {
MockServerRestTemplateCustomizer mockServerCustomizer = new MockServerRestTemplateCustomizer();
RestTemplateBuilder builder = new RestTemplateBuilder(mockServerCustomizer);
this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, false);
this.server = mockServerCustomizer.getServer();
}
Aggregations