~ubuntu-branches/ubuntu/utopic/lasso/utopic-proposed

« back to all changes in this revision

Viewing changes to lasso/protocols/elements/authentication_statement.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2004-09-13 09:26:34 UTC
  • Revision ID: james.westby@ubuntu.com-20040913092634-01vdfl8j9cp94exa
Tags: upstream-0.4.1
ImportĀ upstreamĀ versionĀ 0.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: authentication_statement.c,v 1.15 2004/09/01 09:59:53 fpeters Exp $ 
 
2
 *
 
3
 * Lasso - A free implementation of the Liberty Alliance specifications.
 
4
 *
 
5
 * Copyright (C) 2004 Entr'ouvert
 
6
 * http://lasso.entrouvert.org
 
7
 * 
 
8
 * Authors: Valery Febvre   <vfebvre@easter-eggs.com>
 
9
 *          Nicolas Clapies <nclapies@entrouvert.com>
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify
 
12
 * it under the terms of the GNU General Public License as published by
 
13
 * the Free Software Foundation; either version 2 of the License, or
 
14
 * (at your option) any later version.
 
15
 * 
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU General Public License
 
22
 * along with this program; if not, write to the Free Software
 
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 */
 
25
 
 
26
#include <lasso/protocols/elements/authentication_statement.h>
 
27
 
 
28
/*****************************************************************************/
 
29
/* public methods                                                            */
 
30
/*****************************************************************************/
 
31
 
 
32
/*****************************************************************************/
 
33
/* instance and class init functions                                         */
 
34
/*****************************************************************************/
 
35
 
 
36
static void
 
37
lasso_authentication_statement_instance_init(LassoAuthenticationStatement *authentication_statement)
 
38
{
 
39
}
 
40
 
 
41
static void
 
42
lasso_authentication_statement_class_init(LassoAuthenticationStatementClass *class)
 
43
{
 
44
}
 
45
 
 
46
GType lasso_authentication_statement_get_type() {
 
47
  static GType this_type = 0;
 
48
 
 
49
  if (!this_type) {
 
50
    static const GTypeInfo this_info = {
 
51
      sizeof (LassoAuthenticationStatementClass),
 
52
      NULL,
 
53
      NULL,
 
54
      (GClassInitFunc) lasso_authentication_statement_class_init,
 
55
      NULL,
 
56
      NULL,
 
57
      sizeof(LassoAuthenticationStatement),
 
58
      0,
 
59
      (GInstanceInitFunc) lasso_authentication_statement_instance_init,
 
60
    };
 
61
    
 
62
    this_type = g_type_register_static(LASSO_TYPE_LIB_AUTHENTICATION_STATEMENT,
 
63
                                       "LassoAuthenticationStatement",
 
64
                                       &this_info, 0);
 
65
  }
 
66
  return this_type;
 
67
}
 
68
 
 
69
LassoNode*
 
70
lasso_authentication_statement_new(const xmlChar           *authenticationMethod,
 
71
                                   const xmlChar           *reauthenticateOnOrAfter,
 
72
                                   LassoSamlNameIdentifier *sp_identifier,
 
73
                                   LassoSamlNameIdentifier *idp_identifier)
 
