Search in sources :

Example 1 with ChallengeResponseFactory

use of com.swiftmq.auth.ChallengeResponseFactory in project swiftmq-client by iitsoftware.

the class EndpointImpl method authenticate.

public void authenticate(String password) throws Exception {
    ChallengeResponseFactory crFactory = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
    AuthReply reply = (AuthReply) request(new AuthRequest(crFactory.createResponse(connectReply.getChallenge(), password)));
    if (!reply.isOk())
        throw reply.getException();
}
Also used : ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory)

Example 2 with ChallengeResponseFactory

use of com.swiftmq.auth.ChallengeResponseFactory in project swiftmq-client by iitsoftware.

the class EndpointImpl method authenticate.

public void authenticate(String password) throws Exception {
    ChallengeResponseFactory crFactory = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
    AuthReply reply = (AuthReply) request(new AuthRequest(crFactory.createResponse(connectReply.getChallenge(), password)));
    if (!reply.isOk())
        throw reply.getException();
}
Also used : ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory)

Example 3 with ChallengeResponseFactory

use of com.swiftmq.auth.ChallengeResponseFactory in project swiftmq-client by iitsoftware.

the class EndpointImpl method authenticate.

public void authenticate(String password) throws Exception {
    ChallengeResponseFactory crFactory = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
    AuthReply reply = (AuthReply) request(new AuthRequest(crFactory.createResponse(connectReply.getChallenge(), password)));
    if (!reply.isOk())
        throw reply.getException();
}
Also used : ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory)

Example 4 with ChallengeResponseFactory

use of com.swiftmq.auth.ChallengeResponseFactory in project swiftmq-ce by iitsoftware.

the class JMSSwiftlet method createGeneralProps.

private void createGeneralProps(Entity root) throws SwiftletException {
    Property prop = root.getProperty("crfactory-class");
    String crf = (String) root.getProperty("crfactory-class").getValue();
    try {
        challengeResponseFactory = (ChallengeResponseFactory) Class.forName(crf).newInstance();
    } catch (Exception e) {
        String msg = "Error creating class instance of challenge/response factory '" + crf + "', exception=" + e;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), msg);
        throw new SwiftletException(msg);
    }
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            try {
                ChallengeResponseFactory sf = (ChallengeResponseFactory) Class.forName((String) newValue).newInstance();
            } catch (Exception e) {
                String msg = "Error creating class instance of default challenge/response factory '" + newValue + "', exception=" + e;
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), msg);
                throw new PropertyChangeException(msg);
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "propertyChanged (crfactory.class): oldValue=" + oldValue + ", newValue=" + newValue);
        }
    });
    prop = root.getProperty("max-connections");
    maxConnections = ((Integer) prop.getValue()).intValue();
    if (maxConnections < -1 || maxConnections == 0)
        throw new SwiftletException("Invalid Value, must be -1 (unlimited) or > 0");
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            int n = ((Integer) newValue).intValue();
            if (n < -1 || n == 0)
                throw new PropertyChangeException("Invalid Value, must be -1 (unlimited) or > 0");
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "propertyChanged (maxconnections): oldValue=" + oldValue + ", newValue=" + newValue);
            maxConnections = n;
        }
    });
}
Also used : ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory) SwiftletException(com.swiftmq.swiftlet.SwiftletException) InvalidClientIDException(javax.jms.InvalidClientIDException) UnknownHostException(java.net.UnknownHostException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 5 with ChallengeResponseFactory

use of com.swiftmq.auth.ChallengeResponseFactory in project swiftmq-ce by iitsoftware.

the class AuthStage method init.

protected void init() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init...");
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, new RequestHandler() {

        public void visited(Request request) {
            try {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + " ...");
                String password = routingConnection.getPassword();
                if (password == null)
                    throw new Exception("Authentication request by remote router but no password is defined!");
                ChallengeResponseFactory crf = (ChallengeResponseFactory) Class.forName(connectReply.getCrFactory()).newInstance();
                AuthRequest ar = new AuthRequest(crf.createResponse(connectReply.getChallenge(), password));
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", sending request: " + ar);
                routingConnection.getOutboundQueue().enqueue(ar);
                startValidTimer();
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", exception=" + e + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + e.getMessage());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.AUTH_REPREQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + "...");
            AuthReplyRequest reply = (AuthReplyRequest) request;
            if (reply.isOk()) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", launching recovery stage");
                // Launch recovery stage
                getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", disconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/exception: " + reply.getException());
                ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
            }
        }
    });
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v400.SMQRFactory.AUTH_REQ, new RequestHandler() {

        public void visited(Request request) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request);
            AuthRequest pr = (AuthRequest) request;
            AuthReplyRequest reply = new AuthReplyRequest();
            if (ctx.challengeResponseFactory.verifyResponse(connectReply.getChallenge(), pr.getResponse(), routingConnection.getPassword())) {
                reply.setOk(true);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", response ok, launching recovery stage");
                // Launch recovery stage
                getStageQueue().setStage(new XARecoveryStage(ctx, routingConnection));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/visited, request=" + request + ", invalid password, diconnect");
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/connection rejected, invalid password!");
                reply.setOk(false);
                reply.setException(new Exception("Invalid password!"));
                ctx.timerSwiftlet.addInstantTimerListener(((Long) ctx.root.getProperty("reject-disconnect-delay").getValue()).longValue(), new TimerListener() {

                    public void performTimeAction() {
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), AuthStage.this.toString() + "/disconnect timeout");
                        ctx.networkSwiftlet.getConnectionManager().removeConnection(routingConnection.getConnection());
                    }
                });
            }
            routingConnection.getOutboundQueue().enqueue(reply);
        }
    });
    if (!listener)
        getStageQueue().enqueue(new StartStageRequest());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/init done");
}
Also used : AuthRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest) RequestHandler(com.swiftmq.impl.routing.single.smqpr.RequestHandler) ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) StartStageRequest(com.swiftmq.impl.routing.single.smqpr.StartStageRequest) Request(com.swiftmq.tools.requestreply.Request) ConnectReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest) AuthRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener) AuthReplyRequest(com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest)

Aggregations

ChallengeResponseFactory (com.swiftmq.auth.ChallengeResponseFactory)7 RequestHandler (com.swiftmq.impl.routing.single.smqpr.RequestHandler)2 StartStageRequest (com.swiftmq.impl.routing.single.smqpr.StartStageRequest)2 TimerListener (com.swiftmq.swiftlet.timer.event.TimerListener)2 Request (com.swiftmq.tools.requestreply.Request)2 AuthReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.AuthReplyRequest)1 AuthRequest (com.swiftmq.impl.routing.single.smqpr.v400.AuthRequest)1 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.ConnectReplyRequest)1 AuthReplyRequest (com.swiftmq.impl.routing.single.smqpr.v942.AuthReplyRequest)1 AuthRequest (com.swiftmq.impl.routing.single.smqpr.v942.AuthRequest)1 ConnectReplyRequest (com.swiftmq.impl.routing.single.smqpr.v942.ConnectReplyRequest)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 UnknownHostException (java.net.UnknownHostException)1 InvalidClientIDException (javax.jms.InvalidClientIDException)1