Skip to content

Commit

Permalink
added property shiny.proxy.authentication (value: ldap or none)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmichielssen committed Jun 7, 2016
1 parent a1612d6 commit 5149e7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/eu/openanalytics/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void configure(HttpSecurity http) throws Exception {
.frameOptions()
.sameOrigin();

if (environment.getProperty("shiny.proxy.ldap.url") != null) {
if (hasAuth(environment)) {
http.authorizeRequests().antMatchers("/login").permitAll();
for (ShinyApp app: appService.getApps()) {
http.authorizeRequests().antMatchers("/app/" + app.getName()).hasAnyRole(appService.getAppRoles(app.getName()));
Expand All @@ -96,6 +96,11 @@ protected void configure(HttpSecurity http) throws Exception {
}
}

private static boolean hasAuth(Environment env) {
String auth = env.getProperty("shiny.proxy.authentication", "").toLowerCase();
return (!auth.isEmpty() && !auth.equals("none"));
}

@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {

Expand All @@ -104,8 +109,7 @@ protected static class AuthenticationConfiguration extends GlobalAuthenticationC

@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
String ldapUrl = environment.getProperty("shiny.proxy.ldap.url");
if (ldapUrl == null) return;
if (!hasAuth(environment)) return;

String[] userDnPatterns = { environment.getProperty("shiny.proxy.ldap.user-dn-pattern") };
if (userDnPatterns[0] == null || userDnPatterns[0].isEmpty()) userDnPatterns = new String[0];
Expand All @@ -114,6 +118,7 @@ public void init(AuthenticationManagerBuilder auth) throws Exception {
if (managerDn != null && managerDn.isEmpty()) managerDn = null;

// Manually instantiate contextSource so it can be passed into authoritiesPopulator below.
String ldapUrl = environment.getProperty("shiny.proxy.ldap.url");
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(ldapUrl);
if (managerDn != null) {
contextSource.setUserDn(managerDn);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ shiny:
logo-url: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png
landing-page: /
port: 8080
authentication: ldap
# LDAP configuration
ldap:
url: ldap://ldap.forumsys.com:389/dc=example,dc=com
Expand Down

0 comments on commit 5149e7e

Please sign in to comment.