aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/apps/SSOSAML.vue
blob: 00fb46aaf7e158d90e279079e14dbe994c49788a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
    <div class="ssosaml-config">
        <ContentBar isContentBar icon="lock-locked" :title="$gettext('SAML Service Provider Configuration')">
            <template #info-text>
                {{ $gettext('Configure your SAML Service Provider settings here.') }}
            </template>
        </ContentBar>

        <form @submit.prevent="saveConfig" class="default">
            <fieldset>
                <legend>{{ $gettext('Basic Settings') }}</legend>

                <label for="entityId">
                    {{ $gettext('Entity ID') }}
                    <input type="text" id="entityId" v-model="config.entityId" required>
                </label>

                <label for="assertionConsumerService">
                    {{ $gettext('Assertion Consumer Service URL') }}
                    <input type="url" id="assertionConsumerService" v-model="config.assertionConsumerService" required>
                </label>

                <label for="singleLogoutService">
                    {{ $gettext('Single Logout Service URL') }}
                    <input type="url" id="singleLogoutService" v-model="config.singleLogoutService">
                </label>

                <label for="nameIdFormat">
                    {{ $gettext('NameID Format') }}
                    <select id="nameIdFormat" v-model="config.nameIdFormat">
                        <option value="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">Unspecified</option>
                        <option value="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">Email Address</option>
                        <option value="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">Persistent</option>
                        <option value="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">Transient</option>
                    </select>
                </label>
            </fieldset>

            <fieldset>
                <legend>{{ $gettext('Certificate Settings') }}</legend>

                <label for="x509cert">
                    {{ $gettext('X.509 Certificate') }}
                    <textarea id="x509cert" v-model="config.x509cert" rows="5"></textarea>
                </label>

                <label for="privateKey">
                    {{ $gettext('Private Key') }}
                    <textarea id="privateKey" v-model="config.privateKey" rows="5"></textarea>
                </label>
            </fieldset>

            <fieldset>
                <legend>{{ $gettext('Security Settings') }}</legend>

                <label>
                    <input type="checkbox" v-model="config.security.authnRequestsSigned">
                    {{ $gettext('Sign AuthnRequests') }}
                </label>

                <label>
                    <input type="checkbox" v-model="config.security.wantMessagesSigned">
                    {{ $gettext('Require Signed Messages') }}
                </label>

                <label>
                    <input type="checkbox" v-model="config.security.wantAssertionsSigned">
                    {{ $gettext('Require Signed Assertions') }}
                </label>
            </fieldset>

            <footer data-dialog-button>
                <button type="submit" class="button">
                    {{ $gettext('Save Configuration') }}
                </button>
                <button type="button" class="button" @click="resetForm">
                    {{ $gettext('Reset') }}
                </button>
            </footer>
        </form>
    </div>
</template>

<script>
import ContentBar from '@/vue/components/ContentBar.vue';
import { mapActions } from 'vuex';

export default {
    name: 'ssosaml',
    components: { ContentBar },
    data() {
        return {
            config: {
                entityId: '',
                assertionConsumerService: '',
                singleLogoutService: '',
                nameIdFormat: 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
                x509cert: '',
                privateKey: '',
                security: {
                    authnRequestsSigned: false,
                    wantMessagesSigned: false,
                    wantAssertionsSigned: false,
                }
            },
            originalConfig: {},
            isLoading: false,
            error: null
        };
    },
    methods: {
        ...mapActions('jsonapi', ['get', 'patch']),

        async saveConfig() {
            this.isLoading = true;
            this.error = null;
            try {
                const response = await this.patch({
                    type: 'saml-configuration',
                    id: '1',
                    attributes: this.config
                });
                this.config = response.data.attributes;
                this.originalConfig = JSON.parse(JSON.stringify(this.config));
                this.$studip.message('success', this.$gettext('SAML configuration saved successfully.'));
            } catch (error) {
                console.error('Error saving SAML configuration:', error);
                this.error = this.$gettext('Failed to save SAML configuration. Please try again.');
                this.$studip.message('error', this.error);
            } finally {
                this.isLoading = false;
            }
        },
        resetForm() {
            this.config = JSON.parse(JSON.stringify(this.originalConfig));
        },
        async loadConfig() {
            this.isLoading = true;
            this.error = null;
            try {
                const response = await this.get({
                    type: 'saml-configuration',
                    id: '1'
                });
                this.config = response.data.attributes;
                this.originalConfig = JSON.parse(JSON.stringify(this.config));
            } catch (error) {
                console.error('Error loading SAML configuration:', error);
                this.error = this.$gettext('Failed to load SAML configuration. Please refresh the page.');
                this.$studip.message('error', this.error);
            } finally {
                this.isLoading = false;
            }
        }
    },
    mounted() {
        this.loadConfig();
    }
};
</script>