74
{
 
75
  LassoNode *statement;
 
76
  LassoNode *new_identifier, *new_idp_identifier;
 
77
  LassoNode *subject, *subject_confirmation;
 
78
  gchar     *str;
 
79
  xmlChar   *time;
 
80
 
 
81
  g_return_val_if_fail(LASSO_IS_SAML_NAME_IDENTIFIER(idp_identifier), NULL);
 
82
 
 
83
  statement = LASSO_NODE(g_object_new(LASSO_TYPE_AUTHENTICATION_STATEMENT,
 
84
                                      "use_xsitype", TRUE,
 
85
                                      NULL));
 
86
 
 
87
  lasso_saml_authentication_statement_set_authenticationMethod(LASSO_SAML_AUTHENTICATION_STATEMENT(statement),
 
88
                                                               authenticationMethod);
 
89
  time = lasso_get_current_time();
 
90
  lasso_saml_authentication_statement_set_authenticationInstant(LASSO_SAML_AUTHENTICATION_STATEMENT(statement),
 
91
                                                                (const xmlChar *)time);
 
92
  xmlFree(time);
 
93
  lasso_lib_authentication_statement_set_reauthenticateOnOrAfter(LASSO_LIB_AUTHENTICATION_STATEMENT(statement),
 
94
                                                                 reauthenticateOnOrAfter);
 
95
 
 
96
  /* use_xsitype = TRUE */
 
97
  subject = lasso_lib_subject_new(TRUE);
 
98
  if (sp_identifier == NULL) {
 
99
    if (idp_identifier != NULL) {
 
100
      new_identifier = lasso_node_copy(LASSO_NODE(idp_identifier));
 
101
    }
 
102
    else {
 
103
      message(G_LOG_LEVEL_CRITICAL, "Failed to create the authentication statement, both name identifiers are NULL\n");
 
104
      lasso_node_destroy(statement);
 
105
      return NULL;
 
106
    }
 
107
  }
 
108
  else {
 
109
    new_identifier = lasso_node_copy(LASSO_NODE(sp_identifier));
 
110
  }
 
111
  lasso_saml_subject_set_nameIdentifier(LASSO_SAML_SUBJECT(subject),
 
112
                                        LASSO_SAML_NAME_IDENTIFIER(new_identifier));
 
113
  lasso_node_destroy(new_identifier);
 
114
 
 
115
  if (sp_identifier != NULL) {
 
116
    /* create a new IdpProvidedNameIdentifier and use idp_identifier data to fill it */
 
117
    str = lasso_node_get_content(LASSO_NODE(idp_identifier), NULL);
 
118
    new_idp_identifier = lasso_lib_idp_provided_name_identifier_new(str);
 
119
    xmlFree(str);
 
120
    str = lasso_node_get_attr_value(LASSO_NODE(idp_identifier), "NameQualifier", NULL);
 
121
    if (str != NULL) {
 
122
      lasso_saml_name_identifier_set_nameQualifier(LASSO_SAML_NAME_IDENTIFIER(new_idp_identifier), str);
 
123
      xmlFree(str);
 
124
    }
 
125
    str = lasso_node_get_attr_value(LASSO_NODE(idp_identifier), "Format", NULL);
 
126
    if (str != NULL) {
 
127
      lasso_saml_name_identifier_set_format(LASSO_SAML_NAME_IDENTIFIER(new_idp_identifier), str);
 
128
      xmlFree(str);
 
129
    }
 
130
    lasso_lib_subject_set_idpProvidedNameIdentifier(LASSO_LIB_SUBJECT(subject),
 
131
                                                    LASSO_LIB_IDP_PROVIDED_NAME_IDENTIFIER(new_idp_identifier));
 
132
    lasso_node_destroy(new_idp_identifier);
 
133
  }
 
134
 
 
135
  /* SubjectConfirmation & Subject */
 
136
  subject_confirmation = lasso_saml_subject_confirmation_new();
 
137
  lasso_saml_subject_confirmation_set_subjectConfirmationMethod(LASSO_SAML_SUBJECT_CONFIRMATION(subject_confirmation),
 
138
                                                                lassoSamlConfirmationMethodBearer);
 
139
  lasso_saml_subject_set_subjectConfirmation(LASSO_SAML_SUBJECT(subject),
 
140
                                             LASSO_SAML_SUBJECT_CONFIRMATION(subject_confirmation));
 
141
 
 
142
  lasso_saml_subject_statement_abstract_set_subject(LASSO_SAML_SUBJECT_STATEMENT_ABSTRACT(statement),
 
143
                                                    LASSO_SAML_SUBJECT(subject));
 
144
 
 
145
  lasso_node_destroy(subject);
 
146
  lasso_node_destroy(subject_confirmation);
 
147
 
 
148
  return statement;
 
149
}