2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 import { Component, OnInit } from '@angular/core';
20 import {EditBaseComponent} from "@app/modules/shared/edit-base.component";
21 import {LdapConfiguration} from "@app/model/ldap-configuration";
22 import {ActivatedRoute} from "@angular/router";
23 import {AbstractControl, FormBuilder, ValidatorFn, Validators} from "@angular/forms";
24 import {SecurityService} from "@app/services/security.service";
25 import {ToastService} from "@app/services/toast.service";
26 import {propertyDescriptorPatch} from "zone.js/lib/browser/property-descriptor";
29 selector: 'app-ldap-security',
30 templateUrl: './ldap-security.component.html',
31 styleUrls: ['./ldap-security.component.scss']
33 export class LdapSecurityComponent extends EditBaseComponent<LdapConfiguration> implements OnInit {
35 authenticationMethods=['none','simple','strong']
37 constructor(private route: ActivatedRoute,
38 public fb: FormBuilder, private securityService: SecurityService, private toastService: ToastService) {
42 port:['', [Validators.min(1), Validators.max(65535)]],
44 base_dn:['',[dnValidator()]],
45 groups_base_dn:['',[dnValidator()]],
46 bind_dn:['',[dnValidator()]],
48 authentication_method:['none'],
49 bind_authenticator_enabled:[false],
50 use_role_name_as_group:[true],
58 createEntity(): LdapConfiguration {
59 return new LdapConfiguration();
65 getInputClasses(field: string) : string[] {
66 let csClasses = super.isValid(field);
67 if (csClasses.length==1 && csClasses[0]=='') {
70 csClasses.push('form-control');
71 console.log("Classes "+field+" " + csClasses);
76 export function dnValidator(): ValidatorFn {
77 return (control: AbstractControl): {[key: string]: any} | null => {
79 let value = control.value.toString()
81 let partKey : string = ''
82 let partValue : string = ''
84 for (let i=0; i<value.length; i+=1) {
85 let c = value.charAt(i);
86 if (c=='\\' && !escape) {
88 } else if (c==',' && !escape) {
89 parts.push( [partKey,partValue]);
90 if (partKey.length==0) {
91 return {'invalidDnBadKey':{value:value,index:i}}
93 if (partValue.length==0) {
94 return {'invalidDnBadValue':{value:value, index: i}}
100 } else if (c=='=' && !escape) {
102 return {'invalidDnBadEquals':{value: value, index:i}}
110 partKey = partKey + c;
112 partValue = partValue + c;