Skip to content

Commit

Permalink
filter implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdurin committed Dec 21, 2023
1 parent 364c8a0 commit e207326
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public String loginPage(@RequestParam Map<String, String> allRequestParams, Mode
mdl.addAttribute("passwordExpired", expired);
boolean invalidCredentials = "invalid_credentials".equals(allRequestParams.get("error"));
mdl.addAttribute("invalidCredentials", invalidCredentials);
boolean duplicateAccount = "duplicate_account".equals(allRequestParams.get("error"));
mdl.addAttribute("duplicateAccount", duplicateAccount);
return "login";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import java.net.URI;
import java.util.Optional;
import java.util.function.Function;

/**
* A {@link GlobalFilter} that resolves the {@link GeorchestraUser} from the
Expand All @@ -64,7 +65,7 @@ public class ResolveGeorchestraUserGlobalFilter implements GlobalFilter, Ordered

private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy();

private static String EXPIRED_PASSWORD = "expired_password";
private static String DUPLICATE_ACCOUNT = "duplicate_account";

/**
* @return a lower precedence than {@link RouteToRequestUrlFilter}'s, in order
Expand All @@ -82,7 +83,6 @@ public class ResolveGeorchestraUserGlobalFilter implements GlobalFilter, Ordered
* chain.
*/
public @Override Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

Mono<Void> res = exchange.getPrincipal()//
.doOnNext(p -> log.debug("resolving user from {}", p.getClass().getName()))//
.filter(Authentication.class::isInstance)//
Expand All @@ -91,27 +91,31 @@ public class ResolveGeorchestraUserGlobalFilter implements GlobalFilter, Ordered
try {
return resolver.resolve(auth);
} catch (DuplicatedEmailFoundException exp) {
GeorchestraUser user = new GeorchestraUser();
user.setId("0");
return Optional.of(user);
Optional<GeorchestraUser> op = Optional.empty();
return op;
}
})//
.filter(user -> !((GeorchestraUser) user.get()).getId().equals("0")).map(user -> {
.map(user -> {
if (user.isEmpty()) {
return this.redirectStrategy.sendRedirect(exchange, URI
.create("https://georchestra-127-0-1-1.traefik.me/login?error=" + DUPLICATE_ACCOUNT));
}

GeorchestraUser usr = user.orElse(null);
GeorchestraUsers.store(exchange, usr);
if (usr != null && usr instanceof ExtendedGeorchestraUser) {
ExtendedGeorchestraUser eu = (ExtendedGeorchestraUser) usr;
Organization org = eu.getOrg();
GeorchestraOrganizations.store(exchange, org);
}
return exchange;
return chain.filter(exchange);
})//
.defaultIfEmpty(exchange)//
.flatMap(chain::filter);
.defaultIfEmpty(chain.filter(exchange))//
.flatMap(Function.identity());

System.out.println(res);
return res;
return this.redirectStrategy.sendRedirect(exchange, URI.create("login?error=" + EXPIRED_PASSWORD));
// return this.redirectStrategy.sendRedirect(exchange, URI.create("login?error=" + DUPLICATE_ACCOUNT));
}

}
3 changes: 2 additions & 1 deletion gateway/src/main/resources/messages/login.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ forget_password = Forgot password ?
identity_provider_title = Log in with an identity provider
expired_password = Your password has been expired
expired_password_link = and should be changed
invalid_credentials = Invalid username or password
invalid_credentials = Invalid username or password
duplicate_account = An account already exists using this email address
3 changes: 2 additions & 1 deletion gateway/src/main/resources/messages/login_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ forget_password = Passwort vergessen?
identity_provider_title = Melden Sie sich bei einem Identitätsanbieter an
expired_password = Ihr Passwort ist abgelaufen
expired_password_link = und sollte geändert werden
invalid_credentials = Ungültiger Benutzername oder Passwort
invalid_credentials = Ungültiger Benutzername oder Passwort
duplicate_account = An account already exists using this email address
3 changes: 2 additions & 1 deletion gateway/src/main/resources/messages/login_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ forget_password = Forgot password ?
identity_provider_title = Log in with an identity provider
expired_password = Your password has been expired
expired_password_link = and should be changed
invalid_credentials = Invalid username or password
invalid_credentials = Invalid username or password
duplicate_account = An account already exists using this email address
3 changes: 2 additions & 1 deletion gateway/src/main/resources/messages/login_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ forget_password = Contraseña olvidada ?
identity_provider_title = Iniciar sesión con un proveedor de identidad
expired_password = Su contraseña ha caducado
expired_password_link = y debería ser cambiado
invalid_credentials = Nombre de usuario o contraseña invalido
invalid_credentials = Nombre de usuario o contraseña invalido
duplicate_account = An account already exists using this email address
3 changes: 2 additions & 1 deletion gateway/src/main/resources/messages/login_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ forget_password = Mot de passe oublié ?
identity_provider_title = Se connecter depuis un fournisseur d'identité
expired_password = Votre mot de passe a expiré
expired_password_link = et doit être changé
invalid_credentials = Nom d'utilisateur ou mot de passe non valide
invalid_credentials = Nom d'utilisateur ou mot de passe non valide
duplicate_account = An account already exists using this email address
3 changes: 2 additions & 1 deletion gateway/src/main/resources/messages/login_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ forget_password = Wachtwoord vergeten ?
identity_provider_title = Log in met een identiteitsprovider
expired_password = Uw wachtwoord is verlopen
expired_password_link = en moet worden veranderd
invalid_credentials = ongeldige gebruikersnaam of wachtwoord
invalid_credentials = ongeldige gebruikersnaam of wachtwoord
duplicate_account = An account already exists using this email address
3 changes: 2 additions & 1 deletion gateway/src/main/resources/messages/login_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ forget_password = Забыли пароль ?
identity_provider_title = Войдите в систему с помощью поставщика удостоверений
expired_password = Срок действия вашего пароля истек,
expired_password_link = и следует изменить
invalid_credentials = неправильное имя пользователя или пароль
invalid_credentials = неправильное имя пользователя или пароль
duplicate_account = An account already exists using this email address
3 changes: 2 additions & 1 deletion gateway/src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ <h2 class="form-signin-heading"><span th:text="#{login_message_title}"></span></
<div style="text-align: center; font-size: 18px; color: #ff0033;" th:if="${passwordExpired}"> <span th:text="#{expired_password}" ></span>
<a href="/console/account/passwordRecovery" > <span th:text="#{expired_password_link}" ></span> </a>
</div>
<div style="text-align: center; font-size: 18px; color: #ff0033;" th:if="${duplicateAccount}"> <span th:text="#{duplicate_account}"></span> </div>
</div>
</form>
</form>~
<div th:if="${oauth2LoginLinks.size() != 0}" class="container"><h2 class="form-signin-heading">Login with OAuth 2.0</h2>
<table class="table table-striped">
<tr th:each="oauth2Client : ${oauth2LoginLinks}">
Expand Down

0 comments on commit e207326

Please sign in to comment.