ScreensLoginModule.java 2.29 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Credentials
 *  javax.jcr.SimpleCredentials
 *  org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule
 *  org.apache.jackrabbit.oak.spi.security.authentication.PreAuthenticatedLogin
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.screens.sessions.impl.auth;

import com.adobe.cq.screens.sessions.impl.auth.ScreensCredentials;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import javax.jcr.Credentials;
import javax.jcr.SimpleCredentials;
import javax.security.auth.login.LoginException;
import org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule;
import org.apache.jackrabbit.oak.spi.security.authentication.PreAuthenticatedLogin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ScreensLoginModule
extends AbstractLoginModule {
    private static final Logger log = LoggerFactory.getLogger(ScreensLoginModule.class);
    private static final Set<Class> SUPPORTED_CREDENTIALS = Collections.singleton(ScreensCredentials.class);
    private String userId;

    protected Set<Class> getSupportedCredentials() {
        return SUPPORTED_CREDENTIALS;
    }

    public boolean login() throws LoginException {
        Credentials credentials = this.getCredentials();
        if (credentials instanceof ScreensCredentials) {
            this.userId = ((ScreensCredentials)credentials).getUserId();
            if (this.userId == null) {
                log.debug("Could not extract userId/credentials");
            } else {
                this.sharedState.put(SHARED_KEY_PRE_AUTH_LOGIN, new PreAuthenticatedLogin(this.userId));
                this.sharedState.put("org.apache.jackrabbit.credentials", new SimpleCredentials(this.userId, new char[0]));
                this.sharedState.put("javax.security.auth.login.name", this.userId);
                log.debug("login succeeded with trusted user: {}", (Object)this.userId);
            }
        }
        return false;
    }

    public boolean commit() throws LoginException {
        if (this.userId == null) {
            this.clearState();
        }
        return false;
    }

    protected void clearState() {
        this.userId = null;
        super.clearState();
    }
}