Skip to content

Commit 8112e62

Browse files
committed
SAML: refactor property names into constants
1 parent 9771362 commit 8112e62

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/main/java/eu/openanalytics/containerproxy/auth/impl/SAMLAuthenticationBackend.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
public class SAMLAuthenticationBackend implements IAuthenticationBackend {
4343

4444
public static final String NAME = "saml";
45+
46+
private static final String PROP_LOGOUT_URL = "proxy.saml.logout-url";
4547

4648
@Autowired(required = false)
4749
private SAMLEntryPoint samlEntryPoint;
@@ -88,15 +90,15 @@ public void configureAuthenticationManagerBuilder(AuthenticationManagerBuilder a
8890

8991
@Override
9092
public String getLogoutURL() {
91-
if (environment.getProperty("proxy.saml.logout-url") != null) {
93+
if (environment.getProperty(PROP_LOGOUT_URL) != null) {
9294
return "/logout";
9395
}
9496
return "/saml/logout";
9597
}
9698

9799
@Override
98100
public String getLogoutSuccessURL() {
99-
String logoutURL = environment.getProperty("proxy.saml.logout-url");
101+
String logoutURL = environment.getProperty(PROP_LOGOUT_URL);
100102
System.out.println("LogoutURL: " + logoutURL);
101103
if (logoutURL == null || logoutURL.trim().isEmpty()) logoutURL = "/";
102104
return logoutURL;

src/main/java/eu/openanalytics/containerproxy/auth/impl/saml/SAMLConfiguration.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@
9393
public class SAMLConfiguration {
9494

9595
private static final String DEFAULT_NAME_ATTRIBUTE = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress";
96-
96+
97+
private static final String PROP_LOG_ATTRIBUTES = "proxy.saml.log-attributes";
98+
private static final String PROP_FORCE_AUTHN = "proxy.saml.force-authn";
99+
private static final String PROP_KEYSTORE = "proxy.saml.keystore";
100+
private static final String PROP_ENCRYPTION_CERT_NAME = "proxy.saml.encryption-cert-name";
101+
private static final String PROP_ENCRYPTION_CERT_PASSWORD = "proxy.saml.encryption-cert-password";
102+
private static final String PROP_ENCRYPTION_KEYSTORE_PASSWORD = "proxy.saml.keystore-password";
103+
private static final String PROP_APP_ENTITY_ID = "proxy.saml.app-entity-id";
104+
private static final String PROP_BASE_URL = "proxy.saml.app-base-url";
105+
private static final String PROP_METADATA_URL = "proxy.saml.idp-metadata-url";
106+
97107
@Inject
98108
private Environment environment;
99109

@@ -152,7 +162,7 @@ public SimpleUrlLogoutSuccessHandler successLogoutHandler() {
152162
public WebSSOProfileOptions defaultWebSSOProfileOptions() {
153163
WebSSOProfileOptions webSSOProfileOptions = new WebSSOProfileOptions();
154164
webSSOProfileOptions.setIncludeScoping(false);
155-
webSSOProfileOptions.setForceAuthN(Boolean.valueOf(environment.getProperty("proxy.saml.force-authn", "false")));
165+
webSSOProfileOptions.setForceAuthN(Boolean.valueOf(environment.getProperty(PROP_FORCE_AUTHN, "false")));
156166
return webSSOProfileOptions;
157167
}
158168

@@ -168,13 +178,13 @@ public WebSSOProfile webSSOprofile() {
168178

169179
@Bean
170180
public KeyManager keyManager() {
171-
String keystore = environment.getProperty("proxy.saml.keystore");
181+
String keystore = environment.getProperty(PROP_KEYSTORE);
172182
if (keystore == null || keystore.isEmpty()) {
173183
return new EmptyKeyManager();
174184
} else {
175-
String certName = environment.getProperty("proxy.saml.encryption-cert-name");
176-
String certPW = environment.getProperty("proxy.saml.encryption-cert-password");
177-
String keystorePW = environment.getProperty("proxy.saml.keystore-password", certPW);
185+
String certName = environment.getProperty(PROP_ENCRYPTION_CERT_NAME);
186+
String certPW = environment.getProperty(PROP_ENCRYPTION_CERT_PASSWORD);
187+
String keystorePW = environment.getProperty(PROP_ENCRYPTION_KEYSTORE_PASSWORD, certPW);
178188

179189
Resource keystoreFile = new FileSystemResource(keystore);
180190
Map<String, String> passwords = new HashMap<>();
@@ -238,8 +248,8 @@ public MetadataDisplayFilter metadataDisplayFilter() throws MetadataProviderExce
238248

239249
@Bean
240250
public MetadataGenerator metadataGenerator() {
241-
String appEntityId = environment.getProperty("proxy.saml.app-entity-id");
242-
String appBaseURL = environment.getProperty("proxy.saml.app-base-url");
251+
String appEntityId = environment.getProperty(PROP_APP_ENTITY_ID);
252+
String appBaseURL = environment.getProperty(PROP_BASE_URL);
243253

244254
MetadataGenerator metadataGenerator = new MetadataGenerator();
245255
metadataGenerator.setEntityId(appEntityId);
@@ -260,7 +270,7 @@ public ExtendedMetadata extendedMetadata() {
260270

261271
@Bean
262272
public ExtendedMetadataDelegate idpMetadata() throws MetadataProviderException, ResourceException {
263-
String metadataURL = environment.getProperty("proxy.saml.idp-metadata-url");
273+
String metadataURL = environment.getProperty(PROP_METADATA_URL);
264274

265275
Timer backgroundTaskTimer = new Timer(true);
266276
HTTPMetadataProvider httpMetadataProvider = new HTTPMetadataProvider(backgroundTaskTimer, new HttpClient(), metadataURL); httpMetadataProvider.setParserPool(parserPool());
@@ -342,7 +352,7 @@ public SAMLAuthenticationProvider samlAuthenticationProvider() {
342352
public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException {
343353
List<Attribute> attributes = credential.getAttributes();
344354

345-
if (Boolean.parseBoolean(environment.getProperty("proxy.saml.log-attributes", "false"))) {
355+
if (Boolean.parseBoolean(environment.getProperty(PROP_LOG_ATTRIBUTES, "false"))) {
346356
// don't use nameValue from below so that in the case this attribute isn't correctly setup,
347357
// we can still log the attribtues (and the correct attribute can be found)
348358
String userID = credential.getNameID().getValue();

0 commit comments

Comments
 (0)