diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-09-11 18:23:33 +0200 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-09-11 18:23:33 +0200 |
commit | 3536b99c17250772f253ea5925da72a29e327c58 (patch) | |
tree | 672cd61bd324e845e322c518223a14e0b1d82fbd /id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls | |
parent | aa1dda4e14e7aebd3ec0df5e50493d273a65d999 (diff) | |
download | moa-id-spss-3536b99c17250772f253ea5925da72a29e327c58.tar.gz moa-id-spss-3536b99c17250772f253ea5925da72a29e327c58.tar.bz2 moa-id-spss-3536b99c17250772f253ea5925da72a29e327c58.zip |
move authentication protocol implementation to separate modules.
authentication protocol modules are loaded by SPI now.
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls')
2 files changed, 63 insertions, 27 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java index f54cffc54..11fa2bb42 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java @@ -24,6 +24,7 @@ package at.gv.egovernment.moa.id.moduls; import java.io.IOException; import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collection; @@ -96,7 +97,6 @@ import at.gv.egovernment.moa.id.protocols.pvp2x.messages.MOARequest; import at.gv.egovernment.moa.id.protocols.pvp2x.metadata.MOAMetadataProvider; import at.gv.egovernment.moa.id.protocols.pvp2x.utils.MOASAMLSOAPClient; import at.gv.egovernment.moa.id.protocols.pvp2x.utils.SAML2Utils; -import at.gv.egovernment.moa.id.protocols.stork2.MOASTORKRequest; import at.gv.egovernment.moa.id.storage.AssertionStorage; import at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage; import at.gv.egovernment.moa.id.util.MOAIDMessageProvider; @@ -468,15 +468,33 @@ public class AuthenticationManager extends MOAIDAuthConstants { AuthnContextClassRef authnClassRef = SAML2Utils.createSAMLObject(AuthnContextClassRef.class); + //check if STORK protocol module is in ClassPath + Object storkRequst = null; + Integer storkSecClass = null; + try { + storkRequst = Class.forName("at.gv.egovernment.moa.id.protocols.stork2.MOASTORKRequest").newInstance(); + if (storkRequst != null && + target.getClass().isInstance(storkRequst)) { + Object storkAuthnRequest = target.getClass().getMethod("getStorkAuthnRequest", null).invoke(target, null); + storkSecClass = (Integer) storkAuthnRequest.getClass().getMethod("getQaa", null).invoke(storkAuthnRequest, null); + + } + + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | java.lang.SecurityException ex) { + + + } + + if (sp != null && sp.isSTORKPVPGateway()){ //use PVP SecClass instead of STORK QAA level String secClass = null; - if (target instanceof MOASTORKRequest) { + if (storkRequst != null && + target.getClass().isInstance(storkRequst)) { - try { - MOASTORKRequest storkReq = (MOASTORKRequest) target; + try { secClass = PVPtoSTORKMapper.getInstance().mapToSecClass( - PVPConstants.STORK_QAA_PREFIX + storkReq.getStorkAuthnRequest().getQaa()); + PVPConstants.STORK_QAA_PREFIX + String.valueOf(storkSecClass)); } catch (Exception e) { Logger.warn("STORK-QAA level can not read from STORK request. Use default QAA 4", e); @@ -490,12 +508,12 @@ public class AuthenticationManager extends MOAIDAuthConstants { authnClassRef.setAuthnContextClassRef("http://www.ref.gv.at/ns/names/agiz/pvp/secclass/0-3"); } else { - if (target instanceof MOASTORKRequest) { + if (storkRequst != null && + target.getClass().isInstance(storkRequst)) { //use requested QAA level from STORK request try { - MOASTORKRequest storkReq = (MOASTORKRequest) target; authnClassRef.setAuthnContextClassRef( - PVPConstants.STORK_QAA_PREFIX + storkReq.getStorkAuthnRequest().getQaa()); + PVPConstants.STORK_QAA_PREFIX + String.valueOf(storkSecClass)); Logger.debug("Use STORK-QAA level " + authnClassRef.getAuthnContextClassRef() + " from STORK request"); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java index 4a1da76e2..e65d77326 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java @@ -25,20 +25,23 @@ package at.gv.egovernment.moa.id.moduls; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.ServiceLoader; import at.gv.egovernment.moa.logging.Logger; public class ModulStorage { - private static final String[] modulClasses = new String[]{ - "at.gv.egovernment.moa.id.protocols.saml1.SAML1Protocol", - "at.gv.egovernment.moa.id.protocols.pvp2x.PVP2XProtocol", - "at.gv.egovernment.moa.id.protocols.stork2.STORKProtocol", - "at.gv.egovernment.moa.id.protocols.oauth20.protocol.OAuth20Protocol" - }; - +// private static final String[] modulClasses = new String[]{ +//// "at.gv.egovernment.moa.id.protocols.saml1.SAML1Protocol", +// "at.gv.egovernment.moa.id.protocols.pvp2x.PVP2XProtocol", +// "at.gv.egovernment.moa.id.protocols.stork2.STORKProtocol", +// "at.gv.egovernment.moa.id.protocols.oauth20.protocol.OAuth20Protocol" +// }; + private static ServiceLoader<IModulInfo> protocolModuleLoader = + ServiceLoader.load(IModulInfo.class); private static List<IModulInfo> registeredModules = new ArrayList<IModulInfo>(); + public static List<IModulInfo> getAllModules() { return registeredModules; @@ -56,20 +59,35 @@ public class ModulStorage { } static { - Logger.info("Loading modules:"); - for(int i = 0; i < modulClasses.length; i++) { - String modulClassName = modulClasses[i]; - try { - @SuppressWarnings("unchecked") - Class<IModulInfo> moduleClass = (Class<IModulInfo>)Class.forName(modulClassName); - IModulInfo module = moduleClass.newInstance(); - Logger.info("Loading Modul Information: " + module.getName()); - registeredModules.add(module); - } catch(Throwable e) { - Logger.error("Check configuration! " + modulClassName + - " is not a valid IModulInfo", e); + Logger.info("Loading protocol modules:"); + if (protocolModuleLoader != null ) { + Iterator<IModulInfo> moduleLoaderInterator = protocolModuleLoader.iterator(); + while (moduleLoaderInterator.hasNext()) { + try { + IModulInfo modul = moduleLoaderInterator.next(); + Logger.info("Loading Modul Information: " + modul.getName()); + registeredModules.add(modul); + + } catch(Throwable e) { + Logger.error("Check configuration! " + "Some protocol modul" + + " is not a valid IModulInfo", e); + } } } + +// for(int i = 0; i < modulClasses.length; i++) { +// String modulClassName = modulClasses[i]; +// try { +// @SuppressWarnings("unchecked") +// Class<IModulInfo> moduleClass = (Class<IModulInfo>)Class.forName(modulClassName); +// IModulInfo module = moduleClass.newInstance(); +// Logger.info("Loading Modul Information: " + module.getName()); +// registeredModules.add(module); +// } catch(Throwable e) { +// Logger.error("Check configuration! " + modulClassName + +// " is not a valid IModulInfo", e); +// } +// } Logger.info("Loading modules done"); } |