summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/qpid/acl/AclLexer.cpp
blob: 4006e5271f5777368159916e1cb6801d5b0ef373 (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
/*
 *
 * Copyright (c) 2014 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include "qpid/acl/AclLexer.h"
#include "qpid/RefCounted.h"
#include "qpid/Exception.h"
#include <boost/shared_ptr.hpp>
#include <boost/concept_check.hpp>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <sstream>

namespace qpid {
namespace acl {

// ObjectType
const std::string objectNames[OBJECTSIZE] = {
    "broker", "connection", "exchange", "link", "method", "query", "queue" };

ObjectType AclHelper::getObjectType(const std::string& str) {
    for (int i=0; i< OBJECTSIZE; ++i) {
        if (str.compare(objectNames[i]) == 0)
            return ObjectType(i);
    }
    throw qpid::Exception("Acl illegal object name: " + str);
}

const std::string& AclHelper::getObjectTypeStr(const ObjectType o) {
    return objectNames[o];
}

// Action
const std::string actionNames[ACTIONSIZE] = {
    "access", "bind", "consume", "create", "delete",
    "move", "publish", "purge", "redirect", "reroute",
    "unbind", "update" };

Action AclHelper::getAction(const std::string& str) {
    for (int i=0; i< ACTIONSIZE; ++i) {
        if (str.compare(actionNames[i]) == 0)
            return Action(i);
    }
    throw qpid::Exception("Acl illegal action name: " + str);
}

const std::string& AclHelper::getActionStr(const Action a) {
    return actionNames[a];
}

// Property
// These are shared between broker and acl using code enums.
const std::string propertyNames[PROPERTYSIZE] = {
    "name", "durable", "owner", "routingkey", "autodelete", "exclusive", "type",
    "alternate", "queuename", "exchangename", "schemapackage",
    "schemaclass", "policytype", "paging", "host",

    "maxpages", "maxpagefactor",
    "maxqueuesize", "maxqueuecount", "maxfilesize", "maxfilecount"};

Property AclHelper::getProperty(const std::string& str) {
    for (int i=0; i< PROPERTYSIZE; ++i) {
        if (str.compare(propertyNames[i]) == 0)
            return Property(i);
    }
    throw qpid::Exception("Acl illegal property name: " + str);
}

const std::string& AclHelper::getPropertyStr(const Property p) {
    return propertyNames[p];
}

// SpecProperty
// These are shared between user acl files and acl using text.
const std::string specPropertyNames[SPECPROPSIZE] = {
    "name", "durable", "owner", "routingkey", "autodelete", "exclusive", "type",
    "alternate", "queuename", "exchangename", "schemapackage",
    "schemaclass", "policytype", "paging", "host",

     "queuemaxsizelowerlimit",  "queuemaxsizeupperlimit",
    "queuemaxcountlowerlimit", "queuemaxcountupperlimit",
      "filemaxsizelowerlimit",   "filemaxsizeupperlimit",
     "filemaxcountlowerlimit",  "filemaxcountupperlimit",
            "pageslowerlimit",         "pagesupperlimit",
       "pagefactorlowerlimit",    "pagefactorupperlimit" };

SpecProperty AclHelper::getSpecProperty(const std::string& str) {
    for (int i=0; i< SPECPROPSIZE; ++i) {
        if (str.compare(specPropertyNames[i]) == 0)
            return SpecProperty(i);
    }
    // Allow old names in ACL file as aliases for newly-named properties
    if (str.compare("maxqueuesize") == 0)
        return SPECPROP_MAXQUEUESIZEUPPERLIMIT;
    if (str.compare("maxqueuecount") == 0)
        return SPECPROP_MAXQUEUECOUNTUPPERLIMIT;
    throw qpid::Exception("Acl illegal spec property name: " + str);
}

const std::string& AclHelper::getPropertyStr(const SpecProperty p) {
    return specPropertyNames[p];
}

// AclResult
const std::string resultNames[RESULTSIZE] = {
    "allow", "allow-log", "deny", "deny-log" };

AclResult AclHelper::getAclResult(const std::string& str) {
    for (int i=0; i< RESULTSIZE; ++i) {
        if (str.compare(resultNames[i]) == 0)
            return AclResult(i);
    }
    throw qpid::Exception("Acl illegal result name: " + str);
}

const std::string& AclHelper::getAclResultStr(const AclResult r) {
    return resultNames[r];
}

bool AclHelper::resultAllows(const AclResult r) {
    bool answer = r == ALLOW || r == ALLOWLOG;
    return answer;
}

}} // namespace qpid::acl