Example usage for org.apache.shiro.subject SimplePrincipalCollection SimplePrincipalCollection

List of usage examples for org.apache.shiro.subject SimplePrincipalCollection SimplePrincipalCollection

Introduction

In this page you can find the example usage for org.apache.shiro.subject SimplePrincipalCollection SimplePrincipalCollection.

Prototype

public SimplePrincipalCollection(Collection principals, String realmName) 

Source Link

Usage

From source file:annis.security.ANNISUserRealm.java

License:Apache License

public void clearCacheForUser(String userName) {
    SimplePrincipalCollection principals = new SimplePrincipalCollection(userName,
            ANNISUserRealm.class.getName());
    clearCache(principals);//from   ww  w .j a  v a 2  s. c o  m
}

From source file:apm.modules.sys.security.SystemAuthorizingRealm.java

License:Open Source License

/**
 * ?????// w w  w .  ja  va2  s .  c om
 */
public void clearCachedAuthorizationInfo(String principal) {
    SimplePrincipalCollection principals = new SimplePrincipalCollection(principal, getName());
    clearCachedAuthorizationInfo(principals);
}

From source file:b4f.seguridad.SecurityAuthenticator.java

@Override
public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException {

    if (DEBUG) {// w w w  . j  a v a2 s.  co m
        System.out.println("[SECURITY AUTHENTICATOR] Autenticando: " + at);
    }

    //SE ACCEDI CON UN JWT TOKEN
    if (at instanceof JwtToken) {
        JwtToken authToken = (JwtToken) at;
        if (authToken.getToken() != null && !authToken.getToken().equals("")) {

            if (!authToken.validar()) {
                throw new AccountException("Token invalido.");
            }

            try {
                Usuario user = UsersManager.getUser(authToken.getUser());
                if (user == null)
                    throw new Exception("Token invalido");

                SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo();
                authenticationInfo.setPrincipals(new SimplePrincipalCollection(user, user.getUsuario()));
                return authenticationInfo;
            } catch (Exception ex) {
                Logger.getLogger(ShiroAuthorizingRealm.class.getName()).log(Level.SEVERE, null, ex);
                throw new AuthenticationException(ex.getMessage());
            }

        } else {
            throw new AccountException("Token invalido.");
        }
    }

    DefaultSecurityManager dsm = new DefaultSecurityManager(getRealm());
    AuthenticationInfo authenticationInfo = dsm.authenticate(at);
    if (DEBUG) {
        System.out.println("[SECURITY AUTHENTICATOR] " + authenticationInfo);
    }
    return authenticationInfo;

}

From source file:cn.powerdash.libsystem.common.security.SecurityContext.java

License:Open Source License

/**
 * Description: ??/*  w ww  .  j  av  a 2s. co  m*/
 * 
 * @param userId
 */
public static void clearAuthzCache(String userName) {
    RealmSecurityManager sm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    for (Realm realm : sm.getRealms()) {
        if (realm instanceof ShiroJdbcRealm) {
            ShiroJdbcRealm jdbcRealm = (ShiroJdbcRealm) realm;
            SimplePrincipalCollection spc = new SimplePrincipalCollection(userName, realm.getName());
            jdbcRealm.clearAuthorizationCache(spc);
        }
    }
    LOGGER.info("Authorization cache cleared for user: {}", userName);
}

From source file:cn.powerdash.libsystem.common.security.SecurityContext.java

License:Open Source License

/**
 * Description: ??//from   w  ww .  j  a  va 2 s .  c o m
 * 
 * @param userId
 */
public static void clearAuthcCache(String userName) {
    RealmSecurityManager sm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    for (Realm realm : sm.getRealms()) {
        if (realm instanceof ShiroJdbcRealm) {
            ShiroJdbcRealm jdbcRealm = (ShiroJdbcRealm) realm;
            SimplePrincipalCollection spc = new SimplePrincipalCollection(userName, realm.getName());
            jdbcRealm.clearAuthenticationCache(spc);
        }
    }
}

From source file:cn.ruiyi.base.service.shiro.ShiroDbRealm.java

License:Apache License

/**
 * ??./*ww w.  j  a  va  2s. co m*/
 */
public void clearCachedAuthorizationInfo(String principal) {
    SimplePrincipalCollection principals = new SimplePrincipalCollection(principal, getName());
    principals.getRealmNames();
    clearCachedAuthorizationInfo(principals);
}

From source file:co.edu.uniandes.csw.miso4204.security.auth.SecurityAuthenticator.java

public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException {
    JwtToken authToken = (JwtToken) at;/* ww  w .ja  v  a2 s.c o m*/
    if (authToken.getToken() != null) {
        if (!authToken.getToken().equals("")) {
            //Descifrar token y establecer info de usuario
            UserDTO user = decodeUser(authToken.getToken());
            if (validarToken(user)) {
                SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo();
                authenticationInfo.setPrincipals(new SimplePrincipalCollection(user, user.getUsername()));
                return authenticationInfo;
            }
        }
    }
    throw new AccountException("Token invalido.");
}

From source file:co.edu.uniandes.csw.uniandes.api.JWT.filter.JwtAuthenticator.java

public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException {
    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo();
    //      VerifyToken ver = new VerifyToken();
    //      UserDTO user = VerifyToken.getDataUser(at.toString());
    info.setPrincipals(new SimplePrincipalCollection("user", "user"));
    return info;/*from  w w  w.j  ava  2s.co  m*/
}

From source file:co.edu.uniandes.csw.uniandes.seguridad.JwtAuthenticator.java

public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException {
    JwtToken authToken = (JwtToken) at;//from w w  w.j  a v  a  2  s  .c o m
    if (authToken.getToken() != null) {
        //Descifrar token y establecer info de usuario
        if (validarToken(authToken.getToken())) {
            SimpleAuthenticationInfo info = new SimpleAuthenticationInfo();
            info.setPrincipals(new SimplePrincipalCollection(new Usuario("usuario1", "1"), "usuario1"));
            return info;
        }
    }
    throw new AccountException("Token invalido.");
}

From source file:co.edu.uniandes.hospitalkennedy.security.otro.SecurityAuthenticator.java

public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException {

    System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");

    JwtToken authToken = (JwtToken) at;//  www  .ja v  a2  s  .co m
    if (authToken.getToken() != null) {
        if (!authToken.getToken().equals("")) {
            //Descifrar token y establecer info de usuario
            UserDTO user = decodeUser(authToken.getToken());
            if (validarToken(user)) {
                SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo();
                authenticationInfo.setPrincipals(new SimplePrincipalCollection(user, user.getUsername()));

                PathInfo pathInfo = PathInfo.getInstance();

                if (!pathInfo.autenticar(user.getGrupo()))
                    throw new AccountException("Token invalido.");

                return authenticationInfo;
            }
        }
    }
    throw new AccountException("Token invalido.");
}