diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2017-03-16 13:13:10 +0100 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2017-03-16 13:13:10 +0100 |
commit | 3a80aa7e900c77da7625886f72ee22666ecfae23 (patch) | |
tree | 5eef5ac02252c1f493908e34c773751987b257b1 /id/server/idserverlib/src/main | |
parent | 226db2c5c41c149256459bf18dff4585a07e5ea1 (diff) | |
parent | d69ba86f0855097e46e525794075f3c743e7facb (diff) | |
download | moa-id-spss-3a80aa7e900c77da7625886f72ee22666ecfae23.tar.gz moa-id-spss-3a80aa7e900c77da7625886f72ee22666ecfae23.tar.bz2 moa-id-spss-3a80aa7e900c77da7625886f72ee22666ecfae23.zip |
Merge branch 'Branch_MOA-ID-3.2.1' into development_preview
# Conflicts:
# id/server/moa-id-commons/pom.xml
# pom.xml
Diffstat (limited to 'id/server/idserverlib/src/main')
3 files changed, 61 insertions, 11 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java index 5b0f5115d..6f700d1cb 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/advancedlogging/StatisticLogger.java @@ -74,6 +74,7 @@ public class StatisticLogger implements IStatisticLogger{ private static final String MANTATORTYPE_NAT = "nat"; private static final int MAXERRORLENGTH = 200; + private static final int MAXOAIDENTIFIER_LENGTH = 254; private static final String ERRORTYPE_UNKNOWN = "unkown"; private static final String ERRORTYPE_BKU = "bku"; @@ -119,7 +120,7 @@ public class StatisticLogger implements IStatisticLogger{ //dblog.setOaID(dbOA.getHjid()); //log basic AuthInformation - dblog.setOaurlprefix(protocolRequest.getOAURL()); + dblog.setOaurlprefix(getMessageWithMaxLength(dbOA.getPublicURLPrefix(), MAXOAIDENTIFIER_LENGTH)); dblog.setOafriendlyName(dbOA.getFriendlyName()); boolean isbusinessservice = isBusinessService(dbOA); @@ -205,8 +206,14 @@ public class StatisticLogger implements IStatisticLogger{ } } } - - entityManager.persist(dblog); + + try { + entityManager.persist(dblog); + + } catch (Exception e) { + Logger.warn("Write 'success' statisticLog to database FAILED.", e); + + } } } @@ -227,8 +234,13 @@ public class StatisticLogger implements IStatisticLogger{ } - - entityManager.persist(dblog); + try { + entityManager.persist(dblog); + + } catch (Exception e) { + Logger.warn("Write 'error' statisticLog to database FAILED.", e); + + } } @@ -243,12 +255,15 @@ public class StatisticLogger implements IStatisticLogger{ dblog.setTimestamp(new Date()); - dblog.setOaurlprefix(errorRequest.getOAURL()); + dblog.setOaurlprefix(getMessageWithMaxLength(errorRequest.getOAURL(), MAXOAIDENTIFIER_LENGTH)); dblog.setProtocoltype(errorRequest.requestedModule()); dblog.setProtocolsubtype(errorRequest.requestedAction()); + generateErrorLogFormThrowable(throwable, dblog); + IOAAuthParameters dbOA = errorRequest.getOnlineApplicationConfiguration(); if (dbOA != null) { + dblog.setOaurlprefix(getMessageWithMaxLength(dbOA.getPublicURLPrefix(), MAXOAIDENTIFIER_LENGTH)); dblog.setOafriendlyName(dbOA.getFriendlyName()); dblog.setOatarget(dbOA.getTarget()); //dblog.setOaID(dbOA.getHjid()); @@ -280,11 +295,18 @@ public class StatisticLogger implements IStatisticLogger{ dblog.setMandatelogin(moasession.isMandateUsed()); } - generateErrorLogFormThrowable(throwable, dblog); + + } + + try { entityManager.persist(dblog); - + + } catch (Exception e) { + Logger.warn("Write 'error' statisticLog to database FAILED.", e); + } + } } @@ -296,6 +318,10 @@ public class StatisticLogger implements IStatisticLogger{ return false; } + private String getMessageWithMaxLength(String msg, int maxlength) { + return getErrorMessageWithMaxLength(msg, maxlength); + + } private String getErrorMessageWithMaxLength(String error, int maxlength) { if (error != null) { diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/utils/SAML2Utils.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/utils/SAML2Utils.java index 9d57c2bae..28a85b4af 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/utils/SAML2Utils.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/utils/SAML2Utils.java @@ -46,6 +46,8 @@ import org.opensaml.xml.io.Marshaller; import org.opensaml.xml.io.MarshallingException; import org.w3c.dom.Document; +import at.gv.egovernment.moa.id.util.Random; + public class SAML2Utils { public static <T> T createSAMLObject(final Class<T> clazz) { @@ -66,7 +68,19 @@ public class SAML2Utils { } public static String getSecureIdentifier() { - return idGenerator.generateIdentifier(); + return "_".concat(Random.nextHexRandom16()); + + /*Bug-Fix: There are open problems with RandomNumberGenerator via Java SPI and Java JDK 8.121 + * Generation of a 16bit Random identifier FAILES with an Caused by: java.lang.ArrayIndexOutOfBoundsException + * Caused by: java.lang.ArrayIndexOutOfBoundsException + at iaik.security.random.o.engineNextBytes(Unknown Source) + at iaik.security.random.SecRandomSpi.engineNextBytes(Unknown Source) + at java.security.SecureRandom.nextBytes(SecureRandom.java:468) + at org.opensaml.common.impl.SecureRandomIdentifierGenerator.generateIdentifier(SecureRandomIdentifierGenerator.java:62) + at org.opensaml.common.impl.SecureRandomIdentifierGenerator.generateIdentifier(SecureRandomIdentifierGenerator.java:56) + at at.gv.egovernment.moa.id.protocols.pvp2x.utils.SAML2Utils.getSecureIdentifier(SAML2Utils.java:69) + */ + //return idGenerator.generateIdentifier(); } private static SecureRandomIdentifierGenerator idGenerator; diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/Random.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/Random.java index ba45a3679..ac2b3c415 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/Random.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/util/Random.java @@ -114,11 +114,21 @@ public class Random { * * @return random hex encoded value [256bit] */ - public static String nextHexRandom() { + public static String nextHexRandom32() { return new String(Hex.encodeHex(nextByteRandom(32))); // 32 bytes = 256 bits } + /** + * Creates a new random number [128bit], and encode it as hex value. + * + * @return random hex encoded value [128bit] + */ + public static String nextHexRandom16() { + return new String(Hex.encodeHex(nextByteRandom(16))); // 16 bytes = 128 bits + + } + /** * Creates a new random number [64bit], to be used as an ID. * @@ -158,7 +168,7 @@ public class Random { * @param size Size of random number in bits * @return */ - private static byte[] nextByteRandom(int size) { + private static synchronized byte[] nextByteRandom(int size) { byte[] b = new byte[size]; random.nextBytes(b); return b; |