use of digilib.util.XMLMapListLoader in project digilib by robcast.
the class OpenIdAuthnOps method init.
/* (non-Javadoc)
* @see digilib.auth.AuthnOps#init(digilib.conf.DigilibConfiguration)
*/
@Override
public void init(DigilibConfiguration dlConfig) throws AuthOpException {
configFile = dlConfig.getAsFile("auth-file");
logger.debug("openidauthnops.init (" + configFile + ")");
List<Map<String, String>> idpList;
try {
// load identity providers
XMLMapListLoader idpLoader = new XMLMapListLoader("digilib-oauth", "openid");
idpList = idpLoader.loadUri(configFile.toURI());
} catch (Exception e) {
throw new AuthOpException("ERROR loading auth config file: " + e);
}
if (idpList == null) {
throw new AuthOpException("ERROR unable to load auth config file!");
}
// create Map of roles by issuer
idpRoles = new HashMap<String, List<String>>();
// build a first pass JwtConsumer that doesn't check signatures or do any validation.
firstPassJwtConsumer = new JwtConsumerBuilder().setSkipAllValidators().setDisableRequireSignature().setSkipSignatureVerification().build();
// create Map of configured JwtConsumers by issuer
idpJwtConsumers = new HashMap<String, JwtConsumer>();
for (Map<String, String> idpDesc : idpList) {
String issuer = idpDesc.get("issuer");
if (issuer == null) {
logger.error("Missing issuer in openid tag!");
continue;
}
String clientid = idpDesc.get("clientid");
if (clientid == null) {
logger.error("Missing clientid in openid tag! (issuer: " + issuer + ")");
continue;
}
String rolestr = idpDesc.get("roles");
if (rolestr == null) {
logger.error("Missing roles in openid tag! (issuer: " + issuer + ")");
continue;
}
// split roles string into list
List<String> roles = Arrays.asList(rolestr.split(","));
String keytype = idpDesc.get("keytype");
if (keytype == null || !keytype.equals("jwk")) {
logger.error("Missing or invalid keytype in openid tag! (issuer: " + issuer + ")");
continue;
}
String keyData = idpDesc.get("_text");
if (keyData == null || keyData.length() == 0) {
logger.error("Missing key data in openid tag! (issuer: " + issuer + ")");
continue;
}
try {
// create key from JWK data
JsonWebKey jwk = JsonWebKey.Factory.newJwk(keyData);
// create second pass consumer for validation
JwtConsumer secondPassJwtConsumer = new JwtConsumerBuilder().setExpectedIssuer(issuer).setVerificationKey(jwk.getKey()).setRequireExpirationTime().setAllowedClockSkewInSeconds(300).setRequireSubject().setExpectedAudience(clientid).build();
// save consumer and roles
idpJwtConsumers.put(issuer, secondPassJwtConsumer);
idpRoles.put(issuer, roles);
logger.debug("Registered id provider '" + issuer + "'");
} catch (JoseException e) {
logger.error("Invalid key data in openid tag! (issuer: " + issuer + ")");
continue;
}
}
// set token cookie name
tokenCookieName = dlConfig.getAsString("authn-token-cookie");
}
Aggregations