Skip to content

Commit

Permalink
Incorporate changes from refactoring of portal-core
Browse files Browse the repository at this point in the history
  • Loading branch information
cuioss committed Aug 29, 2024
1 parent d0af491 commit 130c744
Show file tree
Hide file tree
Showing 41 changed files with 236 additions and 321 deletions.
5 changes: 0 additions & 5 deletions modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>de.cuioss.portal.configuration</groupId>
<artifactId>portal-configuration-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit5</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions modules/portal-ui-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</dependency>
<!-- Portal Core -->
<dependency>
<groupId>de.cuioss.portal.configuration</groupId>
<artifactId>portal-configuration-api</artifactId>
<groupId>de.cuioss.portal.core</groupId>
<artifactId>portal-configuration</artifactId>
</dependency>
<dependency>
<groupId>de.cuioss.portal.authentication</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
*/
package de.cuioss.portal.ui.api.menu.items;

import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;

import de.cuioss.jsf.api.components.model.menu.NavigationMenuItemContainerImpl;

import jakarta.annotation.PostConstruct;
import de.cuioss.portal.authentication.AuthenticatedUserInfo;
import de.cuioss.portal.authentication.PortalUser;
import de.cuioss.portal.common.bundle.ResourceBundleWrapper;
import de.cuioss.portal.ui.api.menu.PortalMenuItem;
import de.cuioss.portal.ui.api.menu.PortalNavigationMenuItemContainerImpl;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import lombok.EqualsAndHashCode;
import lombok.ToString;

