Skip to content

Commit

Permalink
Rename login example application to google-login
Browse files Browse the repository at this point in the history
  • Loading branch information
besidev committed Jan 2, 2024
1 parent 81ac21a commit 018991f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ dependencies {
- As desktop application
```shell
./gradlew jpro-auth:example:run -Psample=basic-login
./gradlew jpro-auth:example:run -Psample=login
./gradlew jpro-auth:example:run -Psample=google-login
./gradlew jpro-auth:example:run -Psample=oauth
./gradlew jpro-file:example:run -Psample=file-uploader
./gradlew jpro-file:example:run -Psample=file-uploader
Expand All @@ -479,7 +479,7 @@ dependencies {
- As JPro application
```shell
./gradlew jpro-auth:example:jproRun -Psample=basic-login
./gradlew jpro-auth:example:jproRun -Psample=login
./gradlew jpro-auth:example:jproRun -Psample=google-login
./gradlew jpro-auth:example:jproRun -Psample=oauth
./gradlew jpro-file:example:jproRun -Psample=file-uploader
./gradlew jpro-file:example:jproRun -Psample=file-uploader
Expand Down
8 changes: 4 additions & 4 deletions jpro-auth/example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ javafx {
}

def examples = [
'basic-login': 'one.jpro.platform.auth.example.basic.BasicLoginApp',
'login' : 'one.jpro.platform.auth.example.login.LoginApp',
'oauth' : 'one.jpro.platform.auth.example.oauth.OAuthApp'
'basic-login' : 'one.jpro.platform.auth.example.basic.BasicLoginApp',
'google-login': 'one.jpro.platform.auth.example.login.GoogleLoginApp',
'oauth' : 'one.jpro.platform.auth.example.oauth.OAuthApp'
]

mainClassName = project.hasProperty("sample") ? examples[project.getProperties().get("sample")] : examples["login"]
mainClassName = project.hasProperty("sample") ? examples[project.getProperties().get("sample")] : examples["google-login"]

application {
mainClass = "$mainClassName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@
* The {@link BasicLoginApp} class is a specialized implementation of {@link RouteApp} designed for handling
* user authentication and session management in a web application context. This class incorporates
* {@link BasicAuthenticationProvider} to facilitate basic authentication using username and password credentials.
* <p>
* <ul>
* Key Features:
* - Authentication: Utilizes {@link BasicAuthenticationProvider} for authenticating users. It defines specific
* roles such as "USER" and "ADMIN" and creates an authentication provider instance accordingly.
* - Credentials Management: Manages user credentials using {@link UsernamePasswordCredentials} which are essential
* for the authentication process.
* - Session Management: Employs {@link SessionManager} for maintaining user sessions. This enables the application
* to persist user state across different requests. It distinguishes between browser and non-browser environments
* for session handling.
* - Routing: Defines application routing using the {@link Route} class. It sets up various routes like the root path
* and authenticated user path, and integrates authentication filters to protect these routes.
* - Error Handling: Implements error handling within the authentication flow, ensuring that authentication failures
* are managed gracefully.
* - User State Management: Provides methods for retrieving and setting the authenticated user in the session,
* thereby managing the user's state throughout the application.
* <li>Authentication: Utilizes {@link BasicAuthenticationProvider} for authenticating users. It defines specific
* roles such as "USER" and "ADMIN" and creates an authentication provider instance accordingly.</li>
* <li>Credentials Management: Manages user credentials using {@link UsernamePasswordCredentials} which are
* essential for the authentication process.</li>
* <li>Session Management: Employs {@link SessionManager} for maintaining user sessions. This enables the
* application to persist user state across different requests. It distinguishes between browser and non-browser
* environments for session handling</li>
* <li>Routing: Defines application routing using the {@link Route} class. It sets up various routes like the root
* path and authenticated user path, and integrates authentication filters to protect these routes.</li>
* <li>Error Handling: Implements error handling within the authentication flow, ensuring that authentication
* failures are managed gracefully.</li>
* <li>Routing: Defines application routing using the {@link Route} class. It sets up various routes like the root
* path and authenticated user path, and integrates authentication filters to protect these routes.</li>
* <li>User State Management: Provides methods for retrieving and setting the authenticated user in the session,
* thereby managing the user's state throughout the application.</li>
* </ul>
*
* @author Besmir Beqiri
*/
Expand All @@ -57,8 +60,8 @@ public class BasicLoginApp extends RouteApp {

@Override
public Route createRoute() {
session = (WebAPI.isBrowser()) ? sessionManager.getSession(getWebAPI())
: sessionManager.getSession("user-session");
session = (WebAPI.isBrowser()) ? sessionManager.getSession(getWebAPI()) :
sessionManager.getSession("user-session");

Optional.ofNullable(CupertinoLight.class.getResource(new CupertinoLight().getUserAgentStylesheet()))
.map(URL::toExternalForm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,32 @@
import java.util.Optional;

/**
* The {@link LoginApp} class extends {@link RouteApp} to create a JavaFX application
* The {@link GoogleLoginApp} class extends {@link RouteApp} to create a JavaFX application
* with integrated Google OAuth authentication. It manages user sessions and error handling
* using JavaFX properties. This class sets up routes for the application including
* the login page, successful signed in page, and error handling page.
*
* <p>It uses environment variables to fetch Google Client ID and Secret for OAuth configuration.
* <p>
* It uses environment variables to fetch Google Client ID and Secret for OAuth configuration.
* The class provides a structured way to handle user authentication and maintain session state.
*
* <p>Routes are defined to handle different parts of the application, such as user authentication,
* <p>
* Routes are defined to handle different parts of the application, such as user authentication,
* session management, and error display. This includes handling OAuth2 authentication with Google,
* managing user sessions, and providing appropriate UI responses for different authentication states.
*
* <p>It also defines properties for the current user and any errors that occur during the
* <p>
* It also defines properties for the current user and any errors that occur during the
* authentication process, allowing for easy integration with JavaFX UI components and data binding.
*
* <p>Note: This class requires additional context about {@code RouteApp}, {@code AuthAPI},
* <p>
* Note: This class requires additional context about {@code RouteApp}, {@code AuthAPI},
* {@code OAuth2Credentials}, and other related classes/methods for its full functionality.
*
* @author Besmir Beqiri
*/
public class LoginApp extends RouteApp {
public class GoogleLoginApp extends RouteApp {

static final String GOOGLE_CLIENT_ID = System.getenv("GOOGLE_TEST_CLIENT_ID");
static final String GOOGLE_CLIENT_SECRET = System.getenv("GOOGLE_TEST_CLIENT_SECRET");

private static final SessionManager sessionManager = new SessionManager("simple-app");

private static final SessionManager sessionManager = new SessionManager("google-login-app");
ObservableMap<String, String> session;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public LoginPage(GoogleAuthenticationProvider authProvider) {
* @return a button node
*/
public Button createAuthProviderButton(String text) {
ImageView iconView = new ImageView();
final var iconView = new ImageView();
iconView.setFitWidth(56);
iconView.setFitHeight(56);
Optional.ofNullable(getClass().getResourceAsStream("/images/" + text + "_Logo.png"))
.map(inputStream -> new Image(inputStream, 0, 0, true, true))
.ifPresent(iconView::setImage);

Button loginButton = new Button("Login with\n" + text, iconView);
final var loginButton = new Button("Login with\n" + text, iconView);
loginButton.getStyleClass().addAll("login-button");
return loginButton;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import one.jpro.platform.auth.core.oauth2.OAuth2AuthenticationProvider;
import one.jpro.platform.auth.example.login.LoginApp;
import one.jpro.platform.auth.example.login.GoogleLoginApp;
import simplefx.experimental.parts.FXFuture;

/**
Expand All @@ -15,8 +15,7 @@
*/
public class SignedInPage extends Page {

public SignedInPage(LoginApp app,
OAuth2AuthenticationProvider authProvider) {
public SignedInPage(GoogleLoginApp app, OAuth2AuthenticationProvider authProvider) {
final var headerLabel = new Label("Not signed in.");
headerLabel.getStyleClass().add("header-label");

Expand Down

0 comments on commit 018991f

Please sign in to comment.