org.apache.shiro.util.JdbcUtils Java Examples

The following examples show how to use org.apache.shiro.util.JdbcUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdbcPermissionDefinitionsLoader.java    From spring-boot-shiro with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: JdbcPermissionDefinitionsLoader.java    From utils with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: MyBatisRealm.java    From nano-framework with Apache License 2.0 4 votes vote down vote up
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;
}