01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.client;
18:
19: import java.rmi.RemoteException;
20: import java.net.URL;
21: import java.net.URLDecoder;
22:
23: public class LoginTestUtil {
24: public static Request serverRequest;
25: public static AuthenticationResponse serverResponse;
26:
27: public static void initialize() throws Exception {
28: String path = System
29: .getProperty("java.security.auth.login.config");
30: if (path == null) {
31: URL resource = ClientLoginTest.class.getClassLoader()
32: .getResource("client.login.conf");
33: if (resource != null) {
34: path = URLDecoder.decode(resource.getFile());
35: System.setProperty("java.security.auth.login.config",
36: path);
37: }
38: }
39:
40: Client.setClient(new Client() {
41: protected Response processRequest(Request req,
42: Response res, ServerMetaData server)
43: throws RemoteException {
44: serverRequest = req;
45: return serverResponse;
46: }
47: });
48: }
49:
50: static void setAuthGranted() {
51: serverResponse = new AuthenticationResponse();
52: serverResponse
53: .setIdentity(new ClientMetaData("SecretIdentity"));
54: serverResponse.setResponseCode(ResponseCodes.AUTH_GRANTED);
55: }
56:
57: static void setAuthDenied() {
58: // setup the server response
59: serverResponse = new AuthenticationResponse();
60: serverResponse.setResponseCode(ResponseCodes.AUTH_DENIED);
61: }
62: }
|