Skip to content
Snippets Groups Projects
Commit efeadd2e authored by ThanKarab's avatar ThanKarab
Browse files

curl added in new docker image.

parent 6cdc1473
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ ENV TZ=Etc/GMT ...@@ -27,7 +27,7 @@ ENV TZ=Etc/GMT
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
####################################################### #######################################################
# Setting up env variables and workdir # Setting up environment
####################################################### #######################################################
ENV APP_CONFIG_TEMPLATE="/opt/config/application.tmpl" ENV APP_CONFIG_TEMPLATE="/opt/config/application.tmpl"
ENV APP_CONFIG_LOCATION="/opt/config/application.yml" ENV APP_CONFIG_LOCATION="/opt/config/application.yml"
...@@ -35,6 +35,7 @@ ENV SPRING_CONFIG_LOCATION="file:/opt/config/application.yml" ...@@ -35,6 +35,7 @@ ENV SPRING_CONFIG_LOCATION="file:/opt/config/application.yml"
WORKDIR /opt WORKDIR /opt
RUN apk add --no-cache curl
####################################################### #######################################################
# Install dockerize # Install dockerize
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
To run the backend using an IDE for development, such as IntelliJ, you need a running instance of PostgreSQL. To run the backend using an IDE for development, such as IntelliJ, you need a running instance of PostgreSQL.
## Deployment (using a Docker image) ## Deployment (using a Docker image)
Build the image: `docker build -t hbpmip/portal-backend:latest .` Build the image: `docker build -t hbpmip/portal-backend:testing .`
To use this image, you need a running instance of PostgreSQL and to configure the software using the following environment variables. To use this image, you need a running instance of PostgreSQL and to configure the software using the following environment variables.
......
package eu.hbp.mip.configurations;
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class KeycloakConfiguration {
@Bean
public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
}
package eu.hbp.mip.configurations; package eu.hbp.mip.configurations;public class SecurityConfiguration {
import eu.hbp.mip.utils.CORSFilter;
import org.keycloak.adapters.springsecurity.KeycloakConfiguration;
import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider;
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.access.channel.ChannelProcessingFilter;
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.WebUtils;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Controller
@KeycloakConfiguration
public class SecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter {
// Upon logout, redirect to login page url
private static final String logoutRedirectURL = "/sso/login";
private final HttpServletRequest request;
@Value("#{'${authentication.enabled}'}")
private boolean authenticationEnabled;
public SecurityConfiguration(HttpServletRequest request) {
this.request = request;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
if (authenticationEnabled) {
http.authorizeRequests()
.antMatchers(
"/sso/login", "/actuator/**"
).permitAll()
.antMatchers("/**").authenticated()
.and().csrf().ignoringAntMatchers("/logout").csrfTokenRepository(csrfTokenRepository())
.and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);
} else {
http.addFilterBefore(new CORSFilter(), ChannelProcessingFilter.class);
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/**").permitAll()
.and().csrf().disable();
}
}
private Filter csrfHeaderFilter() {
return new OncePerRequestFilter() {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
if (csrf != null) {
Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
String token = csrf.getToken();
if (cookie == null || token != null && !token.equals(cookie.getValue())) {
cookie = new Cookie("XSRF-TOKEN", token);
cookie.setPath("/");
response.addCookie(cookie);
}
}
filterChain.doFilter(request, response);
}
};
}
private CsrfTokenRepository csrfTokenRepository() {
HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
repository.setHeaderName("X-XSRF-TOKEN");
return repository;
}
@GetMapping(value = "/logout")
public String logout() throws ServletException {
request.logout();
return String.format("redirect:%s", logoutRedirectURL);
}
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
SimpleAuthorityMapper grantedAuthorityMapper = new SimpleAuthorityMapper();
grantedAuthorityMapper.setConvertToUpperCase(true);
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(grantedAuthorityMapper);
auth.authenticationProvider(keycloakAuthenticationProvider);
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment