-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 fixing the mess about password length resolution
Signed-off-by: dseurotech <[email protected]>
- Loading branch information
1 parent
72c8f63
commit 90927fa
Showing
12 changed files
with
299 additions
and
172 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
.../eclipse/kapua/service/authentication/credential/shiro/AccountPasswordLengthProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.service.authentication.credential.shiro; | ||
|
||
import org.eclipse.kapua.KapuaException; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.storage.TxContext; | ||
|
||
public interface AccountPasswordLengthProvider { | ||
|
||
int getMinimumPasswordLength(TxContext txContext, KapuaId scopeId) throws KapuaException; | ||
|
||
int getMaximumPasswordLength(TxContext txContext, KapuaId scopeId) throws KapuaException; | ||
} |
63 changes: 63 additions & 0 deletions
63
...ipse/kapua/service/authentication/credential/shiro/AccountPasswordLengthProviderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.service.authentication.credential.shiro; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.kapua.KapuaException; | ||
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManager; | ||
import org.eclipse.kapua.commons.util.ArgumentValidator; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.service.authentication.shiro.SystemPasswordLengthProvider; | ||
import org.eclipse.kapua.storage.TxContext; | ||
|
||
public class AccountPasswordLengthProviderImpl implements AccountPasswordLengthProvider { | ||
|
||
private final SystemPasswordLengthProvider systemPasswordLengthProvider; | ||
private final ServiceConfigurationManager credentialServiceConfigurationManager; | ||
public static final String PASSWORD_MIN_LENGTH_ACCOUNT_CONFIG_KEY = "password.minLength"; | ||
|
||
public AccountPasswordLengthProviderImpl(SystemPasswordLengthProvider systemPasswordLengthProvider, ServiceConfigurationManager credentialServiceConfigurationManager) { | ||
this.systemPasswordLengthProvider = systemPasswordLengthProvider; | ||
this.credentialServiceConfigurationManager = credentialServiceConfigurationManager; | ||
} | ||
|
||
@Override | ||
public int getMinimumPasswordLength(TxContext txContext, KapuaId scopeId) throws KapuaException { | ||
// Argument Validation | ||
ArgumentValidator.notNull(scopeId, "scopeId"); | ||
|
||
// Check access | ||
// None | ||
|
||
// Get system minimum password length | ||
int minPasswordLength = systemPasswordLengthProvider.getSystemMinimumPasswordLength(); | ||
|
||
if (!KapuaId.ANY.equals(scopeId)) { | ||
Object minPasswordLengthAccountConfigValue = getConfigValues(txContext, scopeId).get(PASSWORD_MIN_LENGTH_ACCOUNT_CONFIG_KEY); | ||
if (minPasswordLengthAccountConfigValue != null) { | ||
minPasswordLength = Integer.parseInt(minPasswordLengthAccountConfigValue.toString()); | ||
} | ||
} | ||
return minPasswordLength; | ||
} | ||
|
||
@Override | ||
public int getMaximumPasswordLength(TxContext txContext, KapuaId scopeId) throws KapuaException { | ||
return systemPasswordLengthProvider.getSystemMaximumPasswordLength(); | ||
} | ||
|
||
private Map<String, Object> getConfigValues(TxContext tx, KapuaId scopeId) throws KapuaException { | ||
return credentialServiceConfigurationManager.getConfigValues(tx, scopeId, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.