Search in sources :

Example 1 with ValidationException

use of org.owasp.esapi.errors.ValidationException in project Asqatasun by Asqatasun.

the class TokenManager method getTokenUser.

/**
     *
     * @param userAccountName
     * @param additionalParameters
     * @return
     */
public String getTokenUser(String userAccountName, Map<String, String> additionalParameters) {
    try {
        CryptoToken cryptoToken = new CryptoToken();
        cryptoToken.setUserAccountName(userAccountName);
        cryptoToken.setExpiration(tokenDurationValidity);
        cryptoToken.addAttributes(additionalParameters);
        String token = cryptoToken.getToken();
        tokenUsage.put(token, Boolean.FALSE);
        return token;
    } catch (EncryptionException ex) {
        Logger.getLogger(this.getClass()).warn(ex);
        return "";
    } catch (ValidationException ex) {
        Logger.getLogger(this.getClass()).warn(ex);
        return "";
    }
}
Also used : CryptoToken(org.owasp.esapi.crypto.CryptoToken) ValidationException(org.owasp.esapi.errors.ValidationException) EncryptionException(org.owasp.esapi.errors.EncryptionException)

Example 2 with ValidationException

use of org.owasp.esapi.errors.ValidationException in project simba-os by cegeka.

the class PolicyServiceImpl method createPolicy.

@Override
public TPolicy createPolicy(String policyName) throws TException {
    return simbaExceptionHandlingCaller.call(() -> {
        try {
            DTOValidator.assertValidString("createRole", policyName);
            if (roleRepository.findByName(policyName) != null) {
                throw new IllegalArgumentException("Policy with name " + policyName + " already exists");
            }
            Policy newPolicy = new PolicyEntity(policyName);
            policyRepository.persist(newPolicy);
            audit.log("Policy ''{0}'' created", policyName);
            return assembler.assemble(newPolicy);
        } catch (ValidationException e) {
            throw new IllegalArgumentException(e);
        }
    });
}
Also used : TPolicy(org.simbasecurity.api.service.thrift.TPolicy) Policy(org.simbasecurity.core.domain.Policy) ValidationException(org.owasp.esapi.errors.ValidationException) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity)

Example 3 with ValidationException

use of org.owasp.esapi.errors.ValidationException in project simba-os by cegeka.

the class RoleServiceImpl method createRole.

public TRole createRole(String roleName) throws TException {
    return simbaExceptionHandlingCaller.call(() -> {
        try {
            DTOValidator.assertValidString("createRole", roleName);
            if (roleRepository.findByName(roleName) != null) {
                throw new IllegalArgumentException("Role with name " + roleName + " already exists");
            }
            Role newRole = new RoleEntity(roleName);
            roleRepository.persist(newRole);
            managementAudit.log("Role ''{0}'' created", roleName);
            return assembler.assemble(newRole);
        } catch (ValidationException e) {
            throw new IllegalArgumentException(e);
        }
    });
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) ValidationException(org.owasp.esapi.errors.ValidationException)

Example 4 with ValidationException

use of org.owasp.esapi.errors.ValidationException in project Asqatasun by Asqatasun.

the class TokenManager method getTokenUser.

/**
     *
     * @param userAccountName
     * @return
     */
public String getTokenUser(String userAccountName) {
    try {
        CryptoToken cryptoToken = new CryptoToken();
        cryptoToken.setUserAccountName(userAccountName);
        cryptoToken.setExpiration(tokenDurationValidity);
        String token = cryptoToken.getToken();
        tokenUsage.put(token, Boolean.FALSE);
        return token;
    } catch (EncryptionException ex) {
        Logger.getLogger(this.getClass()).warn(ex);
        return "";
    } catch (ValidationException ex) {
        Logger.getLogger(this.getClass()).warn(ex);
        return "";
    }
}
Also used : CryptoToken(org.owasp.esapi.crypto.CryptoToken) ValidationException(org.owasp.esapi.errors.ValidationException) EncryptionException(org.owasp.esapi.errors.EncryptionException)

Example 5 with ValidationException

use of org.owasp.esapi.errors.ValidationException in project Asqatasun by Asqatasun.

the class TokenManager method getTokenUser.

/**
 * @param userAccountName
 * @param additionalParameters
 * @return
 */
public String getTokenUser(String userAccountName, Map<String, String> additionalParameters) {
    try {
        CryptoToken cryptoToken = new CryptoToken();
        cryptoToken.setUserAccountName(userAccountName);
        cryptoToken.setExpiration(tokenDurationValidity);
        cryptoToken.addAttributes(additionalParameters);
        String token = cryptoToken.getToken();
        tokenUsage.put(token, Boolean.FALSE);
        return token;
    } catch (EncryptionException | ValidationException ex) {
        LOGGER.warn(ex.getMessage());
        return "";
    }
}
Also used : CryptoToken(org.owasp.esapi.crypto.CryptoToken) ValidationException(org.owasp.esapi.errors.ValidationException) EncryptionException(org.owasp.esapi.errors.EncryptionException)

Aggregations

ValidationException (org.owasp.esapi.errors.ValidationException)5 CryptoToken (org.owasp.esapi.crypto.CryptoToken)3 EncryptionException (org.owasp.esapi.errors.EncryptionException)3 TPolicy (org.simbasecurity.api.service.thrift.TPolicy)1 Policy (org.simbasecurity.core.domain.Policy)1 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)1 Role (org.simbasecurity.core.domain.Role)1 RoleEntity (org.simbasecurity.core.domain.RoleEntity)1