001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: XACMLSDKUtils.java,v 1.3 2008/06/25 05:48:10 qcheng Exp $ 026 * 027 */ 028 029 030package com.sun.identity.xacml.common; 031 032import com.sun.identity.shared.configuration.SystemPropertiesManager; 033import com.sun.identity.shared.debug.Debug; 034import com.sun.identity.shared.locale.Locale; 035import com.sun.identity.saml2.common.SAML2SDKUtils; 036import com.sun.identity.xacml.context.Attribute; 037import com.sun.identity.xacml.context.ContextFactory; 038import com.sun.identity.xacml.context.Decision; 039import java.security.SecureRandom; 040import java.lang.reflect.Constructor; 041import java.lang.reflect.InvocationTargetException; 042import java.net.URI; 043import java.util.HashMap; 044import java.util.List; 045import java.util.Map; 046import java.util.ResourceBundle; 047import org.w3c.dom.Element; 048 049/** 050 * The <code>XACMLSDKUtils</code> contains utility methods for XACML 2.0 051 * implementation. 052 * 053 * @supported.all.api 054 */ 055public class XACMLSDKUtils extends SAML2SDKUtils { 056 // 057 // This utility class will be run on client side as well, 058 // so DO NOT add any static block which will not run on client side. 059 // 060 061 // The deugging instance 062 public static Debug debug = Debug.getInstance("libXACML"); 063 064 // XACML resource bundle name 065 public static final String XACML_RESOURCE_BUNDLE_NAME = "libXACML"; 066 067 // The resource bundle for XACML implementation. 068 public static ResourceBundle xacmlResourceBundle = Locale. 069 getInstallResourceBundle(XACML_RESOURCE_BUNDLE_NAME); 070 071 /** 072 * Defines mapping between interface and implementation class, 073 * the properties are read from AMConfig.properties in following format: 074 * com.sun.identity.xacml.sdk.mapping.<interface>=<implementation_class> 075 * e.g. 076 * com.sun.identity.xacml.sdk.mapping.Assertion=com.xxx.xacml.RequestImpL 077 */ 078 private static Map classMapping = new HashMap(); 079 080 /** 081 * List of Interfaces in context package which could have 082 * customized implementation 083 */ 084 private static String[] interfaceNames = { 085 XACMLConstants.REQUEST, 086 XACMLConstants.SUBJECT, 087 XACMLConstants.RESOURCE, 088 XACMLConstants.ACTION, 089 XACMLConstants.ATTRIBUTE, 090 XACMLConstants.ATTRIBUTE_VALUE, 091 XACMLConstants.RESOURCE_CONTENT, 092 XACMLConstants.XACML_AUTHZ_DECISION_QUERY }; 093 094 static { 095 // initialize class mapper 096 int len = interfaceNames.length; 097 for (int i = 0; i < len; i++) { 098 String iName = interfaceNames[i]; 099 try { 100 String implClass = SystemPropertiesManager.get( 101 XACMLConstants.SDK_CLASS_MAPPING + iName); 102 if (implClass != null && implClass.trim().length() != 0) { 103 // try it out 104 if (debug.messageEnabled()) { 105 debug.message("XACMLSDKUtils.init: mapper for " + iName 106 + "=" + implClass); 107 } 108 classMapping.put(iName, Class.forName(implClass.trim())); 109 } 110 } catch (ClassNotFoundException cnfe) { 111 debug.error("XACMLSDKUtils.init: " + iName, cnfe); 112 } 113 } 114 } 115 116 /** 117 * Protected contstructor. 118 */ 119 protected XACMLSDKUtils() {} 120 121 122 123 public static Attribute createAttribute(List values, URI attributeId, 124 URI dataType, String issuer) throws XACMLException 125 { 126 ContextFactory factory = ContextFactory.getInstance(); 127 Attribute attr = null; 128 attr = factory.getInstance().createAttribute(); 129 attr.setAttributeId(attributeId); 130 attr.setDataType(dataType); 131 attr.setAttributeValues(values);; 132 attr.setIssuer(issuer); 133 return attr; 134 } 135 136 public static boolean isValidDecision(Decision decision) { 137 boolean valid = false; 138 if (decision != null) { 139 String value = decision.getValue(); 140 valid = isValidDecision(value); 141 } 142 return valid; 143 } 144 145 public static boolean isValidDecision(String value) { 146 boolean valid = false; 147 if (value != null) { 148 if (value.equals(XACMLConstants.PERMIT) 149 || value.equals(XACMLConstants.DENY) 150 || value.equals(XACMLConstants.INDETERMINATE) 151 || value.equals(XACMLConstants.NOT_APPLICABLE)) { 152 valid = true; 153 } 154 } 155 return valid; 156 } 157 158 public static boolean isValidStatusMessage(String value) { 159 boolean valid = true; 160 //FIXME: add validation 161 return valid; 162 } 163 164 public static boolean isValidStatusCode(String value) { 165 boolean valid = true; 166 //FIXME: add validation 167 return valid; 168 } 169 170 public static boolean isValidMinorStatusCode(String value) { 171 boolean valid = true; 172 //FIXME: add validation 173 return valid; 174 } 175 176 public static String quote(String s) { 177 String val = null; 178 if (s == null) { 179 val = "\"\""; 180 } else { 181 val = "\"" + s + "\""; 182 } 183 return val; 184 } 185 186}
Copyright © 2010-2017, ForgeRock All Rights Reserved.