当前位置: 首页>>代码示例>>Java>>正文


Java JdbcUtils类代码示例

本文整理汇总了Java中org.apache.shiro.util.JdbcUtils的典型用法代码示例。如果您正苦于以下问题:Java JdbcUtils类的具体用法?Java JdbcUtils怎么用?Java JdbcUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JdbcUtils类属于org.apache.shiro.util包,在下文中一共展示了JdbcUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObject

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
@Override
public Map<String, String> getObject() throws Exception {
    Connection connection = dataSource.getConnection();
    PreparedStatement ps = connection.prepareStatement(sql);
    ResultSet rs = null;
    Map<String, String> filters = new LinkedHashMap<>();

    try {
        rs = ps.executeQuery();

        while (rs.next()) {

            String url = rs.getString(1);
            String permission = rs.getString(2);

            filters.put(url, String.format(PERMISSION_STRING, permission));
            LOGGER.debug("Load filter chain via JDBC: {} -> {}", url, permission);
        }
    } finally {
        JdbcUtils.closeResultSet(rs);
    }
    return filters;
}
 
开发者ID:johntostring,项目名称:spring-boot-shiro,代码行数:24,代码来源:JdbcPermissionDefinitionsLoader.java

示例2: getObject

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
public Map<String, String> getObject() throws Exception {
    Connection connection = dataSource.getConnection();
    PreparedStatement ps = connection.prepareStatement(sql);
    ResultSet rs = null;
    Map<String, String> filters = new LinkedHashMap<String, String>();

    try {
        rs = ps.executeQuery();
        while (rs.next()) {
            String url = rs.getString(1);
            String permission = rs.getString(2);
            filters.put(url, String.format(PERMISSION_STRING, permission));
        }
    } finally {
        JdbcUtils.closeResultSet(rs);
    }

    return filters;
}
 
开发者ID:storezhang,项目名称:utils,代码行数:20,代码来源:JdbcPermissionDefinitionsLoader.java

示例3: doGetAuthenticationInfo

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken token) throws AuthenticationException {

	Connection conn = null;
	try {
		conn = dataSource.getConnection();
		if (conn.isClosed())
			initializeDB();

	} catch (Exception e) {
		try {
			initializeDB();
		} catch (Exception ex) {
			Logger.logErr("RoleSecurityJDBCRealm could not re-init DB.", ex);
		}
	} finally {
		JdbcUtils.closeConnection(conn);
		conn = null;
	}

	return super.doGetAuthenticationInfo(token);
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:24,代码来源:RoleSecurityJdbcRealm.java

示例4: getUserIdFromUserName

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
private int getUserIdFromUserName(Connection conn, String username)
		throws SQLException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	int uid = -1;
	try {
		ps = conn.prepareStatement(USER_ID_QUERY);
		ps.setString(1, username);

		// Execute query
		rs = ps.executeQuery();
		rs.next();
		uid = rs.getInt(1);

	} finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(ps);
	}
	return uid;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:21,代码来源:RoleSecurityJdbcRealm.java

示例5: clearPrincipalCacheForUser

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
public boolean clearPrincipalCacheForUser(String username) {
	Connection conn = null;
	try {
		conn = dataSource.getConnection();
		if (conn.isClosed())
			initializeDB();

		int userid = getUserIdFromUserName(conn, username);
		cachedPermissions.remove(String.valueOf(userid));

	} catch (Exception e) {
		try {
			initializeDB();
		} catch (Exception ex) {
			Logger.logErr("RoleSecurityJDBCRealm could not re-init DB.", ex);
		}
	} finally {
		JdbcUtils.closeConnection(conn);
		conn = null;
	}

	return true;

}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:25,代码来源:RoleSecurityJdbcRealm.java

