Search in sources :

Example 1 with InjectConfiguration

use of org.restheart.plugins.InjectConfiguration in project restheart by SoftInstigate.

the class JwtAuthenticationMechanism method init.

@InjectConfiguration
public void init(Map<String, Object> args) throws ConfigurationException {
    // get configuration arguments
    base64Encoded = argValue(args, "base64Encoded");
    algorithm = argValue(args, "algorithm");
    key = argValue(args, "key");
    usernameClaim = argValue(args, "usernameClaim");
    rolesClaim = argValue(args, "rolesClaim");
    fixedRoles = argValue(args, "fixedRoles");
    issuer = argValue(args, "issuer");
    audience = argValue(args, "audience");
    Algorithm _algorithm;
    try {
        _algorithm = getAlgorithm(algorithm, key);
    } catch (CertificateException | UnsupportedEncodingException ex) {
        throw new ConfigurationException("wrong JWT configuration, " + "cannot setup algorithm", ex);
    }
    Verification v = JWT.require(_algorithm);
    if (audience != null) {
        v.withAudience(audience);
    }
    if (issuer != null) {
        v.withIssuer(issuer);
    }
    if (rolesClaim != null && fixedRoles != null) {
        throw new ConfigurationException("wrong JWT configuration, " + "cannot set both 'rolesClaim' and 'fixedRoles'");
    }
    if (rolesClaim == null && fixedRoles == null) {
        throw new ConfigurationException("wrong JWT configuration, " + "need to set either 'rolesClaim' or 'fixedRoles'");
    }
    this.jwtVerifier = v.build();
}
Also used : ConfigurationException(org.restheart.ConfigurationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CertificateException(java.security.cert.CertificateException) Verification(com.auth0.jwt.interfaces.Verification) Algorithm(com.auth0.jwt.algorithms.Algorithm) InjectConfiguration(org.restheart.plugins.InjectConfiguration)

Example 2 with InjectConfiguration

use of org.restheart.plugins.InjectConfiguration in project restheart by SoftInstigate.

the class MongoAclAuthorizer method initConfiguration.

@InjectConfiguration
public void initConfiguration(Map<String, Object> args) {
    this.aclDb = argValue(args, "acl-db");
    this.aclCollection = argValue(args, "acl-collection");
    this.rootRole = argValue(args, "root-role");
    if (args != null && args.containsKey("cache-enabled")) {
        this.cacheEnabled = argValue(args, "cache-enabled");
        if (this.cacheEnabled) {
            this.cacheSize = argValue(args, "cache-size");
            this.cacheTTL = argValue(args, "cache-ttl");
            String _cacheExpirePolicy = argValue(args, "cache-expire-policy");
            if (_cacheExpirePolicy != null) {
                try {
                    this.cacheExpirePolicy = Cache.EXPIRE_POLICY.valueOf((String) _cacheExpirePolicy);
                } catch (IllegalArgumentException iae) {
                    throw new ConfigurationException("wrong configuration file format. " + "cache-expire-policy valid values are " + Arrays.toString(Cache.EXPIRE_POLICY.values()));
                }
            }
            this.acl = CacheFactory.createLocalLoadingCache(this.cacheSize, this.cacheExpirePolicy, this.cacheTTL, (String role) -> {
                return this.findRolePermissions(role);
            });
        }
    }
}
Also used : ConfigurationException(org.restheart.ConfigurationException) InjectConfiguration(org.restheart.plugins.InjectConfiguration)

Aggregations

ConfigurationException (org.restheart.ConfigurationException)2 InjectConfiguration (org.restheart.plugins.InjectConfiguration)2 Algorithm (com.auth0.jwt.algorithms.Algorithm)1 Verification (com.auth0.jwt.interfaces.Verification)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CertificateException (java.security.cert.CertificateException)1