All Downloads are FREE. Search and download functionalities are using the official Maven repository.

act.controller.captcha.CaptchaManager Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package act.controller.captcha;

/*-
 * #%L
 * ACT Framework
 * %%
 * Copyright (C) 2014 - 2018 ActFramework
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import act.app.App;
import act.app.AppServiceBase;
import act.controller.captcha.render.CaptchaImageRender;
import act.util.Stateless;
import org.osgl.$;

import java.util.ArrayList;
import java.util.List;

@Stateless
public class CaptchaManager extends AppServiceBase {

    private List generators = new ArrayList<>();
    private List imageRender = new ArrayList<>();

    // so we can allow end to end test to by pass CAPTCHA protection
    private boolean disabled;

    public CaptchaManager(App app) {
        super(app);
    }

    public boolean disabled() {
        return disabled;
    }

    public void disable() {
        this.disabled = true;
    }

    public void enable() {
        this.disabled = false;
    }

    public void registerGenerator(CaptchaSessionGenerator generator) {
        generators.add(generator);
    }

    public void registerImageGenerator(CaptchaImageRender generator) {
        imageRender.add(generator);
    }

    @Override
    protected void releaseResources() {
        generators.clear();
    }

    public CaptchaSessionGenerator randomGenerator() {
        return $.random(generators);
    }

    public CaptchaImageRender randomImageRender() {
        return $.random(imageRender);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy