Skip to content

Commit 1330559

Browse files
committed
DefaultLogoutAPIAuthenticatorCmd: Refactor and implement the logout mechanism
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent ac3adfe commit 1330559

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.api.auth;
18+
19+
import com.cloud.api.response.ApiResponseSerializer;
20+
import com.cloud.user.Account;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiErrorCode;
23+
import org.apache.cloudstack.api.BaseCmd;
24+
import org.apache.cloudstack.api.ServerApiException;
25+
import org.apache.cloudstack.api.response.LogoutCmdResponse;
26+
import org.apache.log4j.Logger;
27+
28+
import javax.servlet.http.HttpSession;
29+
import java.util.Map;
30+
31+
@APICommand(name = "logout", description = "Logs out the user", responseObject = LogoutCmdResponse.class, entityType = {})
32+
public class DefaultLogoutAPIAuthenticatorCmd extends BaseCmd implements APIAuthenticator {
33+
34+
public static final Logger s_logger = Logger.getLogger(DefaultLoginAPIAuthenticatorCmd.class.getName());
35+
private static final String s_name = "logoutresponse";
36+
37+
/////////////////////////////////////////////////////
38+
/////////////// API Implementation///////////////////
39+
/////////////////////////////////////////////////////
40+
41+
@Override
42+
public String getCommandName() {
43+
return s_name;
44+
}
45+
46+
@Override
47+
public long getEntityOwnerId() {
48+
return Account.ACCOUNT_TYPE_NORMAL;
49+
}
50+
51+
@Override
52+
public void execute() throws ServerApiException {
53+
// We should never reach here
54+
throw new ServerApiException(ApiErrorCode.METHOD_NOT_ALLOWED, "This is an authentication api, cannot be used directly");
55+
}
56+
57+
@Override
58+
public String authenticate(String command, Map<String, Object[]> params, HttpSession session, String remoteAddress, String responseType, StringBuilder auditTrailSb) throws ServerApiException {
59+
auditTrailSb.append("=== Logging out ===");
60+
LogoutCmdResponse response = new LogoutCmdResponse();
61+
response.setDescription("success");
62+
response.setResponseName(getCommandName());
63+
return ApiResponseSerializer.toSerializedString(response, responseType);
64+
}
65+
66+
@Override
67+
public APIAuthenticationType getAPIType() {
68+
return APIAuthenticationType.LOGOUT_API;
69+
}
70+
}

0 commit comments

Comments
 (0)