Java tutorial
/* * Copyright (c) 2017 sainth (sainth@sainth.de) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package de.sainth.recipe.backend.security; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import java.util.Collections; import java.util.List; public class RecipeManagerAuthenticationToken implements Authentication { private final Long userId; private final List<SimpleGrantedAuthority> permissions; private final String role; private boolean authenticated; public RecipeManagerAuthenticationToken(Long userId, String role) { this.role = role; this.authenticated = true; this.userId = userId; this.permissions = Collections.singletonList(new SimpleGrantedAuthority(role)); } @Override public List<? extends GrantedAuthority> getAuthorities() { return permissions; } @Override public Object getCredentials() { return null; } @Override public Object getDetails() { return null; } @Override public Long getPrincipal() { return userId; } @Override public boolean isAuthenticated() { return authenticated; } @Override public void setAuthenticated(boolean authenticated) throws IllegalArgumentException { this.authenticated = authenticated; } @Override public String getName() { return null; } public String getRole() { return role; } }