Skip to content

Commit

Permalink
Frontend location logikk håndteres litt anderledes
Browse files Browse the repository at this point in the history
  • Loading branch information
larsLotNav committed Apr 27, 2022
1 parent 32e8489 commit a0700c6
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion nais.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
- secret: nav-status-db-pass
env:
- name: FRONTEND_LOCATION
value: https://portal.labs.nais.io
value: https://status.nav.no
secureLogs:
enabled: true
image: {{ image }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
public class CORSFilter implements Filter {


private boolean isLocal;
private String frontendLocation;


/**
* Default constructor.
* @param isLocal
*/
public CORSFilter() {
}

Expand All @@ -44,7 +41,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo

// Authorize (allow) all domains to consume the content
//TODO hvordan skal dette håndteres? Dersom frontend og backend hostes på samme server trenger ikke
String frontendUrl = isLocal? "localhost" : "portal.labs.nais.io";

((HttpServletResponse) servletResponse).addHeader("Access-Control-Allow-Origin", "*");
((HttpServletResponse) servletResponse).addHeader("Access-Control-Allow-Methods","GET, OPTIONS, HEAD, PUT, POST, DELETE");
((HttpServletResponse) servletResponse).addHeader("Access-Control-Allow-Headers", "*");
Expand All @@ -70,7 +67,7 @@ public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}

public void setIsLocal(boolean isLocal) {
this.isLocal = isLocal;
public void setFrontendLocation(String frontendLocation) {
this.frontendLocation = frontendLocation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class OpenIdConnectAuthentication implements Authentication.Deferred {
private static URL openIdConfiguration;
private static String clientId = System.getenv("AZURE_APP_CLIENT_ID");
private static String clientSecret = System.getenv("AZURE_APP_CLIENT_SECRET");
private static String frontEndUrl = System.getenv("FRONTEND_LOCATION");
private String frontEndUrl;

private int COOKIE_SESSION_TIMEOUT_DURATION_IN_WEEKS = 60*60*24*7;

Expand All @@ -59,6 +59,10 @@ public class OpenIdConnectAuthentication implements Authentication.Deferred {
}
}

public void setFrontendLocation(String frontEndLocation){
this.frontEndUrl = frontEndLocation;
}



@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class LogInnApi extends ClasspathWebAppContext {

private final Authentication authentication = new OpenIdConnectAuthentication();
private final OpenIdConnectAuthentication authentication = new OpenIdConnectAuthentication();

private final CORSFilter corsFilter;

Expand All @@ -29,8 +29,9 @@ public LogInnApi(String context) {
addFilter(new FilterHolder( new AuthenticationFilter(authentication)), "/*", EnumSet.of(DispatcherType.REQUEST));
}

public void setIsLocal(boolean isLocal) {
corsFilter.setIsLocal(isLocal);
public void setFrontEndLocation(String frontEndLocation){
corsFilter.setFrontendLocation(frontEndLocation);
authentication.setFrontendLocation(frontEndLocation);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void setDataSource(DataSource dataSource) {
filter.setDataSource(dataSource);
}

public void setIsLocal(boolean isLocal) {
corsFilter.setIsLocal(isLocal);
public void setFrontEndLocation(String frontEndLocation){
corsFilter.setFrontendLocation(frontEndLocation);
}
}
12 changes: 5 additions & 7 deletions portal-server/src/main/java/no/nav/server/PortalServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class PortalServer {
private final PortalPoller portalPoller = new PortalPoller();
private final JobScheduler jobScheduler = new JobScheduler();
private final SwaggerDocumentation swaggerDocumentation = new SwaggerDocumentation("/doc");
private Boolean isLocal = false;

public PortalServer() {
HttpConfiguration config = new HttpConfiguration();
Expand All @@ -55,7 +54,6 @@ private void setupConfiguration() {
new ConfigObserver("portal")
.onPrefixedValue("dataSource", DataSourceTransformer::create, this::setDataSource)
.onInetSocketAddress("http.port", port, this::setHttpPort)
.onStringValue("isLocal", "false", this::setIsLocal)
/*Når man legger inn autentisering med OIDC for Profil / Admin så er det ca slik. Se denne commit for hvordan det funket for rest før
.onStringValue("openid.discovery_url", null, brukergrupperRestApi::setOpenIdConfiguration)
.onStringValue("openid.client_id", null, brukergrupperRestApi::setClientId)
Expand All @@ -64,11 +62,11 @@ private void setupConfiguration() {
;
}

private void setIsLocal(String isLocal) {
boolean isLocalBool= Boolean.parseBoolean(isLocal);
this.isLocal = isLocalBool;
logInnApi.setIsLocal(isLocalBool);
portalRestApi.setIsLocal(isLocalBool);
private void setFrontEndLocation(){
//TODO lage denne smartere
String frontEndLocation = System.getenv("FRONTEND_LOCATION");
logInnApi.setFrontEndLocation(frontEndLocation);
portalRestApi.setFrontEndLocation(frontEndLocation);
}

private void setDataSource(DataSource dataSource) {
Expand Down
5 changes: 5 additions & 0 deletions portal.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ dataSource.username = postgres
dataSource.driverClassName= org.postgresql.Driver
dataSource.maximumPoolSize=32
dataSource.passwordName=dbpass


frontendLocationLocal = http://localhost:3000
frontendLocationDevelop = https://portal.labs.nais.io
frontendLocationProduction = https://status.nav.no

0 comments on commit a0700c6

Please sign in to comment.