Skip to content
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

[ELY-2023] Elytron ClientCertAuthenticationMechanism does not work when using a web proxy #1442

Merged
merged 1 commit into from Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,81 @@
/*
* Copyright 2020 Red Hat, Inc.
*
* 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.
*/

package org.wildfly.security.auth.callback;

import java.security.Principal;
import org.wildfly.common.Assert;
import org.wildfly.security.auth.principal.NamePrincipal;

/**
* <p>An authorization callback similar to javase {@link javax.security.sasl.AuthorizeCallback}
* but using a generic principal.</p>
*
* @author rmartinc
*/
public class PrincipalAuthorizeCallback implements ExtendedCallback {

private final Principal principal;
private boolean authorized;

/**
* Creates a new instance to authorize the associated <code>name</code>.
* It will be transformed in a {@link NamePrincipal}.
*
* @param name the name to authorize
*/
public PrincipalAuthorizeCallback(String name) {
Assert.checkNotNullParam("name", name);
this.principal = new NamePrincipal(name);
}

/**
* Creates a new instance to authorize the associated <code>principal</code>.
*
* @param principal the principal to authorize
*/
public PrincipalAuthorizeCallback(Principal principal) {
Assert.checkNotNullParam("principal", principal);
this.principal = principal;
}

/**
* Indicates if the principal was successfully authorized.
*
* @return true if the principal was successfully authorized. Otherwise, false
*/
public boolean isAuthorized() {
return authorized;
}

/**
* Sets whether the authorization is allowed for the principal.
*
* @param authorized authorization result
*/
public void setAuthorized(boolean authorized) {
this.authorized = authorized;
}

/**
* Returns the {@link Principal}.
*
* @return the principal (not {@code null})
*/
public Principal getPrincipal() {
return this.principal;
}
}
Expand Up @@ -56,6 +56,7 @@
import org.wildfly.security.auth.callback.EvidenceVerifyCallback;
import org.wildfly.security.auth.callback.ExclusiveNameCallback;
import org.wildfly.security.auth.callback.FastUnsupportedCallbackException;
import org.wildfly.security.auth.callback.PrincipalAuthorizeCallback;
import org.wildfly.security.auth.callback.MechanismInformationCallback;
import org.wildfly.security.auth.callback.IdentityCredentialCallback;
import org.wildfly.security.auth.callback.PeerPrincipalCallback;
Expand Down Expand Up @@ -1115,6 +1116,15 @@ private void handleOne(final Callback[] callbacks, final int idx) throws IOExcep
addPublicCredential(credential);
}
handleOne(callbacks, idx + 1);
} else if (callback instanceof PrincipalAuthorizeCallback) {
PrincipalAuthorizeCallback authorizeCallback = (PrincipalAuthorizeCallback) callback;
Principal principal = authorizeCallback.getPrincipal();
// always re-set the principal to ensure it hasn't changed.
setAuthenticationPrincipal(principal);
boolean authorized = authorize();
log.tracef("Handling PrincipalAuthorizeCallback: principal = %s authorized = %b", principal, authorized);
authorizeCallback.setAuthorized(authorized);
handleOne(callbacks, idx + 1);
} else {
CallbackUtil.unsupported(callback);
handleOne(callbacks, idx + 1);
Expand Down
Expand Up @@ -31,12 +31,12 @@
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.sasl.AuthorizeCallback;

import org.wildfly.security.auth.callback.AuthenticationCompleteCallback;
import org.wildfly.security.auth.callback.CachedIdentityAuthorizeCallback;
import org.wildfly.security.auth.callback.EvidenceDecodePrincipalCallback;
import org.wildfly.security.auth.callback.EvidenceVerifyCallback;
import org.wildfly.security.auth.callback.PrincipalAuthorizeCallback;
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.auth.server.SecurityIdentity;
import org.wildfly.security.cache.CachedIdentity;
Expand Down Expand Up @@ -141,10 +141,9 @@ private boolean attemptAuthentication(HttpServerRequest request, Function<Securi
authorizedFunction = cacheCallback::isAuthorized;
authorizeCallBack = cacheCallback;
} else {
String name = evidence.getDecodedPrincipal().getName();
AuthorizeCallback plainCallback = new AuthorizeCallback(name, name);
authorizedFunction = plainCallback::isAuthorized;
authorizeCallBack = plainCallback;
PrincipalAuthorizeCallback principalCallback = new PrincipalAuthorizeCallback(evidence.getDecodedPrincipal());
authorizedFunction = principalCallback::isAuthorized;
authorizeCallBack = principalCallback;
}

try {
Expand Down