01: /*
02: * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.wso2.esb.modules.authentication.handler;
18:
19: import org.apache.axis2.AxisFault;
20: import org.apache.axis2.context.MessageContext;
21: import org.apache.axis2.context.OperationContext;
22: import org.apache.axis2.context.ServiceContext;
23: import org.apache.axis2.handlers.AbstractHandler;
24: import org.wso2.esb.services.AbstractESBAdmin;
25:
26: /*
27: * This will Authenticate admin services requests
28: */
29: public class AuthenticationHandler extends AbstractHandler {
30:
31: private static final String LOGIN_ADMIN = "LoginAdmin";
32: private static final String LOGIN_METHOD = "login";
33:
34: public InvocationResponse invoke(MessageContext msgContext)
35: throws AxisFault {
36:
37: OperationContext opCtx = msgContext.getOperationContext();
38: ServiceContext serviceCtx = opCtx.getServiceContext();
39:
40: if (serviceCtx.getAxisService().getName().equals(LOGIN_ADMIN)
41: && opCtx.getAxisOperation().getName().getLocalPart()
42: .equals(LOGIN_METHOD)) {
43: return InvocationResponse.CONTINUE;
44: }
45:
46: String status = (String) serviceCtx.getServiceGroupContext()
47: .getProperty(AbstractESBAdmin.LOGGED);
48:
49: if (!"true".equals(status)) {
50: throw new AxisFault("Access Denied. Please login first.");
51: }
52:
53: return InvocationResponse.CONTINUE;
54: }
55: }
|