Package org.togglz.shiro

Source Code of org.togglz.shiro.ShiroUserProvider

package org.togglz.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.togglz.core.user.FeatureUser;
import org.togglz.core.user.UserProvider;
import org.togglz.core.user.SimpleFeatureUser;

/**
*
* A {@link UserProvider} implementation for Apache Shiro.
*
* @author Christian Kaltepoth
*
*/
public class ShiroUserProvider implements UserProvider {

    private String featureAdminRole;

    /**
     * Constructor for the provider.
     *
     * @param featureAdminRole The role identifier to check whether the users are feature admins.
     */
    public ShiroUserProvider(String featureAdminRole) {
        this.featureAdminRole = featureAdminRole;
    }

    @Override
    public FeatureUser getCurrentUser() {

        // will always return a result
        Subject subject = SecurityUtils.getSubject();

        // only allow authenticated user
        if (subject.isAuthenticated()) {
            return new SimpleFeatureUser(subject.getPrincipal().toString(), subject.hasRole(featureAdminRole));
        }

        // user is not authenticated
        return null;

    }
}
TOP

Related Classes of org.togglz.shiro.ShiroUserProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.