private String[] getAvailableRealms() throws AuthenticationMechanismException { final AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); try { callbackHandler.handle(new Callback[] { availableRealmsCallback }); return availableRealmsCallback.getRealmNames(); } catch (UnsupportedCallbackException ignored) { return new String[0]; } catch (AuthenticationMechanismException e) { throw e; } catch (IOException e) { throw httpDigest.mechCallbackHandlerFailedForUnknownReason(e); } }
public SaslServer createSaslServer(final String mechanism, final String protocol, final String serverName, final Map<String, ?> props, final CallbackHandler cbh) throws SaslException { final String realmList = (String) props.get(WildFlySasl.REALM_LIST); if (realmList == null) { // The legacy REALM_LIST property wasn't specified return delegate.createSaslServer(mechanism, protocol, serverName, props, cbh); } return delegate.createSaslServer(mechanism, protocol, serverName, props, callbacks -> { final ArrayList<Callback> list = new ArrayList<>(Arrays.asList(callbacks)); final Iterator<Callback> iterator = list.iterator(); while (iterator.hasNext()) { Callback callback = iterator.next(); if (callback instanceof AvailableRealmsCallback) { String[] realms = realmListPropertyToArray(realmList, escapeCharacter, delims); ((AvailableRealmsCallback) callback).setRealmNames(realms); iterator.remove(); } } if (! list.isEmpty()) { cbh.handle(list.toArray(new Callback[list.size()])); } }); }
private String getRealmName() throws HttpAuthenticationException { try { AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); callbackHandler.handle(new Callback[] { availableRealmsCallback }); String[] realmNames = availableRealmsCallback.getRealmNames(); if (realmNames != null && realmNames.length > 0) { return realmNames[0]; } } catch (UnsupportedCallbackException ignored) { } catch (IOException e) { throw httpBearer.mechCallbackHandlerFailedForUnknownReason(e).toHttpAuthenticationException(); } return null; }
((AvailableRealmsCallback) callback).setRealmNames(names.toArray(new String[names.size()]));
final AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); try { cbh.handle(new Callback[] { availableRealmsCallback }); realms = availableRealmsCallback.getRealmNames(); } catch (UnsupportedCallbackException ignored) { } catch (SaslException e) {
public SaslServer createSaslServer(final String mechanism, final String protocol, final String serverName, final Map<String, ?> props, final CallbackHandler cbh) throws SaslException { final String realmList = (String) props.get(WildFlySasl.REALM_LIST); if (realmList == null) { // The legacy REALM_LIST property wasn't specified return delegate.createSaslServer(mechanism, protocol, serverName, props, cbh); } return delegate.createSaslServer(mechanism, protocol, serverName, props, callbacks -> { final ArrayList<Callback> list = new ArrayList<>(Arrays.asList(callbacks)); final Iterator<Callback> iterator = list.iterator(); while (iterator.hasNext()) { Callback callback = iterator.next(); if (callback instanceof AvailableRealmsCallback) { String[] realms = realmListPropertyToArray(realmList, escapeCharacter, delims); ((AvailableRealmsCallback) callback).setRealmNames(realms); iterator.remove(); } } if (! list.isEmpty()) { cbh.handle(list.toArray(new Callback[list.size()])); } }); }
public SaslServer createSaslServer(final String mechanism, final String protocol, final String serverName, final Map<String, ?> props, final CallbackHandler cbh) throws SaslException { String[] realms = null; final AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); try { cbh.handle(new Callback[] { availableRealmsCallback }); realms = availableRealmsCallback.getRealmNames(); } catch (UnsupportedCallbackException ignored) { } catch (SaslException e) { throw e; } catch (IOException e) { throw sasl.mechCallbackHandlerFailedForUnknownReason(e).toSaslException(); } if (realms == null) { realms = new String[] { serverName }; } final String realmList = arrayToRealmListProperty(realms, escapeCharacter, delims); final Map<String, Object> newProps = new HashMap<String, Object>(props) { public Object get(Object key) { Object value = super.get(key); if (key.equals(WildFlySasl.REALM_LIST) && (value == null)) { value = realmList; put(WildFlySasl.REALM_LIST, value); } return value; } }; return delegate.createSaslServer(mechanism, protocol, serverName, newProps, cbh); }
public SaslServer createSaslServer(final String mechanism, final String protocol, final String serverName, final Map<String, ?> props, final CallbackHandler cbh) throws SaslException { final String realmList = (String) props.get(WildFlySasl.REALM_LIST); if (realmList == null) { // The legacy REALM_LIST property wasn't specified return delegate.createSaslServer(mechanism, protocol, serverName, props, cbh); } return delegate.createSaslServer(mechanism, protocol, serverName, props, callbacks -> { final ArrayList<Callback> list = new ArrayList<>(Arrays.asList(callbacks)); final Iterator<Callback> iterator = list.iterator(); while (iterator.hasNext()) { Callback callback = iterator.next(); if (callback instanceof AvailableRealmsCallback) { String[] realms = realmListPropertyToArray(realmList, escapeCharacter, delims); ((AvailableRealmsCallback) callback).setRealmNames(realms); iterator.remove(); } } if (! list.isEmpty()) { cbh.handle(list.toArray(new Callback[list.size()])); } }); }
final AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); try { callbackHandler.handle(new Callback[] { availableRealmsCallback }); realms = availableRealmsCallback.getRealmNames(); } catch (UnsupportedCallbackException ignored) { } catch (HttpAuthenticationException e) {
public SaslServer createSaslServer(final String mechanism, final String protocol, final String serverName, final Map<String, ?> props, final CallbackHandler cbh) throws SaslException { final String realmList = (String) props.get(WildFlySasl.REALM_LIST); if (realmList == null) { // The legacy REALM_LIST property wasn't specified return delegate.createSaslServer(mechanism, protocol, serverName, props, cbh); } return delegate.createSaslServer(mechanism, protocol, serverName, props, callbacks -> { final ArrayList<Callback> list = new ArrayList<>(Arrays.asList(callbacks)); final Iterator<Callback> iterator = list.iterator(); while (iterator.hasNext()) { Callback callback = iterator.next(); if (callback instanceof AvailableRealmsCallback) { String[] realms = realmListPropertyToArray(realmList, escapeCharacter, delims); ((AvailableRealmsCallback) callback).setRealmNames(realms); iterator.remove(); } } if (! list.isEmpty()) { cbh.handle(list.toArray(new Callback[list.size()])); } }); }
private String[] getAvailableRealms() throws AuthenticationMechanismException { final AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); try { callbackHandler.handle(new Callback[] { availableRealmsCallback }); return availableRealmsCallback.getRealmNames(); } catch (UnsupportedCallbackException ignored) { return new String[0]; } catch (AuthenticationMechanismException e) { throw e; } catch (IOException e) { throw httpDigest.mechCallbackHandlerFailedForUnknownReason(e); } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { ArrayList<Callback> list = new ArrayList<>(Arrays.asList(callbacks)); Iterator<Callback> it = list.iterator(); CredentialCallback cb = null; while (it.hasNext()) { Callback callback = it.next(); if (callback instanceof AvailableRealmsCallback) { ((AvailableRealmsCallback) callback).setRealmNames(realmList); it.remove(); } else if (callback instanceof CredentialCallback) { cb = (CredentialCallback) callback; } } // If the only callback was AvailableRealmsCallback, we must not pass it to the AuthorizingCallbackHandler if (!list.isEmpty()) { if (cb != null && cb.getAlgorithm().equals(ALGORITHM_DIGEST_MD5)) { // It's necessary to add the NameCallback with the CredentialCallback, otherwise a UserNotFoundException is thrown DigestPasswordAlgorithmSpec spec = (DigestPasswordAlgorithmSpec) cb.getParameterSpec(); list.add(new NameCallback("User", spec.getUsername())); callbacks = list.toArray(new Callback[list.size()]); } delegate.handle(callbacks); } }
private String[] getAvailableRealms() throws AuthenticationMechanismException { final AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); try { callbackHandler.handle(new Callback[] { availableRealmsCallback }); return availableRealmsCallback.getRealmNames(); } catch (UnsupportedCallbackException ignored) { return new String[0]; } catch (AuthenticationMechanismException e) { throw e; } catch (IOException e) { throw httpDigest.mechCallbackHandlerFailedForUnknownReason(e); } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { // We have to provide the available realms via this callback // Ideally we would utilise org.wildfly.security.sasl.util.AvailableRealmsSaslServerFactory, however as we can't // pass the SaslServerFactory impl to JGroups we must do it here instead. ArrayList<Callback> list = new ArrayList<>(Arrays.asList(callbacks)); Iterator<Callback> it = list.iterator(); CredentialCallback cb = null; while (it.hasNext()) { Callback callback = it.next(); if (callback instanceof AvailableRealmsCallback) { ((AvailableRealmsCallback) callback).setRealmNames(realmList); it.remove(); } else if (callback instanceof CredentialCallback) { cb = (CredentialCallback) callback; } } // If the only callback was AvailableRealmsCallback, we must not pass it to the AuthorizingCallbackHandler if (!list.isEmpty()) { if (cb != null && cb.getAlgorithm().equals(ALGORITHM_DIGEST_MD5)) { // It's necessary to add the NameCallback with the CredentialCallback, otherwise a UserNotFoundException is thrown DigestPasswordAlgorithmSpec spec = (DigestPasswordAlgorithmSpec) cb.getParameterSpec(); list.add(new NameCallback("User", spec.getUsername())); callbacks = list.toArray(new Callback[list.size()]); } getMechCallbackHandler().handle(callbacks); } }
private String[] getAvailableRealms() throws AuthenticationMechanismException { final AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); try { callbackHandler.handle(new Callback[] { availableRealmsCallback }); return availableRealmsCallback.getRealmNames(); } catch (UnsupportedCallbackException ignored) { return new String[0]; } catch (AuthenticationMechanismException e) { throw e; } catch (IOException e) { throw httpDigest.mechCallbackHandlerFailedForUnknownReason(e); } }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof AvailableRealmsCallback) { ((AvailableRealmsCallback) callback).setRealmNames(realm.getName()); } else if (callback instanceof AuthorizeCallback) { AuthorizeCallback acb = (AuthorizeCallback) callback; String authenticationId = acb.getAuthenticationID(); String authorizationId = acb.getAuthorizationID(); acb.setAuthorized(authenticationId.equals(authorizationId)); int realmSep = authorizationId.indexOf('@'); realmUser = realmSep <= 0 ? new RealmUser(authorizationId) : new RealmUser(authorizationId.substring(realmSep+1), authorizationId.substring(0, realmSep)); } } }
private String getRealmName() throws HttpAuthenticationException { try { AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); callbackHandler.handle(new Callback[] { availableRealmsCallback }); String[] realmNames = availableRealmsCallback.getRealmNames(); if (realmNames != null && realmNames.length > 0) { return realmNames[0]; } } catch (UnsupportedCallbackException ignored) { } catch (IOException e) { throw httpBearer.mechCallbackHandlerFailedForUnknownReason(e).toHttpAuthenticationException(); } return null; }
((AvailableRealmsCallback) callback).setRealmNames(names.toArray(new String[names.size()]));
private String getRealmName() throws HttpAuthenticationException { try { AvailableRealmsCallback availableRealmsCallback = new AvailableRealmsCallback(); callbackHandler.handle(new Callback[] { availableRealmsCallback }); String[] realmNames = availableRealmsCallback.getRealmNames(); if (realmNames != null && realmNames.length > 0) { return realmNames[0]; } } catch (UnsupportedCallbackException ignored) { } catch (IOException e) { throw httpBearer.mechCallbackHandlerFailedForUnknownReason(e).toHttpAuthenticationException(); } return null; }
((AvailableRealmsCallback) callback).setRealmNames(names.toArray(new String[names.size()]));