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

Allow CAS to authenticate itself at the REST password management endpoints #3685

Merged
merged 6 commits into from Dec 30, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -144,6 +144,16 @@ public static class Rest implements Serializable {
* Endpoint URL to use when updating passwords..
*/
private String endpointUrlChange;
larsgrefer marked this conversation as resolved.
Show resolved Hide resolved

/**
* Username for Basic-Auth at the password management endpoints.
*/
private String endpointUsername;

/**
* Password for Basic-Auth at the password management endpoints.
*/
private String endpointPassword;
}

@RequiresModule(name = "cas-server-support-pm-ldap")
Expand Down
Expand Up @@ -2,17 +2,18 @@

import org.apereo.cas.CipherExecutor;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties;
import org.apereo.cas.pm.PasswordManagementService;
import org.apereo.cas.pm.rest.RestPasswordManagementService;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.util.StringUtils;

/**
* This is {@link RestPasswordManagementConfiguration}.
Expand All @@ -32,10 +33,19 @@ public class RestPasswordManagementConfiguration {

@RefreshScope
@Bean
public PasswordManagementService passwordChangeService() {
public PasswordManagementService passwordChangeService(RestTemplateBuilder restTemplateBuilder) {
PasswordManagementProperties pm = casProperties.getAuthn().getPm();
String username = pm.getRest().getEndpointUsername();
String password = pm.getRest().getEndpointPassword();

if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
restTemplateBuilder = restTemplateBuilder
.basicAuthentication(username, password);
}

return new RestPasswordManagementService(passwordManagementCipherExecutor.getIfAvailable(),
casProperties.getServer().getPrefix(),
new RestTemplate(),
casProperties.getAuthn().getPm());
casProperties.getServer().getPrefix(),
restTemplateBuilder.build(),
pm);
}
}