Skip to content

Commit

Permalink
Merge pull request #879 from RADAR-base/update-login-url
Browse files Browse the repository at this point in the history
Fetch kratos login url from backend
  • Loading branch information
mpgxvii authored Jul 4, 2024
2 parents 3f493a6 + c698737 commit 6086eb2
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 24 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ RUN curl -sL https://deb.nodesource.com/setup_16.x | bash \
WORKDIR /code

ENV GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.project.prod=true -Dorg.gradle.vfs.watch=false"
ARG KRATOS_URL

COPY package.json yarn.lock .yarnrc.yml /code/
COPY .yarn /code/.yarn
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ micrometer_version=1.12.3
hibernate_orm_version=6.4.4.Final
hibernate_validator_version=8.0.0.Final
testcontainers_version=1.19.7
undertow_version=2.2.32.Final
undertow_version=2.2.33.Final

kotlin.code.style=official
org.gradle.vfs.watch=true
Expand Down
14 changes: 0 additions & 14 deletions gradle/profile_prod.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,7 @@ bootRun {
systemProperty "spring.profiles.active", profiles
}

task setEnvVars {
doLast {
def kratosUrl = System.getenv('KRATOS_URL')
def envProdFileContent = """
export const environment = {
production: true,
KRATOS_URL: '${kratosUrl}'
};
"""
file('src/main/webapp/environments/environment.prod.ts').text = envProdFileContent
}
}

task webpack(type: YarnTask, dependsOn: 'yarn_install') {
dependsOn setEnvVars
args = ["build:prod"]
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/docker/managementportal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ services:
build:
context: ../../../
dockerfile: ./Dockerfile
args:
- KRATOS_URL=http://localhost:3000
environment:
- SPRING_PROFILES_ACTIVE=prod,api-docs
- SPRING_DATASOURCE_URL=jdbc:postgresql://managementportal-postgresql:5432/managementportal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ public void setRequireAal2(Boolean requireAal2) {

public static class IdentityServer {
private String serverUrl = null;

private String serverAdminUrl = null;
private String adminEmail = null;
private String loginUrl = null;

public String getServerUrl() {
return serverUrl;
Expand Down Expand Up @@ -314,6 +314,14 @@ public String getServerAdminUrl() {
public void setServerAdminUrl(String serverAdminUrl) {
this.serverAdminUrl = serverAdminUrl;
}

public String getLoginUrl() {
return loginUrl;
}

public void setLoginUrl(String loginUrl) {
this.loginUrl = loginUrl;
}
}

public static class CatalogueServer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class OAuth2ServerConfiguration(
.skipUrlPattern(HttpMethod.POST, "/oauth/token")
.skipUrlPattern(HttpMethod.GET, "/api/meta-token/*")
.skipUrlPattern(HttpMethod.GET, "/api/sitesettings")
.skipUrlPattern(HttpMethod.GET, "/api/redirect/login")
.skipUrlPattern(HttpMethod.GET, "/api/redirect/account")
.skipUrlPattern(HttpMethod.GET, "/api/logout-url")
.skipUrlPattern(HttpMethod.GET, "/oauth2/authorize")
.skipUrlPattern(HttpMethod.GET, "/images/**")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SecurityConfiguration
.antMatchers("/api/logout-url")
.antMatchers("/api/profile-info")
.antMatchers("/api/activate")
.antMatchers("/api/redirect/**")
.antMatchers("/api/account/reset_password/init")
.antMatchers("/api/account/reset_password/finish")
.antMatchers("/test/**")
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/radarbase/management/web/rest/LoginEndpoint.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.radarbase.management.web.rest

import org.radarbase.management.config.ManagementPortalProperties
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.view.RedirectView

@RestController
@RequestMapping("/api")
class LoginEndpoint
@Autowired
constructor(
@Autowired private val managementPortalProperties: ManagementPortalProperties,
) {
@GetMapping("/redirect/login")
fun loginRedirect(): RedirectView {
val redirectView = RedirectView()
redirectView.url = managementPortalProperties.identityServer.loginUrl +
"/login?return_to=" + managementPortalProperties.common.managementPortalBaseUrl
return redirectView
}

@GetMapping("/redirect/account")
fun settingsRedirect(): RedirectView {
val redirectView = RedirectView()
redirectView.url = managementPortalProperties.identityServer.loginUrl + "/settings"
return redirectView
}

companion object {
private val logger = LoggerFactory.getLogger(TokenKeyEndpoint::class.java)
}
}
1 change: 1 addition & 0 deletions src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ managementportal:
identityServer:
serverUrl: http://localhost:4433
serverAdminUrl: http://localhost:4434
loginUrl: http://localhost:3000

# ===================================================================
# JHipster specific properties
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ managementportal:
adminEmail: bdegraaf1234@gmail.com
serverUrl: https://radar-k3s-test.thehyve.net/kratos
serverAdminUrl: http://kratos-admin
loginUrl: http://localhost:3000

# ===================================================================
# JHipster specific properties
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ managementportal:
keyStorePassword: radarbase
signingKeyAlias: radarbase-managementportal-ec
enablePublicKeyVerifiers: false
requireAal2: false
siteSettings:
hiddenSubjectFields: [ ]

Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class HomeComponent {
modalRef: NgbModalRef;
// projects: Project[];
subscriptions: Subscription;
private loginUrl = 'oauth/login';

constructor(
public principal: Principal,
Expand Down Expand Up @@ -63,6 +64,6 @@ export class HomeComponent {
}

login() {
window.location.href = environment.KRATOS_URL + `/login?return_to=${window.location.href}`;
window.location.href = this.loginUrl
}
}
5 changes: 3 additions & 2 deletions src/main/webapp/app/layouts/error/error.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ErrorComponent implements OnInit, OnDestroy {
error403: boolean;
modalRef: NgbModalRef;
private routeSubscription: Subscription;
private loginUrl = 'oauth/login';

constructor(
private loginModalService: LoginModalService,
Expand All @@ -34,6 +35,6 @@ export class ErrorComponent implements OnInit, OnDestroy {
}

login() {
window.location.href = environment.KRATOS_URL + `/login?return_to=${window.location.href}`;
window.location.href = this.loginUrl;
}
}
}
7 changes: 5 additions & 2 deletions src/main/webapp/app/layouts/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class NavbarComponent {
projects: Project[];
organizations: Organization[];

private loginUrl = 'oauth/login';
private settingsUrl = 'oauth/settings';

constructor(
private loginService: LoginService,
public languageHelper: JhiLanguageHelper,
Expand Down Expand Up @@ -65,7 +68,7 @@ export class NavbarComponent {
}

login() {
window.location.href = environment.KRATOS_URL + `/login?return_to=${window.location.href}`;
window.location.href = this.loginUrl;
}

logout() {
Expand All @@ -79,6 +82,6 @@ export class NavbarComponent {
}

redirectToProfile() {
window.location.href = environment.KRATOS_URL + '/settings';
window.location.href = this.settingsUrl;
}
}

0 comments on commit 6086eb2

Please sign in to comment.