Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MfaProvider validation returns specific message. Do not restrict whit…
…espace in name [#150620737] https://www.pivotaltracker.com/story/show/150620737 Signed-off-by: Shash Reddy <sreddy@pivotal.io>
- Loading branch information
1 parent
8a8d957
commit 21e1af4
Showing
17 changed files
with
380 additions
and
105 deletions.
There are no files selected for viewing
26 changes: 25 additions & 1 deletion
26
model/src/main/java/org/cloudfoundry/identity/uaa/mfa_provider/GoogleMfaProviderConfig.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
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
40 changes: 40 additions & 0 deletions
40
...src/main/java/org/cloudfoundry/identity/uaa/mfa_provider/GeneralMfaProviderValidator.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,40 @@ | ||
package org.cloudfoundry.identity.uaa.mfa_provider; | ||
|
||
import org.springframework.util.StringUtils; | ||
|
||
public class GeneralMfaProviderValidator implements MfaProviderValidator{ | ||
private MfaProviderConfigValidator configValidator; | ||
|
||
@Override | ||
public void validate(MfaProvider mfaProvider) { | ||
if(mfaProvider.getName() == null || StringUtils.isEmpty(mfaProvider.getName().trim())) { | ||
throw new InvalidMfaProviderException("Provider name is required"); | ||
} | ||
mfaProvider.setName(mfaProvider.getName().trim()); | ||
if(mfaProvider.getName().length() > 256) { | ||
throw new InvalidMfaProviderException("Provider name cannot be longer than 256 characters"); | ||
} | ||
if(!mfaProvider.getName().matches("^[a-zA-Z0-9]+[\\sa-zA-Z0-9]*$")){ | ||
throw new InvalidMfaProviderException("Provider name must be alphanumeric"); | ||
} | ||
if(mfaProvider.getType() == null) { | ||
throw new InvalidMfaProviderException("Provider type is required. Must be one of " + MfaProvider.MfaProviderType.getStringValues()); | ||
} | ||
if(mfaProvider.getConfig() == null) { | ||
throw new InvalidMfaProviderException("Provider config is required"); | ||
} | ||
if(!StringUtils.hasText(mfaProvider.getIdentityZoneId())){ | ||
throw new InvalidMfaProviderException("Provider must belong to a zone"); | ||
} | ||
try { | ||
configValidator.validate(mfaProvider.getConfig()); | ||
} catch (InvalidMfaProviderConfigException e) { | ||
throw new InvalidMfaProviderException("Invalid Config for MFA Provider. " + e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
public void setConfigValidator(MfaProviderConfigValidator configValidator) { | ||
this.configValidator = configValidator; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ain/java/org/cloudfoundry/identity/uaa/mfa_provider/GoogleMfaProviderConfigValidator.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,17 @@ | ||
package org.cloudfoundry.identity.uaa.mfa_provider; | ||
|
||
public class GoogleMfaProviderConfigValidator implements MfaProviderConfigValidator<GoogleMfaProviderConfig> { | ||
|
||
@Override | ||
public void validate(GoogleMfaProviderConfig mfaProviderConfig) throws InvalidMfaProviderConfigException { | ||
if(mfaProviderConfig.getAlgorithm() == null) { | ||
throw new InvalidMfaProviderConfigException("Algorithm must be one of " + GoogleMfaProviderConfig.Algorithm.getStringaValues()); | ||
} | ||
if(mfaProviderConfig.getDigits() < 1) { | ||
throw new InvalidMfaProviderConfigException("Digits must be greater than 0"); | ||
} | ||
if(mfaProviderConfig.getDuration() < 1) { | ||
throw new InvalidMfaProviderConfigException("Duration must be greater than 0"); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...in/java/org/cloudfoundry/identity/uaa/mfa_provider/InvalidMfaProviderConfigException.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,7 @@ | ||
package org.cloudfoundry.identity.uaa.mfa_provider; | ||
|
||
public class InvalidMfaProviderConfigException extends Exception { | ||
public InvalidMfaProviderConfigException(String message) { | ||
super(message); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/main/java/org/cloudfoundry/identity/uaa/mfa_provider/InvalidMfaProviderException.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,15 @@ | ||
package org.cloudfoundry.identity.uaa.mfa_provider; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.cloudfoundry.identity.uaa.error.UaaException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class InvalidMfaProviderException extends UaaException { | ||
|
||
public final Log logger = LogFactory.getLog(InvalidMfaProviderException.class); | ||
public InvalidMfaProviderException(String message) { | ||
super("invalid_mfa_provider", message, HttpStatus.UNPROCESSABLE_ENTITY.value()); | ||
logger.debug("MfaProvider validation error. " + message); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
.../src/main/java/org/cloudfoundry/identity/uaa/mfa_provider/MfaProviderConfigValidator.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,5 @@ | ||
package org.cloudfoundry.identity.uaa.mfa_provider; | ||
|
||
public interface MfaProviderConfigValidator<T extends AbstractMfaProviderConfig>{ | ||
void validate(T mfaProviderConfig) throws InvalidMfaProviderConfigException; | ||
} |
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
5 changes: 5 additions & 0 deletions
5
server/src/main/java/org/cloudfoundry/identity/uaa/mfa_provider/MfaProviderValidator.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,5 @@ | ||
package org.cloudfoundry.identity.uaa.mfa_provider; | ||
|
||
public interface MfaProviderValidator { | ||
void validate(MfaProvider mfaProvider); | ||
} |
Oops, something went wrong.