ec.gob.senescyt.sniese.commons.tests.helpers.ShiroRealmMock Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sniese-commons-test Show documentation
Show all versions of sniese-commons-test Show documentation
Librería que contiene clases de uso comun para microservicios hechos en dropwizard
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());
}
}