ProviderConfig.java 8.35 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.crypto.CryptoSupport
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.PropertyUnbounded
 *  org.apache.sling.commons.osgi.OsgiUtil
 *  org.osgi.service.cm.ConfigurationException
 *  org.scribe.builder.api.Api
 *  org.scribe.model.OAuthConfig
 *  org.scribe.model.SignatureType
 *  org.scribe.oauth.OAuthService
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.auth.oauth.impl.helper;

import com.adobe.granite.auth.oauth.Provider;
import com.adobe.granite.auth.oauth.impl.helper.OauthTokenManager;
import com.adobe.granite.crypto.CryptoSupport;
import java.io.OutputStream;
import java.util.Dictionary;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.osgi.service.cm.ConfigurationException;
import org.scribe.builder.api.Api;
import org.scribe.model.OAuthConfig;
import org.scribe.model.SignatureType;
import org.scribe.oauth.OAuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component(name="com.adobe.granite.auth.oauth.provider", ds=0, metatype=1, configurationFactory=1)
@Properties(value={@Property(name="oauth.config.id"), @Property(name="oauth.client.id"), @Property(name="oauth.client.secret"), @Property(name="oauth.scope", unbounded=PropertyUnbounded.ARRAY), @Property(name="oauth.config.provider.id"), @Property(name="oauth.create.users", boolValue={0}), @Property(name="force.strict.username.matching", boolValue={0}), @Property(name="oauth.create.users.groups", unbounded=PropertyUnbounded.ARRAY), @Property(name="oauth.encode.userids", boolValue={0}), @Property(name="oauth.hash.userids", boolValue={0}), @Property(name="oauth.callBackUrl", value={""}), @Property(name="oauth.access.token.persist", boolValue={0}), @Property(name="oauth.access.token.persist.cookie", boolValue={0}), @Property(name="oauth.csrf.state.protection", boolValue={1}), @Property(name="oauth.redirect.request.params", boolValue={0})})
public class ProviderConfig {
    private boolean autoCreateUsers;
    private boolean forceStrictUsernameMatching;
    private boolean encodeUserIds;
    private boolean hashUserIds;
    private String[] autoCreateUsersGroups;
    private final String configId;
    private final String providerId;
    private String callBackUrl;
    private boolean saveAccessToken;
    private boolean saveAccessTokenCookie;
    private boolean enableCSRFStateProtection;
    private boolean persistRequestParamsCallbackUrl;
    private OauthTokenManager tokenManager;
    private final Logger log;
    private final String clientId;
    private final String clientSecret;
    private final String pid;
    private String scope;
    private int loginTimeout;
    private int cookieMaxAge;

