-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathDummyAuthorization3.java
More file actions
executable file
·143 lines (124 loc) · 4.5 KB
/
DummyAuthorization3.java
File metadata and controls
executable file
·143 lines (124 loc) · 4.5 KB
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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package javaobject;
import java.security.Principal;
import java.util.HashSet;
import java.util.Set;
import org.apache.geode.LogWriter;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.operations.GetOperationContext;
import org.apache.geode.cache.operations.OperationContext;
import org.apache.geode.cache.operations.PutOperationContext;
import org.apache.geode.cache.operations.RegionCreateOperationContext;
import org.apache.geode.cache.operations.OperationContext.OperationCode;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.security.AccessControl;
import org.apache.geode.security.NotAuthorizedException;
/**
* A dummy implementation of the <code>AccessControl</code> interface that
* allows authorization depending on the format of the <code>Principal</code>
* string.
*
*
* @since 6.5
*/
public class DummyAuthorization3 implements AccessControl {
private String operationKeyIdx;
private DistributedMember remoteDistributedMember;
private LogWriter logger;
private boolean m_closed;
public DummyAuthorization3() {
operationKeyIdx = "null";
m_closed = false;
}
public static AccessControl create() {
return new DummyAuthorization3();
}
public void init(Principal principal,
DistributedMember remoteMember,
Cache cache) throws NotAuthorizedException {
this.remoteDistributedMember = remoteMember;
this.logger = cache.getLogger();
if (principal != null) {
String name = principal.getName().toLowerCase();
if (name != null) {
if(name.startsWith("user"))
{
String idx = name.substring(4);
if(idx != null)
{
try
{
int keyIdx = Integer.valueOf(idx);
operationKeyIdx = idx;
}
catch(Exception ex)
{
}
}
}
}
}
}
public boolean authorizeOperation(String regionName, OperationContext context) {
if(m_closed == true)
return false;
OperationCode opCode = context.getOperationCode();
this.logger.fine("Invoked authorize operation for [" + opCode
+ "] in region [" + regionName + "] for client: " + remoteDistributedMember);
this.logger.fine("Invoked authorize operation for user id = " + operationKeyIdx);
if (operationKeyIdx.equals("4"))
{
if (context instanceof GetOperationContext) {
this.logger.fine("4 Invoked authorize operation for get ");
GetOperationContext goc = (GetOperationContext)context;
String key = (String)goc.getKey();
this.logger.fine("4 Invoked authorize operation for get key = " + key);
if (key.indexOf(operationKeyIdx) >=0)
return true;
else
return false;
}
else if(context instanceof PutOperationContext)
{
this.logger.fine("4 Invoked authorize operation for put ");
PutOperationContext goc = (PutOperationContext)context;
String key = (String)goc.getKey();
this.logger.fine("4 Invoked authorize operation for put key = " + key);
if (key.indexOf(operationKeyIdx) >=0)
return true;
else
return false;
}
}
if (context instanceof GetOperationContext) {
this.logger.fine("Invoked authorize operation for get ");
}
else if(context instanceof PutOperationContext)
{
this.logger.fine("Invoked authorize operation for put ");
}
else if (context instanceof RegionCreateOperationContext)
{
this.logger.fine("Invoked authorize operation for region create operation context ");
}
return true;
}
public void close() {
m_closed =true;
}
}