01: /*
02: * Copyright 2000-2001,2004 The Apache Software Foundation.
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.apache.wsrp4j.util;
18:
19: import javax.portlet.PortletRequest;
20:
21: public class AuthenticationInfoHelper {
22: /**
23: * No authentication was done
24: **/
25: public static final String WSRP_NONE = "wsrp:none";
26:
27: /**
28: * End-User identified themselves using password/username scenario
29: **/
30: public static final String WSRP_PASSWD = "wsrp:password";
31:
32: /**
33: * End-User presented a security certificate
34: **/
35: public static final String WSRP_CERT = "wsrp:certificate";
36:
37: /**
38: * Get a string representation of the user authentification
39: * as defined in the WSRP spec. from a passed authentification
40: * info defined in the portlet spec. If the passed value could not
41: * be matched the same string is returned.
42: *
43: * @param jsrAuthInfo Authentification info as defined in the portlet spec
44: * @return The authentification info as defined in the WSRP spec. or the
45: * argument if no match could be made.
46: **/
47: public static String getWsrpFromPortlet(String jsrAuthInfo) {
48: if (jsrAuthInfo == null) {
49: return WSRP_NONE;
50: } else if (jsrAuthInfo == PortletRequest.BASIC_AUTH
51: || jsrAuthInfo == PortletRequest.FORM_AUTH
52: || jsrAuthInfo.equals(PortletRequest.BASIC_AUTH)
53: || jsrAuthInfo.equals(PortletRequest.FORM_AUTH)) {
54: return WSRP_PASSWD;
55:
56: } else if (jsrAuthInfo == PortletRequest.CLIENT_CERT_AUTH
57: || jsrAuthInfo.equals(PortletRequest.CLIENT_CERT_AUTH)) {
58:
59: return WSRP_CERT;
60:
61: } else {
62:
63: return jsrAuthInfo;
64: }
65: }
66:
67: /**
68: * Get the authentification info as defined in the portlet spec
69: * from a passed authentification info defined in the WSRP spec..
70: * If wsrp:none is passed <code>null</code> is returned. In case the
71: * passed info could not be matched the same string is returned.
72: *
73: * @param wsrpInfo
74: * @return
75: **/
76: public static String getPortletFromWsrp(String wsrpInfo) {
77: if (wsrpInfo.equals(WSRP_PASSWD)) {
78: return PortletRequest.FORM_AUTH;
79:
80: } else if (wsrpInfo.equals(WSRP_CERT)) {
81: return PortletRequest.CLIENT_CERT_AUTH;
82:
83: } else if (wsrpInfo.equals(WSRP_NONE)) {
84:
85: return null;
86:
87: } else {
88:
89: return wsrpInfo;
90: }
91: }
92: }
|