|
| 1 | +/* |
| 2 | + * Copyright (c) 2025-2025, FusionAuth, All Rights Reserved |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, |
| 11 | + * software distributed under the License is distributed on an |
| 12 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 13 | + * either express or implied. See the License for the specific |
| 14 | + * language governing permissions and limitations under the License. |
| 15 | + */ |
| 16 | +package io.fusionauth.domain; |
| 17 | + |
| 18 | +/** |
| 19 | + * Determines if FusionAuth is in FIPS mode based on the system property <code>fusionauth.fips.enabled</code>. This can only be enabled once and |
| 20 | + * should be enabled when the VM starts or as close to that point as possible. |
| 21 | + * <p> |
| 22 | + * Once this has been enabled, it cannot be disabled. |
| 23 | + * <p> |
| 24 | + * This also provides some helpers for FIPS things such as password length requirements. |
| 25 | + * |
| 26 | + * @author Brian Pontarelli & Daniel DeGroff |
| 27 | + */ |
| 28 | +public class FIPS { |
| 29 | + public static final int FIPS_MIN_PASSWORD_LENGTH = 14; |
| 30 | + |
| 31 | + public static final int STANDARD_MIN_PASSWORD_LENGTH = 8; |
| 32 | + |
| 33 | + private static volatile Boolean Enabled; |
| 34 | + |
| 35 | + /** |
| 36 | + * Lazily determines if the System configuration is set to enable FIPS mode. This is done on the first call to this method. Subsequent calls return |
| 37 | + * the cached value, regardless of the System properties changing. |
| 38 | + * |
| 39 | + * @return Whether or not FIPS is enabled. |
| 40 | + */ |
| 41 | + public static boolean isEnabled() { |
| 42 | + if (Enabled != null) { |
| 43 | + return Enabled; |
| 44 | + } |
| 45 | + |
| 46 | + Enabled = Boolean.getBoolean("fusionauth.fips.enabled"); |
| 47 | + return Boolean.TRUE.equals(Enabled); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns the minimum password length requirement, which depends on whether FusionAuth is operating in FIPS mode. |
| 52 | + * If FIPS mode is enabled, the minimum password length will be {@code FIPS_MIN_PASSWORD_LENGTH}. |
| 53 | + * Otherwise, the minimum password length will be {@code STANDARD_MIN_PASSWORD_LENGTH}. |
| 54 | + * |
| 55 | + * @return The minimum password length, either {@code FIPS_MIN_PASSWORD_LENGTH} when FIPS mode is enabled or {@code STANDARD_MIN_PASSWORD_LENGTH} |
| 56 | + * when it is not. |
| 57 | + */ |
| 58 | + public static int minimumPasswordLength() { |
| 59 | + return isEnabled() ? FIPS_MIN_PASSWORD_LENGTH : STANDARD_MIN_PASSWORD_LENGTH; |
| 60 | + } |
| 61 | +} |
0 commit comments