Expand Down Expand Up @@ -56,11 +53,10 @@ public class UserMenuItem extends PortalNavigationMenuItemContainerImpl {
/** The icon for the user. */
public static final String ICON = "cui-icon-user";

/** The string based id for this menu item. */
/** The string-based id for this menu item. */
public static final String MENU_ID = "userMenuItem";

@Inject
@PortalUser
AuthenticatedUserInfo userInfo;

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static org.junit.jupiter.api.Assertions.*;

@EnableAutoWeld
@AddBeanClasses({ JsfObjectsProducer.class })
@AddBeanClasses({JsfObjectsProducer.class})
@EnableJsfEnvironment
@EnablePortalConfiguration
class PortalNavigationMenuItemImplBaseTest {
Expand Down Expand Up @@ -68,8 +68,8 @@ void shouldHandleMissingConfigurationGracefully() {

@Test
void shouldHandleConfiguration() {
configuration.fireEvent(ENABLED, "true", ORDER, DEFAULT_ORDER.toString());
configuration.fireEvent(PARENT, DEFAULT_PARENT);
configuration.update(ENABLED, "true", ORDER, DEFAULT_ORDER.toString());
configuration.update(PARENT, DEFAULT_PARENT);

underTest = underTestProvider.get();
assertEquals(DEFAULT_PARENT, underTest.getParentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void shouldHandleMissingServletRequest() {

@Test
void shouldNotRedirectIfNotConfigured() {
configuration.fireEvent(PortalConfigurationKeys.PAGES_ERROR_404_REDIRECT, "false");
configuration.update(PortalConfigurationKeys.PAGES_ERROR_404_REDIRECT, "false");

getRequestConfigDecorator().setViewId(FACES_VIEW_JSF).setRequestAttribute(AbstractHttpErrorPage.JAKARTA_SERVLET_ERROR_REQUEST_URI,
FACES_VIEW_JSF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import de.cuioss.jsf.api.application.message.MessageProducer;
import de.cuioss.jsf.api.servlet.ServletAdapterUtil;
import de.cuioss.portal.authentication.AuthenticatedUserInfo;
import de.cuioss.portal.authentication.PortalUser;
import de.cuioss.portal.authentication.facade.FormBasedAuthenticationFacade;
import de.cuioss.portal.authentication.facade.PortalAuthenticationFacade;
import de.cuioss.portal.authentication.model.UserStore;
Expand Down Expand Up @@ -106,7 +105,6 @@ public class LoginPageBean extends AbstractLoginPageBean implements LoginPage {
DisplayNameMessageProducer displayNameMessageProducer;

@Inject
@PortalUser
AuthenticatedUserInfo userInfo;

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import de.cuioss.portal.authentication.AuthenticatedUserInfo;
import de.cuioss.portal.authentication.LoginEvent;
import de.cuioss.portal.authentication.PortalLoginEvent;
import de.cuioss.portal.authentication.PortalUser;
import de.cuioss.portal.authentication.facade.AuthenticationFacade;
import de.cuioss.portal.authentication.facade.PortalAuthenticationFacade;
import de.cuioss.portal.common.priority.PortalPriorities;
Expand Down Expand Up @@ -51,18 +50,17 @@ public class LogoutPageBean implements LogoutPage {

@Inject
@PortalAuthenticationFacade
private AuthenticationFacade authenticationFacade;
AuthenticationFacade authenticationFacade;

@Inject
private FacesContext facesContext;
FacesContext facesContext;

@Inject
@PortalLoginEvent
private Event<LoginEvent> preLogoutEvent;
Event<LoginEvent> preLogoutEvent;

@Inject
@PortalUser
private AuthenticatedUserInfo authenticatedUserInfo;
AuthenticatedUserInfo authenticatedUserInfo;

/**
* Logs out and redirects to login page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

@EnablePortalUiEnvironment
@AddBeanClasses({PortalPagesConfiguration.class, PortalTestUserProducer.class, PortalClientStorageMock.class,
LoginPageClientStorageImpl.class, LoginPageHistoryManagerProviderImpl.class})
LoginPageClientStorageImpl.class, LoginPageHistoryManagerProviderImpl.class})
class LoginPageBeanTest extends AbstractPageBeanTest<LoginPageBean> implements ComponentConfigurator {

private static final String SOME_ERROR_KEY = "some.error";
Expand Down Expand Up @@ -93,8 +93,7 @@ class LoginPageBeanTest extends AbstractPageBeanTest<LoginPageBean> implements C
@Param
public String getParameter(final InjectionPoint injectionPoint) {

configuration.put(PortalConfigurationKeys.PAGES_LOGIN_DEFAULT_USER_STORE, SOME_OTHER_LDAP_USER_STORE.getName());
configuration.fireEvent();
configuration.update(PortalConfigurationKeys.PAGES_LOGIN_DEFAULT_USER_STORE, SOME_OTHER_LDAP_USER_STORE.getName());

final var name = injectionPoint.getMember().getName();
return switch (name) {
Expand Down Expand Up @@ -122,10 +121,10 @@ void shouldUseUrlParameterAtDeepLinking() {

// Mimic that Preferences was initially called
final ViewDescriptor newDescriptor = ViewDescriptorImpl.builder()
.withViewId(PortalNavigationConfiguration.VIEW_PREFERENCES_LOGICAL_VIEW_ID)
.withUrlParameter(mutableList(new UrlParameter(LoginPage.KEY_USERNAME, TEST_USER_NAME),
new UrlParameter(LoginPage.KEY_USERSTORE, TEST_USER_STORE)))
.withLogicalViewId(PortalNavigationConfiguration.VIEW_PREFERENCES_LOGICAL_VIEW_ID).build();
.withViewId(PortalNavigationConfiguration.VIEW_PREFERENCES_LOGICAL_VIEW_ID)
.withUrlParameter(mutableList(new UrlParameter(LoginPage.KEY_USERNAME, TEST_USER_NAME),
new UrlParameter(LoginPage.KEY_USERSTORE, TEST_USER_STORE)))
.withLogicalViewId(PortalNavigationConfiguration.VIEW_PREFERENCES_LOGICAL_VIEW_ID).build();
portalHistoryManagerMock.addCurrentUriToHistory(newDescriptor);

assertEquals(TEST_USER_NAME, underTest.getLoginCredentials().getUsername());
Expand Down Expand Up @@ -194,7 +193,7 @@ void shouldHideUserStoreSelectionOnSingleEntry() {
assertFalse(underTest.isShouldDisplayUserStoreDropdown(), "User store drop-down should be hidden");

assertEquals(DEFAULT_USER_STORE.getName(), underTest.getLoginCredentials().getUserStore(),
"On single user store the first must be selected as default");
"On single user store the first must be selected as default");
}

@Test
Expand All @@ -212,9 +211,8 @@ void shouldDisplayErrorText() {

@Test
void viewActionShouldLogoutOnLogoutStrategy() {
configuration.put(PortalConfigurationKeys.PAGES_LOGIN_ENTER_STRATEGY,
LoginPageStrategy.LOGOUT.getStrategyName());
configuration.fireEvent();
configuration.update(PortalConfigurationKeys.PAGES_LOGIN_ENTER_STRATEGY,
LoginPageStrategy.LOGOUT.getStrategyName());
assertNull(underTest.initViewAction());
authenticationFacadeMock.assertAuthenticated(false);
}
Expand All @@ -224,7 +222,7 @@ void viewActionShouldLogoutOnLogoutStrategy() {
// No idea here
void shouldUseConfiguredUserStoreAsDefault() {
assertEquals(underTest.getLoginCredentials().getUserStore(), SOME_OTHER_LDAP_USER_STORE.getName(),
"Wrong selected user store");
"Wrong selected user store");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
*/
package de.cuioss.portal.ui.oauth;

import java.io.Serial;
import java.io.Serializable;

import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.servlet.http.HttpServletRequest;

import de.cuioss.portal.authentication.AuthenticatedUserInfo;
import de.cuioss.portal.authentication.LoginEvent;
import de.cuioss.portal.authentication.PortalLoginEvent;
import de.cuioss.portal.authentication.PortalUser;
import de.cuioss.portal.authentication.facade.AuthenticationFacade;
import de.cuioss.portal.authentication.facade.PortalAuthenticationFacade;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.servlet.http.HttpServletRequest;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.io.Serial;
import java.io.Serializable;

/**
* Provides an empty logout page to be embedded from the oauth server via iframe
* for the front channel logout - no further action is necessary.
Expand All @@ -50,22 +48,18 @@ public class OauthIFrameLogoutPageBean implements Serializable {

@Inject
@PortalAuthenticationFacade
private AuthenticationFacade authenticationFacade;
AuthenticationFacade authenticationFacade;

@Inject
private HttpServletRequest servletRequest;
HttpServletRequest servletRequest;

@Inject
@PortalUser
private AuthenticatedUserInfo authenticatedUserInfo;
AuthenticatedUserInfo authenticatedUserInfo;

@Inject
@PortalLoginEvent
private Event<LoginEvent> preLougoutEvent;
Event<LoginEvent> preLougoutEvent;

/**
* @return
*/
public String logoutViewAction() {
if (authenticatedUserInfo.isAuthenticated()) {
preLougoutEvent.fire(LoginEvent.builder().action(LoginEvent.Action.LOGOUT).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import de.cuioss.portal.authentication.AuthenticatedUserInfo;
import de.cuioss.portal.authentication.LoginEvent;
import de.cuioss.portal.authentication.PortalLoginEvent;
import de.cuioss.portal.authentication.PortalUser;
import de.cuioss.portal.authentication.facade.PortalAuthenticationFacade;
import de.cuioss.portal.authentication.oauth.LoginPagePath;
import de.cuioss.portal.authentication.oauth.OAuthConfigKeys;
Expand Down Expand Up @@ -71,31 +70,30 @@ public class OauthLogoutPageBean implements LogoutPage {

@Inject
@PortalAuthenticationFacade
private Oauth2AuthenticationFacade authenticationFacade;
Oauth2AuthenticationFacade authenticationFacade;

@Inject
private FacesContext facesContext;
FacesContext facesContext;

@Inject
@PortalLoginEvent
private Event<LoginEvent> preLogoutEvent;
Event<LoginEvent> preLogoutEvent;

@Inject
@PortalUser
private AuthenticatedUserInfo authenticatedUserInfo;
AuthenticatedUserInfo authenticatedUserInfo;

@Inject
private Oauth2Configuration oauth2Configuration;
Oauth2Configuration oauth2Configuration;

@Inject
@LoginPagePath
private String loginUrl;
String loginUrl;

@Inject
private HttpServletRequest servletRequest;
HttpServletRequest servletRequest;

@Inject
private Oauth2Configuration configuration;
Oauth2Configuration configuration;

/**
* Logs out and redirects to login page.
Expand All @@ -109,7 +107,7 @@ public String logoutViewAction() {
}

var idpLogoutUrl = authenticationFacade.retrieveClientLogoutUrl(
CollectionBuilder.<UrlParameter>copyFrom().add(getPostLogoutRedirectUriParam()).toImmutableSet());
CollectionBuilder.<UrlParameter>copyFrom().add(getPostLogoutRedirectUriParam()).toImmutableSet());
LOGGER.debug("Redirecting to IDP logout URL: {}", idpLogoutUrl);

// Actually wrong if strictly sticking to rp-initiated-logout specification,
Expand Down Expand Up @@ -141,7 +139,7 @@ private Optional<UrlParameter> getPostLogoutRedirectUriParam() {
if (isPresent(postLogoutRedirectUri)) {
if (isBlank(configuration.getLogoutRedirectParamName())) {
LOGGER.warn("postLogoutRedirectUri set, but no url-parameter name. Set via: {}",
OAuthConfigKeys.OPEN_ID_CLIENT_LOGOUT_REDIRECT_PARAMETER);
OAuthConfigKeys.OPEN_ID_CLIENT_LOGOUT_REDIRECT_PARAMETER);
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,42 @@
*/
package de.cuioss.portal.ui.oauth;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;

import org.jboss.weld.junit5.auto.AddBeanClasses;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import de.cuioss.portal.authentication.AuthenticatedUserInfo;
import de.cuioss.portal.authentication.LoginEvent;
import de.cuioss.portal.authentication.PortalLoginEvent;
import de.cuioss.portal.authentication.PortalUser;
import de.cuioss.portal.authentication.facade.PortalAuthenticationFacade;
import de.cuioss.portal.authentication.model.BaseAuthenticatedUserInfo;
import de.cuioss.portal.core.test.mocks.authentication.PortalAuthenticationFacadeMock;
import de.cuioss.portal.ui.test.junit5.EnablePortalUiEnvironment;
import de.cuioss.portal.ui.test.tests.AbstractPageBeanTest;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import lombok.Getter;
import org.jboss.weld.junit5.auto.AddBeanClasses;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

@EnablePortalUiEnvironment
@AddBeanClasses({ PortalAuthenticationFacadeMock.class })
@AddBeanClasses({PortalAuthenticationFacadeMock.class})
class OauthIFrameLogoutPageBeanTest extends AbstractPageBeanTest<OauthIFrameLogoutPageBean> {

private static final String USER = "user";

@Inject
@Getter
private OauthIFrameLogoutPageBean underTest;
OauthIFrameLogoutPageBean underTest;

@Inject
@PortalAuthenticationFacade
private PortalAuthenticationFacadeMock facade;
PortalAuthenticationFacadeMock facade;

@Produces
@PortalUser
private AuthenticatedUserInfo user;
AuthenticatedUserInfo user;

private LoginEvent logoutEvent;
LoginEvent logoutEvent;

@BeforeEach
void resetLogoutEvent() {
Expand Down
Loading

0 comments on commit 130c744

Please sign in to comment.