    public ProviderConfig(String pid, int loginTimeout, int cookieMaxAge, Dictionary<String, Object> config, CryptoSupport cryptoSupport) throws ConfigurationException {
        String scope;
        this.log = LoggerFactory.getLogger(this.getClass());
        this.pid = pid;
        this.cookieMaxAge = cookieMaxAge;
        this.loginTimeout = loginTimeout;
        String configId = OsgiUtil.toString((Object)config.get("oauth.config.id"), (String)"");
        if (configId.length() == 0) {
            throw new ConfigurationException("oauth.config.id", "Config ID must not be empty");
        }
        String clientId = OsgiUtil.toString((Object)config.get("oauth.client.id"), (String)"");
        String clientSecret = OsgiUtil.toString((Object)config.get("oauth.client.secret"), (String)"");
        this.providerId = OsgiUtil.toString((Object)config.get("oauth.config.provider.id"), (String)"");
        if (this.providerId.length() == 0) {
            throw new ConfigurationException("oauth.config.provider.id", "Provider ID must not be empty");
        }
        String[] scopes = OsgiUtil.toStringArray((Object)config.get("oauth.scope"));
        if (scopes == null || scopes.length == 0) {
            scope = null;
        } else {
            StringBuilder result = new StringBuilder();
            String separator = "";
            for (String string : scopes) {
                result.append(separator);
                result.append(string);
                separator = ",";
            }
            scope = result.toString();
        }
        this.autoCreateUsers = OsgiUtil.toBoolean((Object)config.get("oauth.create.users"), (boolean)false);
        this.encodeUserIds = OsgiUtil.toBoolean((Object)config.get("oauth.encode.userids"), (boolean)false);
        this.hashUserIds = OsgiUtil.toBoolean((Object)config.get("oauth.hash.userids"), (boolean)false);
        this.forceStrictUsernameMatching = OsgiUtil.toBoolean((Object)config.get("force.strict.username.matching"), (boolean)false);
        this.autoCreateUsersGroups = OsgiUtil.toStringArray((Object)config.get("oauth.create.users.groups"), (String[])new String[0]);
        this.saveAccessToken = OsgiUtil.toBoolean((Object)config.get("oauth.access.token.persist"), (boolean)false);
        this.saveAccessTokenCookie = OsgiUtil.toBoolean((Object)config.get("oauth.access.token.persist.cookie"), (boolean)false);
        this.enableCSRFStateProtection = OsgiUtil.toBoolean((Object)config.get("oauth.csrf.state.protection"), (boolean)true);
        this.persistRequestParamsCallbackUrl = OsgiUtil.toBoolean((Object)config.get("oauth.redirect.request.params"), (boolean)false);
        String configCallBackUrl = OsgiUtil.toString((Object)config.get("oauth.callBackUrl"), (String)"");
        if (configCallBackUrl == null || configCallBackUrl.length() == 0) {
            configCallBackUrl = null;
        }
        this.callBackUrl = configCallBackUrl;
        this.configId = configId;
        this.clientId = clientId;
        this.clientSecret = clientSecret;
        this.scope = scope;
        this.tokenManager = new OauthTokenManager(cryptoSupport, loginTimeout, cookieMaxAge);
    }

    public String getConfigId() {
        return this.configId;
    }

    public String getPid() {
        return this.pid;
    }

    public String getProviderId() {
        return this.providerId;
    }

    public String getClientId() {
        return this.clientId;
    }

    public String getClientSecret() {
        return this.clientSecret;
    }

    public String getCallBackUrl() {
        return this.callBackUrl;
    }

    public boolean getAutoCreateUsers() {
        return this.autoCreateUsers;
    }

    public boolean getEncodeUserIds() {
        return this.encodeUserIds;
    }

    public boolean getHashUserIds() {
        return this.hashUserIds;
    }

    public boolean getForceStrictUsernameMatching() {
        return this.forceStrictUsernameMatching;
    }

    public String[] getAutoCreateUsersGroups() {
        return this.autoCreateUsersGroups;
    }

    public boolean getSaveAccessToken() {
        return this.saveAccessToken;
    }

    public boolean getSaveAccessTokenCookie() {
        return this.saveAccessTokenCookie;
    }

    public boolean getEnableCSRFStateProtection() {
        return this.enableCSRFStateProtection;
    }

    public boolean getPersistRequestParamsCallbackUrl() {
        return this.persistRequestParamsCallbackUrl;
    }

    public void setPersistRequestParamsCallbackUrl(boolean persistRequestParamsCallbackUrl) {
        this.persistRequestParamsCallbackUrl = persistRequestParamsCallbackUrl;
    }

    public OauthTokenManager getOAuthTokenManager() {
        return this.tokenManager;
    }

    public int getCookieMaxAge() {
        return this.cookieMaxAge;
    }

    public int getLoginTimeout() {
        return this.loginTimeout;
    }

    public OAuthConfig getOAuthConfig(String callbackUrl) {
        return new OAuthConfig(this.getClientId(), this.getClientSecret(), callbackUrl, SignatureType.QueryString, this.getScope(), null);
    }

    public OAuthService getOAuthService(Provider provider, String callbackUrl) {
        return provider.getApi().createService(this.getOAuthConfig(callbackUrl));
    }

    public String getScope() {
        return this.scope;
    }
}