Esempio n. 1
0
rampart_saml_token_t * AXIS2_CALL
create_saml_token(const axutil_env_t *env)
{
    oxs_sign_ctx_t *sign_ctx = NULL;
	oxs_x509_cert_t *cert = NULL;
	openssl_pkey_t *prv_key = NULL;
	rampart_saml_token_t *saml = NULL;

	axutil_date_time_t *time = NULL;
	saml_assertion_t *assertion = NULL;
	axiom_node_t *node = NULL;
    axis2_char_t *prv_key_file = NULL;
    axis2_char_t *certificate_file = NULL;
    /* 
     * Create a rampart_saml_token_t to give to the Rampart/C 
     * Here the token type is protection token.
     */    
	saml = rampart_saml_token_create(env, NULL, RAMPART_ST_CONFIR_TYPE_HOLDER_OF_KEY);
	time = axutil_date_time_create(env);
	assertion = saml_assertion_create(env);
	if (assertion)	
	{
		saml_assertion_set_minor_version(assertion, env, 1);		
		saml_assertion_set_issue_instant(assertion, env, time);
		saml_assertion_set_issuer(assertion, env, "http://ws.apache.org/rampart/c");	
		saml_assertion_add_condition(assertion, env, create_condition(env));
		saml_assertion_set_not_before(assertion, env, axutil_date_time_create(env));
		saml_assertion_add_statement(assertion, env, create_auth_statement(env, saml));
	}
    /* Load the private key from file*/
    prv_key_file = axutil_stracat(env, axis2c_home, PRIVATE_KEY_FILE);  
    certificate_file = axutil_stracat(env, axis2c_home, CERTIFICATE_FILE);
    prv_key = oxs_key_mgr_load_private_key_from_pem_file(env, prv_key_file, PRIVATE_KEY_PASSWORD);
    cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, certificate_file);

	sign_ctx = oxs_sign_ctx_create(env);
	saml_util_set_sig_ctx_defaults(sign_ctx, env, "AssertionID");
	oxs_sign_ctx_set_private_key(sign_ctx, env, prv_key);
    oxs_sign_ctx_set_certificate(sign_ctx, env, cert);
    saml_assertion_set_signature(assertion, env, sign_ctx);

	node = saml_assertion_to_om(assertion, NULL, env);	 
	rampart_saml_token_set_assertion(saml, env, node);
    rampart_saml_token_set_token_type(saml, env, RAMPART_ST_TYPE_PROTECTION_TOKEN);
	saml_assertion_free(assertion, env);
	return saml;
}
Esempio n. 2
0
axiom_node_t * AXIS2_CALL
create_saml_assertion(const axutil_env_t *env)
{
    saml_assertion_t *assertion = NULL;
    saml_attr_stmt_t *attr_stmt = NULL;
    saml_subject_t *subject = NULL;
    saml_named_id_t *named_id = NULL;
    saml_attr_t *attr = NULL;
    axiom_node_t *attr_val = NULL;
    axiom_element_t *e = NULL;
    saml_stmt_t *stmt = NULL;

    assertion = saml_assertion_create(env);
    attr_stmt = saml_attr_stmt_create(env);
    subject = saml_subject_create(env);

    saml_assertion_set_issue_instant(assertion, env, axutil_date_time_create(env));
    saml_assertion_set_issuer(assertion, env, "www.mrt.ac.lk");
    saml_assertion_set_minor_version(assertion, env, 1);

    saml_subject_add_confirmation(subject, env, SAML_SUB_CONFIRMATION_SENDER_VOUCHES);

    named_id = saml_named_id_create(env);
    saml_named_id_set_name(named_id, env, "cse07");
    saml_subject_set_named_id(subject, env, named_id);

    attr = saml_attr_create(env);
    saml_attr_set_name(attr, env, "csestudent");
    saml_attr_set_namespace(attr, env, "www.mrt.ac.lk/cse");
    e = axiom_element_create(env, NULL, "noofstudent", NULL, &attr_val);
    axiom_element_set_text(e, env, "10", attr_val);
    saml_attr_add_value(attr, env, attr_val); 
   
    saml_attr_stmt_set_subject(attr_stmt, env, subject);
    saml_attr_stmt_add_attribute(attr_stmt, env, attr);

    stmt = saml_stmt_create(env);
    saml_stmt_set_stmt(stmt, env, attr_stmt, SAML_STMT_ATTRIBUTESTATEMENT);

    saml_assertion_add_statement(assertion, env, stmt);
    return saml_assertion_to_om(assertion, NULL, env);
}
Esempio n. 3
0
axiom_node_t *
create_saml_token(axutil_env_t *env)
{
	axutil_date_time_t *time = NULL;
	saml_assertion_t *assertion = NULL;
	axiom_node_t *node = NULL;
	time = axutil_date_time_create(env);
	assertion = saml_assertion_create(env);
	if (assertion)	
	{
		saml_assertion_set_minor_version(assertion, env, 1);		
		saml_assertion_set_issue_instant(assertion, env, time);
		saml_assertion_set_issuer(assertion, env, "http://ws.apache.org/rampart/c");	
		saml_assertion_add_condition(assertion, env, create_condition(env));
		saml_assertion_set_not_before(assertion, env, axutil_date_time_create(env));
		saml_assertion_add_statement(assertion, env, create_auth_statement(env));
	}	
	node = saml_assertion_to_om(assertion, NULL, env);	 
	saml_assertion_free(assertion, env);
	return node;
}