Search in sources :

Example 11 with AuthenticationRequiredException

use of org.apache.geode.security.AuthenticationRequiredException in project geode by apache.

the class HandShake method handshakeWithSubscriptionFeed.

/**
   * Used by client-side CacheClientUpdater to handshake with a server in order to receive messages
   * generated by subscriptions (register-interest, continuous query)
   */
public ServerQueueStatus handshakeWithSubscriptionFeed(Socket sock, boolean isPrimary) throws IOException, AuthenticationRequiredException, AuthenticationFailedException, ServerRefusedConnectionException, ClassNotFoundException {
    ServerQueueStatus sqs = null;
    try {
        DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
        final InputStream in = sock.getInputStream();
        DataInputStream dis = new DataInputStream(in);
        DistributedMember member = getIDForSocket(sock);
        if (!this.multiuserSecureMode) {
            this.credentials = getCredentials(member);
        }
        byte mode = isPrimary ? Acceptor.PRIMARY_SERVER_TO_CLIENT : Acceptor.SECONDARY_SERVER_TO_CLIENT;
        write(dos, dis, mode, REPLY_OK, 0, new ArrayList(), this.credentials, member, true);
        // Wait here for a reply before continuing. This ensures that the client
        // updater is registered with the server before continuing.
        byte acceptanceCode = dis.readByte();
        if (acceptanceCode == (byte) 21 && !(sock instanceof SSLSocket)) {
            // SSL
            throw new AuthenticationRequiredException(LocalizedStrings.HandShake_SERVER_EXPECTING_SSL_CONNECTION.toLocalizedString());
        }
        // No need to check for return value since DataInputStream already throws
        // EOFException in case of EOF
        byte qType = dis.readByte();
        // read and ignore qSize flag
        int qSize = dis.readInt();
        sqs = new ServerQueueStatus(qType, qSize, member);
        // Read the message (if any)
        readMessage(dis, dos, acceptanceCode, member);
        // clients but that is not used in tests
        if (currentClientVersion.compareTo(Version.GFE_61) < 0) {
            return sqs;
        }
        HashMap instantiatorMap = DataSerializer.readHashMap(dis);
        for (Iterator itr = instantiatorMap.entrySet().iterator(); itr.hasNext(); ) {
            Map.Entry instantiator = (Map.Entry) itr.next();
            Integer id = (Integer) instantiator.getKey();
            ArrayList instantiatorArguments = (ArrayList) instantiator.getValue();
            InternalInstantiator.register((String) instantiatorArguments.get(0), (String) instantiatorArguments.get(1), id, false);
        }
        HashMap dataSerializersMap = DataSerializer.readHashMap(dis);
        for (Iterator itr = dataSerializersMap.entrySet().iterator(); itr.hasNext(); ) {
            Map.Entry dataSerializer = (Map.Entry) itr.next();
            Integer id = (Integer) dataSerializer.getKey();
            InternalDataSerializer.register((String) dataSerializer.getValue(), false, null, null, id);
        }
        HashMap<Integer, ArrayList<String>> dsToSupportedClassNames = DataSerializer.readHashMap(dis);
        InternalDataSerializer.updateSupportedClassesMap(dsToSupportedClassNames);
    } catch (IOException ex) {
        CancelCriterion stopper = this.system.getCancelCriterion();
        stopper.checkCancelInProgress(null);
        throw ex;
    } catch (ClassNotFoundException ex) {
        CancelCriterion stopper = this.system.getCancelCriterion();
        stopper.checkCancelInProgress(null);
        throw ex;
    }
    return sqs;
}
Also used : HashMap(java.util.HashMap) DataOutputStream(java.io.DataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SSLSocket(javax.net.ssl.SSLSocket) CancelCriterion(org.apache.geode.CancelCriterion) ArrayList(java.util.ArrayList) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) IOException(java.io.IOException) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) BigInteger(java.math.BigInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with AuthenticationRequiredException

use of org.apache.geode.security.AuthenticationRequiredException in project geode by apache.

the class MessageIdExtractor method getAuthIdsFromMessage.

private AuthIds getAuthIdsFromMessage(Message requestMessage, HandShake handshake) throws AuthenticationRequiredException {
    try {
        byte[] secureBytes = requestMessage.getSecureBytes();
        secureBytes = handshake.decryptBytes(secureBytes);
        return new AuthIds(secureBytes);
    } catch (Exception ex) {
        throw new AuthenticationRequiredException(LocalizedStrings.HandShake_NO_SECURITY_CREDENTIALS_ARE_PROVIDED.toLocalizedString(), ex);
    }
}
Also used : AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException)

Aggregations

AuthenticationRequiredException (org.apache.geode.security.AuthenticationRequiredException)12 IOException (java.io.IOException)10 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)5 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)5 Properties (java.util.Properties)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 EOFException (java.io.EOFException)3 GemFireConfigException (org.apache.geode.GemFireConfigException)3 GatewayConfigurationException (org.apache.geode.cache.GatewayConfigurationException)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 DistributedSystem (org.apache.geode.distributed.DistributedSystem)3 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 DataOutputStream (java.io.DataOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 Socket (java.net.Socket)2 Principal (java.security.Principal)2