Skip to content

Commit

Permalink
working on fixing tests due to Spring 5.1 update. (+4 squashed commits)
Browse files Browse the repository at this point in the history
Squashed commits:
[7ee0672087] all security and gs-main tests passing after Spring 5.1 update.
[07a3c34364] Updating security to work with Spring 5.1. Tests passing here, build still broken.
[e6f1911908] Updating security to work with Spring 5.1.  Tests passing here, build still broken.
[ff8e63edb0] first updates to comply with Spring 5.1
  • Loading branch information
vickdw committed Oct 24, 2018
1 parent 73fe2c4 commit 9ee4b05
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 200 deletions.
286 changes: 135 additions & 151 deletions src/main/src/main/java/org/geoserver/data/jdbc/SpringUnWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@
*/
package org.geoserver.data.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.geotools.data.jdbc.datasource.UnWrapper;
import org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.JBossNativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.WebLogicNativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor;

// import org.springframework.jdbc.support.nativejdbc.XAPoolNativeJdbcExtractor;

/**
Expand All @@ -30,140 +14,140 @@
*
* @author Andrea Aime - OpenGeo
*/
public class SpringUnWrapper implements UnWrapper {

static final List<NativeJdbcExtractor> EXTRACTORS;

static {
List<NativeJdbcExtractor> extractors = new ArrayList<NativeJdbcExtractor>();

// some of these extractors will just blow up during initialization if
// the environment does not contain the classes they are looking for, so we
// guard their initialization and just skip them
try {
extractors.add(new CommonsDbcpNativeJdbcExtractor());
} catch (Throwable e) {
}
;
try {
extractors.add(new JBossNativeJdbcExtractor());
} catch (Throwable e) {
}
;
try {
extractors.add(new Jdbc4NativeJdbcExtractor());
} catch (Throwable e) {
}
;
try {
extractors.add(new SimpleNativeJdbcExtractor());
} catch (Throwable e) {
}
;
try {
extractors.add(new WebLogicNativeJdbcExtractor());
} catch (Throwable e) {
}
;
try {
extractors.add(new WebSphereNativeJdbcExtractor());
} catch (Throwable e) {
}
;
// try {
// extractors.add(new XAPoolNativeJdbcExtractor());
// } catch(Throwable e) {};
try {
extractors.add(new C3P0NativeJdbcExtractor());
} catch (Throwable e) {
}
;

// use a concurrent enabled data structure so that we can modify
// the order of extractors at run time, in a way that the extractors
// that can actually do the work end up first (the code is executed in
// tight loops over features and handling over and over exceptions is expensive)
EXTRACTORS = new CopyOnWriteArrayList<NativeJdbcExtractor>(extractors);
}

public boolean canUnwrap(Connection conn) {
Connection unwrapped = unwrapInternal(conn);
return unwrapped != null;
}

public Connection unwrap(Connection conn) {
Connection unwrapped = unwrapInternal(conn);
if (unwrapped != null) return unwrapped;
else
throw new IllegalArgumentException(
"This connection is not unwrappable, "
+ "check canUnwrap before calling unwrap");
}

private Connection unwrapInternal(Connection conn) {
for (int i = 0; i < EXTRACTORS.size(); i++) {
NativeJdbcExtractor extractor = EXTRACTORS.get(i);
try {
// the contract is that the original connection is returned
// if unwrapping was not possible
Connection unwrapped = extractor.getNativeConnection(conn);

if (conn != unwrapped) {
if (i != 0) {
// move the extractor to the top, so that we don't do
// many useless attempts at unwrapping with the others
// (this code is typically executed for each feature)
EXTRACTORS.add(0, extractor);
EXTRACTORS.remove(i);
}
return unwrapped;
}
} catch (Throwable t) {
// catch a throwable since some of the unwrappers do not blow up
// during initialization when the enviroment does not help, but
// they do at unwrap time and they throw Error suclasses
// We just want to skip the unwrapper and move on
}
}
return null;
}

public boolean canUnwrap(Statement st) {
Statement unwrapped = unwrapInternal(st);
return unwrapped != null;
}

public Statement unwrap(Statement statement) {
Statement unwrapped = unwrapInternal(statement);
if (unwrapped != null) return unwrapped;
else
throw new IllegalArgumentException(
"This statement is not unwrappable, "
+ "check canUnwrap before calling unwrap");
}

private Statement unwrapInternal(Statement st) {
for (int i = 0; i < EXTRACTORS.size(); i++) {
NativeJdbcExtractor extractor = EXTRACTORS.get(i);
try {
// the contract is that the original connection is returned
// if unwrapping was not possible
Statement unwrapped = extractor.getNativeStatement(st);
if (st != unwrapped) {
if (i != 0) {
// move the extractor to the beginning, so that we don't do
// many useless attempts at unwrapping with the others
// (this code is typically executed for each feature)
EXTRACTORS.add(0, extractor);
EXTRACTORS.remove(i);
}
public class SpringUnWrapper {

return unwrapped;
}
} catch (SQLException e) {
// no problem, skip it
}
}
return null;
}
// static final List<NativeJdbcExtractor> EXTRACTORS;
//
// static {
// List<NativeJdbcExtractor> extractors = new ArrayList<NativeJdbcExtractor>();
//
// // some of these extractors will just blow up during initialization if
// // the environment does not contain the classes they are looking for, so we
// // guard their initialization and just skip them
// try {
// extractors.add(new CommonsDbcpNativeJdbcExtractor());
// } catch (Throwable e) {
// }
// ;
// try {
// extractors.add(new JBossNativeJdbcExtractor());
// } catch (Throwable e) {
// }
// ;
// try {
// extractors.add(new Jdbc4NativeJdbcExtractor());
// } catch (Throwable e) {
// }
// ;
// try {
// extractors.add(new SimpleNativeJdbcExtractor());
// } catch (Throwable e) {
// }
// ;
// try {
// extractors.add(new WebLogicNativeJdbcExtractor());
// } catch (Throwable e) {
// }
// ;
// try {
// extractors.add(new WebSphereNativeJdbcExtractor());
// } catch (Throwable e) {
// }
// ;
// // try {
// // extractors.add(new XAPoolNativeJdbcExtractor());
// // } catch(Throwable e) {};
// try {
// extractors.add(new C3P0NativeJdbcExtractor());
// } catch (Throwable e) {
// }
// ;
//
// // use a concurrent enabled data structure so that we can modify
// // the order of extractors at run time, in a way that the extractors
// // that can actually do the work end up first (the code is executed in
// // tight loops over features and handling over and over exceptions is expensive)
// EXTRACTORS = new CopyOnWriteArrayList<NativeJdbcExtractor>(extractors);
// }
//
// public boolean canUnwrap(Connection conn) {
// Connection unwrapped = unwrapInternal(conn);
// return unwrapped != null;
// }
//
// public Connection unwrap(Connection conn) {
// Connection unwrapped = unwrapInternal(conn);
// if (unwrapped != null) return unwrapped;
// else
// throw new IllegalArgumentException(
// "This connection is not unwrappable, "
// + "check canUnwrap before calling unwrap");
// }
//
// private Connection unwrapInternal(Connection conn) {
// for (int i = 0; i < EXTRACTORS.size(); i++) {
// NativeJdbcExtractor extractor = EXTRACTORS.get(i);
// try {
// // the contract is that the original connection is returned
// // if unwrapping was not possible
// Connection unwrapped = extractor.getNativeConnection(conn);
//
// if (conn != unwrapped) {
// if (i != 0) {
// // move the extractor to the top, so that we don't do
// // many useless attempts at unwrapping with the others
// // (this code is typically executed for each feature)
// EXTRACTORS.add(0, extractor);
// EXTRACTORS.remove(i);
// }
// return unwrapped;
// }
// } catch (Throwable t) {
// // catch a throwable since some of the unwrappers do not blow up
// // during initialization when the enviroment does not help, but
// // they do at unwrap time and they throw Error suclasses
// // We just want to skip the unwrapper and move on
// }
// }
// return null;
// }
//
// public boolean canUnwrap(Statement st) {
// Statement unwrapped = unwrapInternal(st);
// return unwrapped != null;
// }
//
// public Statement unwrap(Statement statement) {
// Statement unwrapped = unwrapInternal(statement);
// if (unwrapped != null) return unwrapped;
// else
// throw new IllegalArgumentException(
// "This statement is not unwrappable, "
// + "check canUnwrap before calling unwrap");
// }
//
// private Statement unwrapInternal(Statement st) {
// for (int i = 0; i < EXTRACTORS.size(); i++) {
// NativeJdbcExtractor extractor = EXTRACTORS.get(i);
// try {
// // the contract is that the original connection is returned
// // if unwrapping was not possible
// Statement unwrapped = extractor.getNativeStatement(st);
// if (st != unwrapped) {
// if (i != 0) {
// // move the extractor to the beginning, so that we don't do
// // many useless attempts at unwrapping with the others
// // (this code is typically executed for each feature)
// EXTRACTORS.add(0, extractor);
// EXTRACTORS.remove(i);
// }
//
// return unwrapped;
// }
// } catch (SQLException e) {
// // no problem, skip it
// }
// }
// return null;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

package org.geoserver.security.password;

import java.io.IOException;
import java.security.Security;
import java.util.logging.Logger;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.geoserver.security.GeoServerSecurityManager;
import org.geoserver.security.GeoServerUserGroupService;
import org.geotools.util.logging.Logging;
import org.springframework.dao.DataAccessException;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.io.IOException;
import java.security.Security;
import java.util.logging.Logger;

/**
* Abstract base implementation, delegating the encoding to third party encoders implementing {@link
Expand Down Expand Up @@ -92,7 +93,8 @@ protected final PasswordEncoder getActualEncoder() {

@Override
public String encodePassword(String rawPass, Object salt) throws DataAccessException {
return doEncodePassword(getStringEncoder().encodePassword(rawPass, salt));
// return doEncodePassword(getStringEncoder().encodePassword(rawPass, salt));
return doEncodePassword(getStringEncoder().encode(rawPass));
}

@Override
Expand Down Expand Up @@ -122,7 +124,8 @@ StringBuffer initPasswordBuffer() {
public boolean isPasswordValid(String encPass, String rawPass, Object salt)
throws DataAccessException {
if (encPass == null) return false;
return getStringEncoder().isPasswordValid(stripPrefix(encPass), rawPass, salt);
// return getStringEncoder().isPasswordValid(stripPrefix(encPass), rawPass, salt);
return getStringEncoder().matches(encPass, rawPass);
}

@Override
Expand Down Expand Up @@ -157,7 +160,8 @@ public String decode(String encPass) throws UnsupportedOperationException {

@Override
public char[] decodeToCharArray(String encPass) throws UnsupportedOperationException {
throw new UnsupportedOperationException("decoding passwords not supported");
return encPass.toCharArray();
// throw new UnsupportedOperationException("decoding passwords not supported");
}

public String getPrefix() {
Expand Down

0 comments on commit 9ee4b05

Please sign in to comment.