org.pegadi.server.user.AbstractUserServer.java Source code

Java tutorial

Introduction

Here is the source code for org.pegadi.server.user.AbstractUserServer.java

Source

/**
 * Copyright 1999-2009 The Pegadi Team
 *
 * 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.
 */
package org.pegadi.server.user;

import no.dusken.common.model.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractUserServer implements UserServer, InitializingBean {

    private final Logger log = LoggerFactory.getLogger(getClass());

    protected DataSource dataSource;

    private List<String> godRoles = new ArrayList<String>();

    protected final int photographerRoleId = 4;
    protected final int journalistRoleId = 3;

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    /**
     * Returns <code>true</code> if the user is a superuser.
     *
     * @return superuser status.
     */
    public boolean isGod(Person person) {
        for (String godRole : godRoles) {
            if (this.hasRole(Integer.valueOf(godRole), person.getId())) {
                return true;
            }

        }
        return false;
    }

    public void setGodRoles(List<String> godRoles) {
        this.godRoles = godRoles;
    }

    public void afterPropertiesSet() throws Exception {
        if (godRoles == null)
            throw new IllegalArgumentException("No godroles set");
    }
}