OAuth2AuthorizationServerImpl.java 2.56 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Session
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.jackrabbit.api.security.user.Authorizable
 *  org.apache.sling.jcr.api.SlingRepository
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.oauth.server.impl;

import com.adobe.granite.oauth.server.OAuth2AuthorizationServer;
import com.adobe.granite.oauth.server.impl.helper.OAuth2Helper;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Component(metatype=0)
public class OAuth2AuthorizationServerImpl
implements OAuth2AuthorizationServer {
    private final Logger logger;
    @Reference
    private SlingRepository repository;

    public OAuth2AuthorizationServerImpl() {
        this.logger = LoggerFactory.getLogger(this.getClass());
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public String getClientName(String clientId) {
        Session oauthServiceSession = null;
        try {
            oauthServiceSession = this.repository.loginService(null, null);
            Authorizable user = OAuth2Helper.getOAuthClientAuthorizable(oauthServiceSession, clientId);
            if (user != null) {
                String string = OAuth2Helper.getOAuthClientPropertyValue(user, clientId, "oauth:clientName");
                return string;
            }
            this.logger.debug("getClientName: Invalid value {} for parameter client_id", (Object)clientId);
            String string = null;
            return string;
        }
        catch (Exception e) {
            this.logger.error("exception while retrieving clientId, returning clientID ", (Throwable)e);
            String string = null;
            return string;
        }
        finally {
            if (oauthServiceSession != null) {
                oauthServiceSession.logout();
            }
        }
    }

    protected void bindRepository(SlingRepository slingRepository) {
        this.repository = slingRepository;
    }

    protected void unbindRepository(SlingRepository slingRepository) {
        if (this.repository == slingRepository) {
            this.repository = null;
        }
    }
}