-
Notifications
You must be signed in to change notification settings - Fork 273
KNOX-3340: Add Control for LDAPRolesLookupInterceptor #1258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
handavid
wants to merge
4
commits into
apache:master
Choose a base branch
from
handavid:knox-3340-role-lookup-groups
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...src/main/java/org/apache/knox/gateway/services/ldap/control/RolesLookupBypassControl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * 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 org.apache.knox.gateway.services.ldap.control; | ||
|
|
||
| import org.apache.directory.api.ldap.model.message.Control; | ||
|
|
||
| public interface RolesLookupBypassControl extends Control { | ||
| boolean isBypassRolesLookup(); | ||
| void setBypassRolesLookup(boolean bypassRolesLookup); | ||
| } |
74 changes: 74 additions & 0 deletions
74
...java/org/apache/knox/gateway/services/ldap/control/RolesLookupBypassControlDecorator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * 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 org.apache.knox.gateway.services.ldap.control; | ||
|
|
||
| import org.apache.directory.api.asn1.Asn1Object; | ||
| import org.apache.directory.api.asn1.DecoderException; | ||
| import org.apache.directory.api.asn1.EncoderException; | ||
| import org.apache.directory.api.asn1.util.Asn1Buffer; | ||
| import org.apache.directory.api.ldap.codec.api.ControlDecorator; | ||
| import org.apache.directory.api.ldap.codec.api.LdapApiService; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
|
|
||
| public class RolesLookupBypassControlDecorator extends ControlDecorator<RolesLookupBypassControl> implements RolesLookupBypassControl { | ||
|
|
||
| private final RolesLookupBypassControlFactory rolesLookupBypassControlFactory; | ||
|
|
||
| public RolesLookupBypassControlDecorator(LdapApiService codec, RolesLookupBypassControl decoratedControl, RolesLookupBypassControlFactory rolesLookupBypassControlFactory) { | ||
| super(codec, decoratedControl); | ||
| this.rolesLookupBypassControlFactory = rolesLookupBypassControlFactory; | ||
| } | ||
|
|
||
| @Override | ||
| public Asn1Object decode(byte[] bytes) throws DecoderException { | ||
| rolesLookupBypassControlFactory.decodeValue(getDecorated(), bytes); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public int computeLength() { | ||
| return 3; // Tag, Length, Value | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuffer encode(ByteBuffer byteBuffer) throws EncoderException { | ||
| Asn1Buffer asn1Buffer = new Asn1Buffer(); | ||
| rolesLookupBypassControlFactory.encodeValue(asn1Buffer, getDecorated()); | ||
|
|
||
| // reverse the byte ordering because Asn1Buffers store bytes in reverse | ||
| ByteBuffer factoryBuffer = asn1Buffer.getBytes(); | ||
| int totalBytes = factoryBuffer.remaining(); | ||
| byte[] factoryBytes = factoryBuffer.array(); | ||
| for (int i = totalBytes - 1; i >= 0; i-- ) { | ||
| byteBuffer.put(factoryBytes[i]); | ||
| } | ||
|
|
||
| return byteBuffer; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isBypassRolesLookup() { | ||
| return getDecorated().isBypassRolesLookup(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setBypassRolesLookup(boolean bypassRolesLookup) { | ||
| getDecorated().setBypassRolesLookup(bypassRolesLookup); | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
...n/java/org/apache/knox/gateway/services/ldap/control/RolesLookupBypassControlFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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 org.apache.knox.gateway.services.ldap.control; | ||
|
|
||
| import org.apache.directory.api.asn1.DecoderException; | ||
| import org.apache.directory.api.asn1.util.Asn1Buffer; | ||
| import org.apache.directory.api.ldap.codec.api.AbstractControlFactory; | ||
| import org.apache.directory.api.ldap.codec.api.LdapApiService; | ||
| import org.apache.directory.api.ldap.model.message.Control; | ||
|
|
||
| public class RolesLookupBypassControlFactory extends AbstractControlFactory<RolesLookupBypassControl> { | ||
| public static final byte BOOLEAN_TAG_BYTE = 0x01; | ||
|
|
||
| public RolesLookupBypassControlFactory(LdapApiService codec, String oid) { | ||
| super(codec, oid); | ||
| } | ||
|
|
||
| @Override | ||
| public Control newControl() { | ||
| return new RolesLookupBypassControlDecorator(codec, new RolesLookupBypassControlImpl(oid), this); | ||
| } | ||
|
|
||
| @Override | ||
| public void decodeValue(Control control, byte[] controlBytes) throws DecoderException { | ||
| if (control instanceof RolesLookupBypassControl) { | ||
| RolesLookupBypassControl rolesLookupBypassControl = (RolesLookupBypassControl) control; | ||
| if (controlBytes == null || controlBytes.length < 3) { | ||
| throw new DecoderException("Invalid BER encoding for Boolean Control"); | ||
| } | ||
|
|
||
| if (controlBytes[0] != BOOLEAN_TAG_BYTE) { | ||
| throw new DecoderException("Expected Boolean Tag (0x01), found: " + controlBytes[0]); | ||
| } | ||
|
|
||
| boolean value = (controlBytes[2] != 0x00); | ||
| rolesLookupBypassControl.setBypassRolesLookup(value); | ||
| } else { | ||
| throw new DecoderException("Cannot decode into " + control.getClass().getSimpleName() + ". Control must be instance of RolesLookupBypassControl."); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void encodeValue(Asn1Buffer buffer, Control control) { | ||
| if (control instanceof RolesLookupBypassControl) { | ||
| RolesLookupBypassControl rolesLookupBypassControl = (RolesLookupBypassControl) control; | ||
|
|
||
| buffer.put(BOOLEAN_TAG_BYTE); | ||
| buffer.put((byte) 1); // Value is one byte long | ||
| buffer.put((byte) (rolesLookupBypassControl.isBypassRolesLookup() ? 0xFF : 0x00)); | ||
| } | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
...main/java/org/apache/knox/gateway/services/ldap/control/RolesLookupBypassControlImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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 org.apache.knox.gateway.services.ldap.control; | ||
|
|
||
| import org.apache.directory.api.ldap.model.message.controls.AbstractControl; | ||
|
|
||
| public class RolesLookupBypassControlImpl extends AbstractControl implements RolesLookupBypassControl { | ||
| private boolean bypassRolesLookup; | ||
|
|
||
| public RolesLookupBypassControlImpl(String oid) { | ||
| super(oid); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isBypassRolesLookup() { | ||
| return bypassRolesLookup; | ||
| } | ||
|
|
||
| @Override | ||
| public void setBypassRolesLookup(boolean bypassRolesLookup) { | ||
| this.bypassRolesLookup = bypassRolesLookup; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you are throwing
throw new ConfigurationException("Roles Lookup Bypass Control OID is not valid");below inKnoxLDAPServerManager. However, I think that exception belongs here, when the factory wants to create an instance ofLDAPRolesLookupInterceptor.The creation of this interceptor is also happening in
KnoxLDAPServerManager.init()by callingcreateInterceptors, so it'd fail fast in case someone provided an invalid OID.What do you think?