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

ec.gob.senescyt.sniese.commons.tests.helpers.ShiroRealmMock Maven / Gradle / Ivy

Go to download

Librería que contiene clases de uso comun para microservicios hechos en dropwizard

There is a newer version: 1.0.16
Show newest version
package ec.gob.senescyt.sniese.commons.tests.helpers;

import ec.gob.senescyt.sniese.commons.security.Usuario;
import ec.gob.senescyt.sniese.commons.security.UsuarioAutenticado;
import ec.gob.senescyt.sniese.commons.security.shiro.BearerToken;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

import static com.google.common.collect.Sets.newHashSet;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;

public class ShiroRealmMock extends AuthorizingRealm {
    @Override
    public boolean supports(AuthenticationToken authenticationToken) {
        return authenticationToken instanceof BearerToken;
    }
    
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return new SimpleAuthorizationInfo(newHashSet());
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        Usuario usuarioAutenticado = new UsuarioAutenticado(randomAlphabetic(10), randomAlphabetic(10));
        return new SimpleAuthenticationInfo(usuarioAutenticado, token.getCredentials(), getName());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy