-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from IDSIA/dev
Version 1.6
- Loading branch information
Showing
19 changed files
with
288 additions
and
49 deletions.
There are no files selected for viewing
Binary file modified
BIN
+1.03 KB
(100%)
AdapQuestBackend/data/templates/adaptive.questionnaire.template.xlsx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
AdapQuestBackend/src/main/java/ch/idsia/adaptive/backend/config/ActiveRoutesInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ch.idsia.adaptive.backend.config; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class ActiveRoutesInterceptor implements HandlerInterceptor { | ||
private static final Logger logger = LoggerFactory.getLogger(ActiveRoutesInterceptor.class); | ||
|
||
@Value("${adapquest.controller.assistant}") | ||
private boolean assistant = true; | ||
@Value("${adapquest.controller.console}") | ||
private boolean console = true; | ||
@Value("${adapquest.controller.dashboard}") | ||
private boolean dashboard = true; | ||
@Value("${adapquest.controller.demo}") | ||
private boolean demo = true; | ||
@Value("${adapquest.controller.experiments}") | ||
private boolean experiments = true; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
final String path = request.getServletPath(); | ||
|
||
if (path.contains("/assistant")) | ||
return assistant; | ||
if (path.contains("/console")) | ||
return console; | ||
if (path.contains("/dashboard")) | ||
return dashboard; | ||
if (path.contains("/demo")) | ||
return demo; | ||
if (path.contains("/experiments")) | ||
return experiments; | ||
|
||
return HandlerInterceptor.super.preHandle(request, response, handler); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
AdapQuestBackend/src/main/java/ch/idsia/adaptive/backend/config/KeycloakConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ch.idsia.adaptive.backend.config; | ||
|
||
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnProperty(name = "keycloak.enabled", havingValue = "true") | ||
public class KeycloakConfig { | ||
|
||
@Bean | ||
public KeycloakSpringBootConfigResolver keycloakConfigResolver() { | ||
return new KeycloakSpringBootConfigResolver(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
AdapQuestBackend/src/main/java/ch/idsia/adaptive/backend/config/SecurityKeycloakConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ch.idsia.adaptive.backend.config; | ||
|
||
import org.keycloak.adapters.springsecurity.KeycloakConfiguration; | ||
import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider; | ||
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper; | ||
import org.springframework.security.core.session.SessionRegistryImpl; | ||
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy; | ||
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; | ||
|
||
@KeycloakConfiguration | ||
@AutoConfigureAfter(SecurityConfig.class) | ||
@ConditionalOnProperty(name = "keycloak.enabled", havingValue = "true") | ||
class SecurityKeycloakConfig extends KeycloakWebSecurityConfigurerAdapter { | ||
private static final Logger logger = LoggerFactory.getLogger(SecurityKeycloakConfig.class); | ||
|
||
@Value("${adapquest.keycloak.role}") | ||
private String role = "user"; | ||
|
||
@Value("${adapquest.keycloak.admin}") | ||
private String admin = "admin"; | ||
|
||
@Autowired | ||
public void configureGlobal(AuthenticationManagerBuilder auth) { | ||
final SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper(); | ||
simpleAuthorityMapper.setPrefix("ROLE_"); | ||
simpleAuthorityMapper.setConvertToUpperCase(true); | ||
|
||
final KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider(); | ||
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(simpleAuthorityMapper); | ||
auth.authenticationProvider(keycloakAuthenticationProvider); | ||
} | ||
|
||
@Bean | ||
@Override | ||
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { | ||
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl()); | ||
} | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
super.configure(http); | ||
http.authorizeRequests() | ||
.antMatchers("/", "/css/**", "/webjars/**", "/img/**").permitAll() | ||
.and() | ||
.authorizeRequests() | ||
.antMatchers("/demo**", "/survey**").hasRole(role) | ||
.antMatchers("/console*").hasRole(admin) | ||
.anyRequest() | ||
.authenticated(); | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.