示例6: doGetAuthorizationInfo

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
@Override
public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {

    //null usernames are invalid
    if (principals == null) {
        throw new OAuth2AuthenticationException("PrincipalCollection method argument cannot be null.");
    }

    String username = (String) getAvailablePrincipal(principals);

    Connection conn = null;
    Set<String> roleNames = null;
    Set<String> permissions = null;
    try {
        conn = dataSource.getConnection();

        // Retrieve roles and permissions from database
        roleNames = getRoleNamesForUser(conn, username);
        if (permissionsLookupEnabled) {
            permissions = getPermissions(conn, username, roleNames);
        }

    } catch (SQLException e) {
        final String message = "There was a SQL error while authorizing user [" + username + "]";
        if (LOG.isErrorEnabled()) {
            LOG.error(message, e);
        }

        // Rethrow any SQL errors as an authorization exception
        throw new OAuth2AuthenticationException(message, e);
    } finally {
        JdbcUtils.closeConnection(conn);
    }

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
    info.setStringPermissions(permissions);
    return info;

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:40,代码来源:OAuth2JdbcRealm.java

示例7: doGetAuthorizationInfo

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
@Override
public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {

    //null usernames are invalid
    if (principals == null) {
        throw new OAuth2AuthenticationException("PrincipalCollection method argument cannot be null.");
    }

    String username = (String) getAvailablePrincipal(principals);

    Connection conn = null;
    Set<String> roleNames = null;
    Set<String> permissions = null;
    try {
        conn = dataSource.getConnection();

        // Retrieve roles and permissions from database
        roleNames = getRoleNamesForUser(conn, username);
        if (permissionsLookupEnabled) {
            permissions = getPermissions(conn, username, roleNames);
        }

    } catch (SQLException e) {
        final String message = "There was a SQL error while authorizing user [" + username + "]";
        if (log.isErrorEnabled()) {
            log.error(message, e);
        }

        // Rethrow any SQL errors as an authorization exception
        throw new OAuth2AuthenticationException(message, e);
    } finally {
        JdbcUtils.closeConnection(conn);
    }

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
    info.setStringPermissions(permissions);
    return info;

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:40,代码来源:OAuth2JdbcRealm.java

示例8: doGetAuthorizationInfo

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
/**
 * This implementation of the interface expects the principals collection to return a String username keyed off of
 * this realm's {@link #getName() name}
 *
 * @see #getAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {

    //null usernames are invalid
    if (principals == null) {
        throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
    }

    String username = (String) getAvailablePrincipal(principals);

    Connection conn = null;
    Set<String> roleNames = null;
    Set<String> permissions = null;
    try {
        conn = dataSource.getConnection();

        // Retrieve roles and permissions from database
        roleNames = getRoleNamesForUser(conn, username);
        if (permissionsLookupEnabled) {
            permissions = getPermissions(conn, username, roleNames);
        }

    } catch (SQLException e) {
        final String message = "There was a SQL error while authorizing user [" + username + "]";
        if (log.isErrorEnabled()) {
            log.error(message, e);
        }

        // Rethrow any SQL errors as an authorization exception
        throw new AuthorizationException(message, e);
    } finally {
        JdbcUtils.closeConnection(conn);
    }

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
    info.setStringPermissions(permissions);
    return info;

}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:46,代码来源:JdbcRealm.java

示例9: getRoleNamesForUser

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
protected Set<String> getRoleNamesForUser(Connection conn, String username) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;
    Set<String> roleNames = new LinkedHashSet<String>();
    try {
        ps = conn.prepareStatement(userRolesQuery);
        ps.setString(1, username);

        // Execute query
        rs = ps.executeQuery();

        // Loop over results and add each returned role to a set
        while (rs.next()) {

            String roleName = rs.getString(1);

            // Add the role to the list of names if it isn't null
            if (roleName != null) {
                roleNames.add(roleName);
            } else {
                if (log.isWarnEnabled()) {
                    log.warn("Null role name found while retrieving role names for user [" + username + "]");
                }
            }
        }
    } finally {
        JdbcUtils.closeResultSet(rs);
        JdbcUtils.closeStatement(ps);
    }
    return roleNames;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:32,代码来源:JdbcRealm.java

示例10: getPermissions

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
protected Set<String> getPermissions(Connection conn, String username, Collection<String> roleNames) throws SQLException {
    PreparedStatement ps = null;
    Set<String> permissions = new LinkedHashSet<String>();
    try {
        ps = conn.prepareStatement(permissionsQuery);
        for (String roleName : roleNames) {

            ps.setString(1, roleName);

            ResultSet rs = null;

            try {
                // Execute query
                rs = ps.executeQuery();

                // Loop over results and add each returned role to a set
                while (rs.next()) {

                    String permissionString = rs.getString(1);

                    // Add the permission to the set of permissions
                    permissions.add(permissionString);
                }
            } finally {
                JdbcUtils.closeResultSet(rs);
            }

        }
    } finally {
        JdbcUtils.closeStatement(ps);
    }

    return permissions;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:35,代码来源:JdbcRealm.java

示例11: getRoleNamesForUser

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
protected Set<String> getRoleNamesForUser(Connection conn, String username)
		throws SQLException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	Set<String> roleNames = new LinkedHashSet<String>();
	try {
		ps = conn.prepareStatement(userRolesQuery);
		ps.setString(1, username);

		// Execute query
		rs = ps.executeQuery();

		// Loop over results and add each returned role to a set
		while (rs.next()) {

			String roleName = rs.getString(1);

			// Add the role to the list of names if it isn't null
			if (roleName != null) {
				roleNames.add(roleName);
			} else {
				if (log.isWarnEnabled()) {
					log.warn("Null role name found while retrieving role names for user ["
							+ username + "]");
				}
			}
		}
	} finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(ps);
	}
	return roleNames;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:34,代码来源:JdbcRealm.java

示例12: doGetAuthenticationInfo

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
        String username = upToken.getUsername();

        // Null username is invalid
        if (username == null) {
            throw new AccountException("Null usernames are not allowed by this realm.");
        }

        Connection conn = null;
        SimpleAuthenticationInfo info = null;
        try {
            conn = dataSource.getConnection();

            String password = null;
            String salt = null;
            switch (saltStyle) {
            case NO_SALT:
                password = getPasswordForUser(conn, username)[0];
                break;
            case CRYPT:
                // TODO: separate password and hash from getPasswordForUser[0]
                throw new ConfigurationException("Not implemented yet");
                //break;
            case COLUMN:
                String[] queryResults = getPasswordForUser(conn, username);
                password = queryResults[0];
                salt = queryResults[1];
                break;
            case EXTERNAL:
                password = getPasswordForUser(conn, username)[0];
                salt = getSaltForUser(username);
            }

            if (password == null) {
                throw new UnknownAccountException("No account found for user [" + username + "]");
            }

            info = new SimpleAuthenticationInfo(username, password.toCharArray(), getName());
            
            if (salt != null) {
                info.setCredentialsSalt(ByteSource.Util.bytes(salt));
            }

        } catch (SQLException e) {
            final String message = "There was a SQL error while authenticating user [" + username + "]";
            if (log.isErrorEnabled()) {
                log.error(message, e);
            }

            // Rethrow any SQL errors as an authentication exception
            throw new AuthenticationException(message, e);
        } finally {
            JdbcUtils.closeConnection(conn);
        }

        return info;
    }
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:60,代码来源:JdbcRealm.java

示例13: getPasswordForUser

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
private String[] getPasswordForUser(Connection conn, String username) throws SQLException {

        String[] result;
        boolean returningSeparatedSalt = false;
        switch (saltStyle) {
        case NO_SALT:
        case CRYPT:
        case EXTERNAL:
            result = new String[1];
            break;
        default:
            result = new String[2];
            returningSeparatedSalt = true;
        }
        
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(authenticationQuery);
            ps.setString(1, username);

            // Execute query
            rs = ps.executeQuery();

            // Loop over results - although we are only expecting one result, since usernames should be unique
            boolean foundResult = false;
            while (rs.next()) {

                // Check to ensure only one row is processed
                if (foundResult) {
                    throw new AuthenticationException("More than one user row found for user [" + username + "]. Usernames must be unique.");
                }

                result[0] = rs.getString(1);
                if (returningSeparatedSalt) {
                    result[1] = rs.getString(2);
                }

                foundResult = true;
            }
        } finally {
            JdbcUtils.closeResultSet(rs);
            JdbcUtils.closeStatement(ps);
        }

        return result;
    }
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:48,代码来源:JdbcRealm.java

示例14: getPasswordForUser

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
private String[] getPasswordForUser(Connection conn, String username) throws SQLException {
    String[] result;
    boolean returningSeparatedSalt = false;
    switch (saltStyle) {
    case NO_SALT:
    case CRYPT:
    case EXTERNAL:
        result = new String[1];
        break;
    default:
        result = new String[2];
        returningSeparatedSalt = true;
    }
    
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = conn.prepareStatement(authenticationQuery);
        ps.setString(1, username);

        // Execute query
        rs = ps.executeQuery();

        // Loop over results - although we are only expecting one result, since usernames should be unique
        boolean foundResult = false;
        while (rs.next()) {

            // Check to ensure only one row is processed
            if (foundResult) {
                throw new AuthenticationException("More than one user row found for user [" + username + "]. Usernames must be unique.");
            }

            result[0] = rs.getString(1);
            if (returningSeparatedSalt) {
                result[1] = rs.getString(2);
            }

            foundResult = true;
        }
    } finally {
        JdbcUtils.closeResultSet(rs);
        JdbcUtils.closeStatement(ps);
    }

    return result;
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:47,代码来源:MyBatisRealm.java

示例15: getPasswordForUser

import org.apache.shiro.util.JdbcUtils; //导入依赖的package包/类
private String[] getPasswordForUser(Connection conn, String email)
    throws SQLException {
  String[] result;
  boolean returningSeparatedSalt = false;
  switch (saltStyle) {
  case NO_SALT:
  case CRYPT:
  case EXTERNAL:
    result = new String[1];
    break;
  default:
    result = new String[2];
    returningSeparatedSalt = true;
  }

  PreparedStatement ps = null;
  ResultSet rs = null;
  try {
    ps = conn.prepareStatement(authenticationQuery);
    ps.setString(1, email); // set email address

    // Loop over results - although we are only expecting one result,
    // since usernames should be unique
    rs = ps.executeQuery();
    boolean foundResult = false;
    while (rs.next()) {
      // Check to ensure only one row is processed
      if (foundResult) {
        throw new AuthenticationException(
            "More than one user row found for user [" + email
                + "]. Emails must be unique.");
      }

      result[0] = rs.getString(1);
      if (returningSeparatedSalt) {
        result[1] = rs.getString(2);
      }
      foundResult = true;
    }
  } finally {
    JdbcUtils.closeResultSet(rs);
    JdbcUtils.closeStatement(ps);
  }

  return result;
}
 
开发者ID:pires,项目名称:fabric8-cxf-shiro,代码行数:47,代码来源:SMRealm.java


注:本文中的org.apache.shiro.util.JdbcUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。