// per-dir module configuration structure
struct shib_dir_config
{
+ SH_AP_TABLE* tSettings; // generic table of extensible settings
+
// RM Configuration
char* szAuthGrpFile; // Auth GroupFile name
- int bRequireAll; // all require directives must match, otherwise OR logic
+ int bRequireAll; // all "known" require directives must match, otherwise OR logic
+ int bAuthoritative; // allow htaccess plugin to DECLINE when authz fails
// Content Configuration
char* szApplicationId; // Shib applicationId value
extern "C" void* create_shib_dir_config (SH_AP_POOL* p, char* d)
{
shib_dir_config* dc=(shib_dir_config*)ap_pcalloc(p,sizeof(shib_dir_config));
+ dc->tSettings = NULL;
+ dc->szAuthGrpFile = NULL;
+ dc->bRequireAll = -1;
+ dc->bAuthoritative = -1;
+ dc->szApplicationId = NULL;
+ dc->szRequireWith = NULL;
+ dc->szRedirectToSSL = NULL;
dc->bOff = -1;
dc->bBasicHijack = -1;
dc->bRequireSession = -1;
dc->bExportAssertion = -1;
- dc->bRequireAll = -1;
- dc->szRedirectToSSL = NULL;
- dc->szAuthGrpFile = NULL;
- dc->szApplicationId = NULL;
- dc->szRequireWith = NULL;
dc->bUseEnvVars = -1;
dc->bUseHeaders = -1;
return dc;
shib_dir_config* parent=(shib_dir_config*)base;
shib_dir_config* child=(shib_dir_config*)sub;
+ // The child supersedes any matching table settings in the parent.
+ dc->tSettings = NULL;
+ if (parent->tSettings)
+ dc->tSettings = ap_copy_table(p, parent->tSettings);
+ if (child->tSettings) {
+ if (dc->tSettings)
+ ap_overlap_tables(dc->tSettings, child->tSettings, AP_OVERLAP_TABLES_SET);
+ else
+ dc->tSettings = ap_copy_table(p, child->tSettings);
+ }
+
if (child->szAuthGrpFile)
dc->szAuthGrpFile=ap_pstrdup(p,child->szAuthGrpFile);
else if (parent->szAuthGrpFile)
dc->bRequireSession=((child->bRequireSession==-1) ? parent->bRequireSession : child->bRequireSession);
dc->bExportAssertion=((child->bExportAssertion==-1) ? parent->bExportAssertion : child->bExportAssertion);
dc->bRequireAll=((child->bRequireAll==-1) ? parent->bRequireAll : child->bRequireAll);
+ dc->bAuthoritative=((child->bAuthoritative==-1) ? parent->bAuthoritative : child->bAuthoritative);
dc->bUseEnvVars=((child->bUseEnvVars==-1) ? parent->bUseEnvVars : child->bUseEnvVars);
dc->bUseHeaders=((child->bUseHeaders==-1) ? parent->bUseHeaders : child->bUseHeaders);
return dc;
return DECLINE_CMD;
}
+extern "C" const char* shib_table_set(cmd_parms* parms, shib_dir_config* dc, const char* arg1, const char* arg2)
+{
+ if (!dc->tSettings)
+ dc->tSettings = ap_make_table(parms->pool, 4);
+ ap_table_set(dc->tSettings, arg1, arg2);
+ return NULL;
+}
+
/********************************************************************************/
// Apache ShibTarget subclass(es) here.
pair<bool,long> res = sta.getServiceProvider().doAuthorization(sta);
if (res.first) return res.second;
- // We're all okay.
- return OK;
+ // The SP method should always return true, so if we get this far, something unusual happened.
+ // Just let Apache (or some other module) decide what to do.
+ return DECLINED;
}
catch (exception& e) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an exception: %s", e.what());
~htAccessControl() {}
Lockable* lock() {return this;}
void unlock() {}
- bool authorized(const SPRequest& request, const Session* session) const;
+ aclresult_t authorized(const SPRequest& request, const Session* session) const;
private:
bool checkAttribute(const SPRequest& request, const Attribute* attr, const char* toMatch, RegularExpression* re) const;
};
const PropertySet* s=reinterpret_cast<const PropertySet*>(m_propsKey->getData());
if (sta && !ns) {
// Override Apache-settable boolean properties.
- if (name && !strcmp(name,"requireSession") && sta->m_dc->bRequireSession==1)
- return make_pair(true,true);
- else if (name && !strcmp(name,"exportAssertion") && sta->m_dc->bExportAssertion==1)
- return make_pair(true,true);
+ if (name && !strcmp(name,"requireSession") && sta->m_dc->bRequireSession != -1)
+ return make_pair(true, sta->m_dc->bRequireSession==1);
+ else if (name && !strcmp(name,"exportAssertion") && sta->m_dc->bExportAssertion != -1)
+ return make_pair(true, sta->m_dc->bExportAssertion==1);
+ else if (sta->m_dc->tSettings) {
+ const char* prop = ap_table_get(sta->m_dc->tSettings, name);
+ if (prop)
+ return make_pair(true, !strcmp(prop, "true") || !strcmp(prop, "1") || !strcmp(prop, "On"));
+ }
}
return s ? s->getBool(name,ns) : make_pair(false,false);
}
return pair<bool,const char*>(true,sta->m_dc->szRequireWith);
else if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
return pair<bool,const char*>(true,sta->m_dc->szRedirectToSSL);
+ else if (sta->m_dc->tSettings) {
+ const char* prop = ap_table_get(sta->m_dc->tSettings, name);
+ if (prop)
+ return make_pair(true, prop);
+ }
}
return s ? s->getString(name,ns) : pair<bool,const char*>(false,NULL);
}
if (sta && !ns) {
// Override Apache-settable int properties.
if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
- return pair<bool,unsigned int>(true,strtol(sta->m_dc->szRedirectToSSL,NULL,10));
+ return pair<bool,unsigned int>(true, strtol(sta->m_dc->szRedirectToSSL, NULL, 10));
+ else if (sta->m_dc->tSettings) {
+ const char* prop = ap_table_get(sta->m_dc->tSettings, name);
+ if (prop)
+ return make_pair(true, strtol(prop, NULL, 10));
+ }
}
return s ? s->getUnsignedInt(name,ns) : pair<bool,unsigned int>(false,0);
}
// Override Apache-settable int properties.
if (name && !strcmp(name,"redirectToSSL") && sta->m_dc->szRedirectToSSL)
return pair<bool,int>(true,atoi(sta->m_dc->szRedirectToSSL));
+ else if (sta->m_dc->tSettings) {
+ const char* prop = ap_table_get(sta->m_dc->tSettings, name);
+ if (prop)
+ return make_pair(true, atoi(prop));
+ }
}
return s ? s->getInt(name,ns) : pair<bool,int>(false,0);
}
const vector<string>& vals = attr->getSerializedValues();
for (vector<string>::const_iterator v=vals.begin(); v!=vals.end(); ++v) {
if (re) {
- auto_ptr<XMLCh> trans(fromUTF8(v->c_str()));
+ auto_arrayptr<XMLCh> trans(fromUTF8(v->c_str()));
if (re->matches(trans.get())) {
request.log(SPRequest::SPDebug,
string("htAccessControl plugin expecting regexp ") + toMatch + ", got " + *v + ": authorization granted"
return false;
}
-bool htAccessControl::authorized(const SPRequest& request, const Session* session) const
+AccessControl::aclresult_t htAccessControl::authorized(const SPRequest& request, const Session* session) const
{
// Make sure the object is our type.
const ShibTargetApache* sta=dynamic_cast<const ShibTargetApache*>(&request);
const array_header* reqs_arr=ap_requires(sta->m_req);
if (!reqs_arr)
- return true;
+ return shib_acl_indeterminate; // should never happen
require_line* reqs=(require_line*)reqs_arr->elts;
#define SHIB_AP_CHECK_IS_OK { \
if (sta->m_dc->bRequireAll < 1) \
- return true; \
+ return shib_acl_true; \
auth_OK[x] = true; \
continue; \
}
request.log(SPRequest::SPDebug,"htAccessControl plugin accepting valid-user based on active session");
SHIB_AP_CHECK_IS_OK;
}
- else
+ else {
request.log(SPRequest::SPError,"htAccessControl plugin rejecting access for valid-user rule, no session is active");
+ }
}
else if (!strcmp(w,"user") && !remote_user.empty()) {
bool regexp=false;
if (regexp) {
try {
// To do regex matching, we have to convert from UTF-8.
- auto_ptr<XMLCh> trans(fromUTF8(w));
+ auto_arrayptr<XMLCh> trans(fromUTF8(w));
RegularExpression re(trans.get());
- auto_ptr<XMLCh> trans2(fromUTF8(remote_user.c_str()));
+ auto_arrayptr<XMLCh> trans2(fromUTF8(remote_user.c_str()));
if (re.matches(trans2.get())) {
request.log(SPRequest::SPDebug, string("htAccessControl plugin accepting user (") + w + ")");
SHIB_AP_CHECK_IS_OK;
}
}
}
+ else if (!strcmp(w,"authnContextClassRef")) {
+ const char* ref = session->getAuthnContextClassRef();
+ while (ref && *t) {
+ w=ap_getword_conf(sta->m_req->pool,&t);
+ if (!strcmp(w, ref)) {
+ request.log(SPRequest::SPDebug, string("htAccessControl plugin accepting authnContextClassRef (") + w + ")");
+ SHIB_AP_CHECK_IS_OK;
+ }
+ }
+ }
+ else if (!strcmp(w,"authnContextDeclRef")) {
+ const char* ref = session->getAuthnContextDeclRef();
+ while (ref && *t) {
+ w=ap_getword_conf(sta->m_req->pool,&t);
+ if (!strcmp(w, ref)) {
+ request.log(SPRequest::SPDebug, string("htAccessControl plugin accepting authnContextDeclRef (") + w + ")");
+ SHIB_AP_CHECK_IS_OK;
+ }
+ }
+ }
else {
// Map alias in rule to the attribute.
if (!session) {
auto_ptr<RegularExpression> re;
if (regexp) {
delete re.release();
- auto_ptr<XMLCh> trans(fromUTF8(w));
+ auto_arrayptr<XMLCh> trans(fromUTF8(w));
auto_ptr<xercesc::RegularExpression> temp(new xercesc::RegularExpression(trans.get()));
re=temp;
}
}
}
- // check if all require directives are true
+ // If we get here, we either "failed" or we're in require all mode.
bool auth_all_OK = true;
for (int i= 0; i<reqs_arr->nelts; i++) {
auth_all_OK &= auth_OK[i];
}
if (auth_all_OK || !method_restricted)
- return true;
+ return shib_acl_true;
- return false;
+ return (sta->m_dc->bAuthoritative != 0) ? shib_acl_false : shib_acl_indeterminate;
}
SPConfig::Caching |
SPConfig::RequestMapping |
SPConfig::InProcess |
- SPConfig::Logging
+ SPConfig::Logging |
+ SPConfig::Handlers
);
if (!g_Config->init(g_szSchemaDir)) {
ap_log_error(APLOG_MARK,APLOG_CRIT|APLOG_NOERRNO,SH_AP_R(s),"shib_child_init() failed to initialize libraries");
(void *) XtOffsetOf (shib_server_config, szScheme),
RSRC_CONF, TAKE1, "URL scheme to force into generated URLs for a vhost"},
+ {"ShibRequestSetting", (config_fn_t)shib_table_set, NULL,
+ OR_AUTHCFG, TAKE2, "Set arbitrary Shibboleth request property for content"},
+
{"ShibDisable", (config_fn_t)ap_set_flag_slot,
(void *) XtOffsetOf (shib_dir_config, bOff),
OR_AUTHCFG, FLAG, "Disable all Shib module activity here to save processing effort"},
{"ShibRequireAll", (config_fn_t)ap_set_flag_slot,
(void *) XtOffsetOf (shib_dir_config, bRequireAll),
OR_AUTHCFG, FLAG, "All require directives must match"},
+ {"AuthzShibAuthoritative", (config_fn_t)ap_set_flag_slot,
+ (void *) XtOffsetOf (shib_dir_config, bAuthoritative),
+ OR_AUTHCFG, FLAG, "Allow failed mod_shib htaccess authorization to fall through to other modules"},
{"ShibUseEnvironment", (config_fn_t)ap_set_flag_slot,
(void *) XtOffsetOf (shib_dir_config, bUseEnvVars),
OR_AUTHCFG, FLAG, "Export attributes using environment variables (default)"},
extern "C" {
static command_rec shib_cmds[] = {
- AP_INIT_TAKE1("ShibConfig",
- (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
- RSRC_CONF, "Path to shibboleth.xml config file"),
- AP_INIT_TAKE1("ShibCatalogs",
- (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
- RSRC_CONF, "Paths of XML schema catalogs"),
- AP_INIT_TAKE1("ShibSchemaDir",
- (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
- RSRC_CONF, "Paths of XML schema catalogs (deprecated in favor of ShibCatalogs)"),
-
- AP_INIT_TAKE1("ShibURLScheme",
- (config_fn_t)shib_set_server_string_slot,
- (void *) offsetof (shib_server_config, szScheme),
- RSRC_CONF, "URL scheme to force into generated URLs for a vhost"),
-
- AP_INIT_FLAG("ShibDisable", (config_fn_t)ap_set_flag_slot,
+ AP_INIT_TAKE1("ShibConfig", (config_fn_t)ap_set_global_string_slot, &g_szSHIBConfig,
+ RSRC_CONF, "Path to shibboleth.xml config file"),
+ AP_INIT_TAKE1("ShibCatalogs", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
+ RSRC_CONF, "Paths of XML schema catalogs"),
+ AP_INIT_TAKE1("ShibSchemaDir", (config_fn_t)ap_set_global_string_slot, &g_szSchemaDir,
+ RSRC_CONF, "Paths of XML schema catalogs (deprecated in favor of ShibCatalogs)"),
+
+ AP_INIT_TAKE1("ShibURLScheme", (config_fn_t)shib_set_server_string_slot,
+ (void *) offsetof (shib_server_config, szScheme),
+ RSRC_CONF, "URL scheme to force into generated URLs for a vhost"),
+
+ AP_INIT_TAKE2("ShibRequestSetting", (config_fn_t)shib_table_set, NULL,
+ OR_AUTHCFG, "Set arbitrary Shibboleth request property for content"),
+
+ AP_INIT_FLAG("ShibDisable", (config_fn_t)ap_set_flag_slot,
(void *) offsetof (shib_dir_config, bOff),
OR_AUTHCFG, "Disable all Shib module activity here to save processing effort"),
- AP_INIT_TAKE1("ShibApplicationId", (config_fn_t)ap_set_string_slot,
+ AP_INIT_TAKE1("ShibApplicationId", (config_fn_t)ap_set_string_slot,
(void *) offsetof (shib_dir_config, szApplicationId),
OR_AUTHCFG, "Set Shibboleth applicationId property for content"),
- AP_INIT_FLAG("ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
+ AP_INIT_FLAG("ShibBasicHijack", (config_fn_t)ap_set_flag_slot,
(void *) offsetof (shib_dir_config, bBasicHijack),
OR_AUTHCFG, "Respond to AuthType Basic and convert to shibboleth"),
- AP_INIT_FLAG("ShibRequireSession", (config_fn_t)ap_set_flag_slot,
+ AP_INIT_FLAG("ShibRequireSession", (config_fn_t)ap_set_flag_slot,
(void *) offsetof (shib_dir_config, bRequireSession),
OR_AUTHCFG, "Initiates a new session if one does not exist"),
- AP_INIT_TAKE1("ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
+ AP_INIT_TAKE1("ShibRequireSessionWith", (config_fn_t)ap_set_string_slot,
(void *) offsetof (shib_dir_config, szRequireWith),
OR_AUTHCFG, "Initiates a new session if one does not exist using a specific SessionInitiator"),
- AP_INIT_FLAG("ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
+ AP_INIT_FLAG("ShibExportAssertion", (config_fn_t)ap_set_flag_slot,
(void *) offsetof (shib_dir_config, bExportAssertion),
OR_AUTHCFG, "Export SAML attribute assertion(s) to Shib-Attributes header"),
- AP_INIT_TAKE1("ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
+ AP_INIT_TAKE1("ShibRedirectToSSL", (config_fn_t)ap_set_string_slot,
(void *) offsetof (shib_dir_config, szRedirectToSSL),
OR_AUTHCFG, "Redirect non-SSL requests to designated port"),
- AP_INIT_TAKE1("AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
+ AP_INIT_TAKE1("AuthGroupFile", (config_fn_t)shib_ap_set_file_slot,
(void *) offsetof (shib_dir_config, szAuthGrpFile),
OR_AUTHCFG, "Text file containing group names and member user IDs"),
- AP_INIT_FLAG("ShibRequireAll", (config_fn_t)ap_set_flag_slot,
+ AP_INIT_FLAG("ShibRequireAll", (config_fn_t)ap_set_flag_slot,
(void *) offsetof (shib_dir_config, bRequireAll),
OR_AUTHCFG, "All require directives must match"),
- AP_INIT_FLAG("ShibUseEnvironment", (config_fn_t)ap_set_flag_slot,
+ AP_INIT_FLAG("AuthzShibAuthoritative", (config_fn_t)ap_set_flag_slot,
+ (void *) offsetof (shib_dir_config, bAuthoritative),
+ OR_AUTHCFG, "Allow failed mod_shib htaccess authorization to fall through to other modules"),
+ AP_INIT_FLAG("ShibUseEnvironment", (config_fn_t)ap_set_flag_slot,
(void *) offsetof (shib_dir_config, bUseEnvVars),
OR_AUTHCFG, "Export attributes using environment variables (default)"),
- AP_INIT_FLAG("ShibUseHeaders", (config_fn_t)ap_set_flag_slot,
+ AP_INIT_FLAG("ShibUseHeaders", (config_fn_t)ap_set_flag_slot,
(void *) offsetof (shib_dir_config, bUseHeaders),
OR_AUTHCFG, "Export attributes using custom HTTP headers"),
- {NULL}
+ {NULL}
};
module AP_MODULE_DECLARE_DATA mod_shib = {