com.pwsz.kutadaniel.controllers.SecurityHelper.java Source code

Java tutorial

Introduction

Here is the source code for com.pwsz.kutadaniel.controllers.SecurityHelper.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pwsz.kutadaniel.controllers;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

public class SecurityHelper {

    /**
     *
     * @param authentication authentication
     * @param rolename role name
     * @return whether it has a role
     */
    public static boolean hasRole(Authentication authentication, String rolename) {
        boolean result = false;
        for (GrantedAuthority authority : authentication.getAuthorities()) {
            if (authority.getAuthority().equals(rolename)) {
                result = true;
                break;
            }
        }
        return result;
    }

}