diff -cNr uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/components/Attribute.java uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/components/Attribute.java *** uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/components/Attribute.java 2010-08-23 12:21:27.000000000 +0900 --- uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/components/Attribute.java 2010-08-23 12:23:14.000000000 +0900 *************** *** 7,18 **** import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; ! public class Attribute implements Serializable { --- 7,19 ---- import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; + import java.security.MessageDigest; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; ! import ch.SWITCH.aai.uApprove.components.ConfigurationManager; public class Attribute implements Serializable { *************** *** 23,29 **** public Map attributeNames; public Map attributeDescriptions; public Collection attributeValues; ! // This function extracts all the attribute names, is the the storage format. // Keep this function for backwards compatibility and all use it for all --- 24,30 ---- public Map attributeNames; public Map attributeDescriptions; public Collection attributeValues; ! public String attributeFriendlyName; // This function extracts all the attribute names, is the the storage format. // Keep this function for backwards compatibility and all use it for all *************** *** 42,60 **** return result; } public static boolean compareAttributeRelease(String approved, String current) { StringTokenizer tokenizer = new StringTokenizer( current,ATTR_DELIMITER ); while (tokenizer.hasMoreElements()) { String attr = (String) tokenizer.nextElement(); ! if (approved.indexOf(ATTR_DELIMITER+attr+ATTR_DELIMITER) == -1) ! return false; } return true; } - - public static String serializeAttributes(Collection attributes) { JSONArray result = new JSONArray(); --- 43,116 ---- return result; } + // This function extracts all the attribute names and values, is the the storage format. + // Keep this function for backwards compatibility and all use it for all + // interaction + // with the storage: store, load, comparing + // Format: ":attr1=values1:attr2=values2:attr3=values3:" || "" + public static String serializeAttributeValues(Collection attributes) { + String result = ""; + for (Iterator iterator = attributes.iterator(); iterator + .hasNext();) { + Attribute attribute = iterator.next(); + String id = attribute.attributeID; + String valuesDigest = ""; + Collection values = attribute.attributeValues; + if ( values != null && !values.isEmpty() ) { + String attrValues = ""; + for (String value : values) + attrValues += value + ";"; + valuesDigest = digest(attrValues); + } + result += ATTR_DELIMITER + id + "=" + valuesDigest; + } + if (!result.equals("")) + result += ATTR_DELIMITER; + return result; + } + + public static String digest(String value) + { + String digestValue = ""; + if (value != null && value.length() > 0) { + try { + String salt = ConfigurationManager.getParam(ConfigurationManager.COMMON_SHARED_SECRET); + MessageDigest md = MessageDigest.getInstance("SHA-1"); + md.update(value.getBytes()); + md.update(salt.getBytes()); + byte[] digest = md.digest(); + + for (int i = 0; i < digest.length; i++) { + int d = digest[i]; + if (d < 0) { + d += 256; + } + if (d < 16) { + digestValue += "0"; + } + digestValue += Integer.toString(d, 16); + } + } catch (Exception e) { + return value; + } + } + + return digestValue; + } public static boolean compareAttributeRelease(String approved, String current) { StringTokenizer tokenizer = new StringTokenizer( current,ATTR_DELIMITER ); while (tokenizer.hasMoreElements()) { String attr = (String) tokenizer.nextElement(); ! if (approved.indexOf(ATTR_DELIMITER+attr+ATTR_DELIMITER) == -1) { ! attr = attr.replaceFirst("=.*$", ""); ! if (approved.indexOf(ATTR_DELIMITER+attr+ATTR_DELIMITER) == -1) ! return false; ! } } return true; } public static String serializeAttributes(Collection attributes) { JSONArray result = new JSONArray(); *************** *** 83,88 **** --- 139,145 ---- attribute.put("attributeNames", names); attribute.put("attributeDescriptions", descs); attribute.put("attributeValues", values); + attribute.put("attributeFriendlyName", attr.attributeFriendlyName); result.add(attribute); } *************** *** 120,125 **** --- 177,183 ---- a.attributeNames = attributeNames; a.attributeDescriptions = attributeDescriptions; a.attributeValues = attributeValues; + a.attributeFriendlyName = (String)attribute.get("attributeFriendlyName"); result.add(a); } diff -cNr uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/components/ConfigurationManager.java uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/components/ConfigurationManager.java *** uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/components/ConfigurationManager.java 2010-08-23 12:21:27.000000000 +0900 --- uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/components/ConfigurationManager.java 2010-08-23 12:23:33.000000000 +0900 *************** *** 49,55 **** public static final String HTTP_PARAM_PROVIDERID = "providerid"; public static final String HTTP_PARAM_ATTRIBUTES = "attributes"; public static final String HTTP_PARAM_PRINCIPAL = "principal"; ! private static Logger LOG = LoggerFactory.getLogger( ConfigurationManager.class ); private static ConfigurationManager configurationManager = null; private static Properties properties = null; --- 49,57 ---- public static final String HTTP_PARAM_PROVIDERID = "providerid"; public static final String HTTP_PARAM_ATTRIBUTES = "attributes"; public static final String HTTP_PARAM_PRINCIPAL = "principal"; ! public static final String HTTP_PARAM_MANDATORY_ATTRIBUTES = "mandatoryattributes"; ! public static final String HTTP_PARAM_SELECTED_ATTRIBUTES = "selectedattributes"; ! private static Logger LOG = LoggerFactory.getLogger( ConfigurationManager.class ); private static ConfigurationManager configurationManager = null; private static Properties properties = null; *************** *** 107,113 **** if (value == null || value.trim().equals("")) return "/uApprove/Controller"; } ! LOG.debug("{} => {}", new Object[] {configKey, value}); return (value != null) ? value.trim() : null; } --- 109,115 ---- if (value == null || value.trim().equals("")) return "/uApprove/Controller"; } ! LOG.debug("{} => {}", new Object[] {configKey, value}); return (value != null) ? value.trim() : null; } *************** *** 141,144 **** return true; return false; } ! } \ ファイル末尾に改行がありません --- 143,146 ---- return true; return false; } ! } diff -cNr uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/components/Metadata.java uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/components/Metadata.java *** uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/components/Metadata.java 1970-01-01 09:00:00.000000000 +0900 --- uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/components/Metadata.java 2010-08-23 12:48:08.000000000 +0900 *************** *** 0 **** --- 1,58 ---- + package ch.SWITCH.aai.uApprove.components; + + import javax.xml.namespace.QName; + import org.opensaml.xml.XMLObject; + import org.opensaml.xml.AttributeExtensibleXMLObject; + import org.opensaml.xml.util.AttributeMap; + import org.opensaml.common.xml.SAMLConstants; + import org.opensaml.saml2.metadata.EntityDescriptor; + import org.opensaml.saml2.metadata.SPSSODescriptor; + import org.opensaml.saml2.metadata.AttributeConsumingService; + import org.opensaml.saml2.metadata.RequestedAttribute; + + public class Metadata { + + public static final QName MD_QNAME = new QName("urn:mace:uapprove:metadata:1.0", "UserApproval"); + private static final String ATTR_DELIMITER = ":"; + + /** + * + * @param entity + */ + public static AttributeConsumingService getAttributeConsumingService(EntityDescriptor entity) { + SPSSODescriptor spsso = entity.getSPSSODescriptor(SAMLConstants.SAML20P_NS); + if (spsso != null) { + AttributeConsumingService defacs = spsso.getDefaultAttributeConsumingService(); + if (defacs != null) { + return defacs; + } + + for (AttributeConsumingService acs: spsso.getAttributeConsumingServices()) { + return acs; + } + } + + return null; + } + + public static String getMandatoryAttributes(EntityDescriptor entity) { + String mandatoryAttrs = ""; + + AttributeConsumingService acs = getAttributeConsumingService(entity); + if (acs == null) { + return mandatoryAttrs; + } + + for (RequestedAttribute attribute: acs.getRequestAttributes()) { + if (attribute.isRequired()) { + if (mandatoryAttrs.equals("")) { + mandatoryAttrs = ATTR_DELIMITER + attribute.getFriendlyName() + ATTR_DELIMITER; + } else { + mandatoryAttrs += attribute.getFriendlyName() + ATTR_DELIMITER; + } + } + } + + return mandatoryAttrs; + } + } diff -cNr uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfo.java uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfo.java *** uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfo.java 2010-08-23 12:21:27.000000000 +0900 --- uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfo.java 2010-08-23 12:32:44.000000000 +0900 *************** *** 62,67 **** --- 62,72 ---- abstract public void update(UserLogInfo theUserData, String theProviderId) throws UApproveException; + // Gets released atttributes + abstract public String getUserReleaseAttrs(String theUsername, + String theProvider, boolean bGlobal) throws UApproveException; + + // / Updates the provider independent part of the UserLogInfo public void update(UserLogInfo theUserData) throws UApproveException { update(theUserData, null); diff -cNr uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoFile.java uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoFile.java *** uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoFile.java 2010-08-23 12:21:27.000000000 +0900 --- uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoFile.java 2010-09-17 13:21:17.000000000 +0900 *************** *** 106,112 **** } catch (Exception e) { throw new UApproveException( "LogInfoFile:initialize: An exception occurred trying to read the file [" ! + filename + "]"); } logInfo.readFromXmlDocument(userSettingDoc); } --- 106,112 ---- } catch (Exception e) { throw new UApproveException( "LogInfoFile:initialize: An exception occurred trying to read the file [" ! + filename + "](" + e.getMessage() +")"); } logInfo.readFromXmlDocument(userSettingDoc); } *************** *** 313,316 **** --- 313,332 ---- return; } + public synchronized String getUserReleaseAttrs(String theUsername, + String theProvider, boolean bGlobal) throws UApproveException { + UserLogInfo userInfo = logInfo.data.get(theUsername); + + String global; + if (bGlobal) { + global = "yes"; + } else { + global = "no"; + } + if (userInfo != null && userInfo.getGlobal().equals(global)) { + return userInfo.getAttributesForProviderId(theProvider); + } else { + return null; + } + } } diff -cNr uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoJdbc.java uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoJdbc.java *** uApprove-2.1.3.org/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoJdbc.java 2010-08-23 12:21:27.000000000 +0900 --- uApprove-2.1.3/common/src/main/java/ch/SWITCH/aai/uApprove/storage/LogInfoJdbc.java 2010-08-23 12:41:01.000000000 +0900 *************** *** 73,78 **** --- 73,80 ---- public static final String selIdxAttrApproval = "selIdxAttrApproval"; + public static final String selReleaseAttrs = "selReleaseAttrs"; + public static final String selIdxAttrApprovalGlobal = "selIdxAttrApprovalGlobal"; public static final String insProviderAccess = "insProviderAccess"; *************** *** 808,811 **** --- 810,842 ---- } + public synchronized String getUserReleaseAttrs(String theUsername, + String theProvider, boolean bGlobal) throws UApproveException { + + LOG.debug("LogInfoJdbc.getUserReleaseAttrs: get released attributes for user " + + theUsername + " provider = " + theProvider + " with global access " + bGlobal); + + try { + String theSQL = (String) theSqlCmds.getProperty(keySqlCmd.selReleaseAttrs); + theSQL = theSQL.replaceFirst("\\?", theUsername); + + if (bGlobal == false) + theSQL = theSQL.replaceFirst("\\?", theProvider); + + ResultSet rs = theDB.execSqlFT(theSQL, true); + + String attributesReleased = null; + + if (rs != null && rs.next()) { + attributesReleased = rs.getString(1); + } + + return attributesReleased; + } catch (SQLException ex) { + LOG.error("LogInfoJdbc.getUserReleaseAttrs:" + + "cannot find released attributes for user "+theUsername+", provider = {} with with global access {}", + theProvider, bGlobal); + throw new UApproveException(ex); + } + } } diff -cNr uApprove-2.1.3.org/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/AttributeDumper.java uApprove-2.1.3/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/AttributeDumper.java *** uApprove-2.1.3.org/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/AttributeDumper.java 2010-08-23 12:21:27.000000000 +0900 --- uApprove-2.1.3/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/AttributeDumper.java 2010-08-23 12:43:31.000000000 +0900 *************** *** 5,13 **** --- 5,15 ---- import java.util.HashMap; import java.util.Iterator; import java.util.Map; + import java.util.List; import java.util.Locale; + import org.opensaml.saml2.core.NameID; import org.opensaml.saml2.metadata.provider.MetadataProvider; import org.opensaml.saml2.metadata.provider.MetadataProviderException; import org.slf4j.Logger; *************** *** 21,26 **** --- 23,30 ---- import edu.internet2.middleware.shibboleth.common.profile.provider.BaseSAMLProfileRequestContext; import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration; import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager; + import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder; + import edu.internet2.middleware.shibboleth.common.attribute.encoding.SAML2AttributeEncoder; public class AttributeDumper { private static Logger LOG = LoggerFactory.getLogger(AttributeDumper.class); *************** *** 72,78 **** throw new UApproveException(e); } requestCtx.setMetadataProvider(metadataProvider); ! Map attributes; try { attributes = saml2AA.getAttributes(requestCtx); --- 76,82 ---- throw new UApproveException(e); } requestCtx.setMetadataProvider(metadataProvider); ! Map attributes; try { attributes = saml2AA.getAttributes(requestCtx); *************** *** 91,101 **** Object valueObj = iter.next(); //String value = valueObj instanceof String ? (String)valueObj : "Non-string attribute value"; if (valueObj != null && !valueObj.toString().trim().equals("")) { ! LOG.trace(valueObj.toString()); ! attributeValues.add(valueObj.toString()); } } ! LOG.debug("Attribute '{}' has {} value(s)", attr.getId(), attributeValues.size()); if (attributeValues.size() == 0) --- 95,110 ---- Object valueObj = iter.next(); //String value = valueObj instanceof String ? (String)valueObj : "Non-string attribute value"; if (valueObj != null && !valueObj.toString().trim().equals("")) { ! if (valueObj instanceof NameID) { ! LOG.trace(((NameID)valueObj).getNameQualifier() + "!" + ((NameID)valueObj).getSPNameQualifier() + "!" + ((NameID)valueObj).getValue()); ! attributeValues.add(((NameID)valueObj).getNameQualifier() + "!" + ((NameID)valueObj).getSPNameQualifier() + "!" + ((NameID)valueObj).getValue()); ! } else { ! LOG.trace(valueObj.toString()); ! attributeValues.add(valueObj.toString()); ! } } } ! LOG.debug("Attribute '{}' has {} value(s)", attr.getId(), attributeValues.size()); if (attributeValues.size() == 0) *************** *** 115,126 **** attributeDescriptions.put(key.getLanguage(), (String) attr.getDisplayDescriptions().get(key)); } Attribute a = new Attribute(); a.attributeID = attr.getId(); a.attributeNames = attributeNames; a.attributeDescriptions = attributeDescriptions; a.attributeValues = attributeValues; ! result.add(a); } --- 124,147 ---- attributeDescriptions.put(key.getLanguage(), (String) attr.getDisplayDescriptions().get(key)); } + String attributeFriendlyName = null; + List encoders = attr.getEncoders(); + for (int i = 0; i < encoders.size(); i++) { + if (encoders.get(i) instanceof SAML2AttributeEncoder) { + attributeFriendlyName = ((SAML2AttributeEncoder) encoders.get(i)).getFriendlyName(); + } + } + if (attributeFriendlyName == null) { + attributeFriendlyName = attr.getId(); + } + Attribute a = new Attribute(); a.attributeID = attr.getId(); a.attributeNames = attributeNames; a.attributeDescriptions = attributeDescriptions; a.attributeValues = attributeValues; ! a.attributeFriendlyName = attributeFriendlyName; ! result.add(a); } diff -cNr uApprove-2.1.3.org/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/Plugin.java uApprove-2.1.3/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/Plugin.java *** uApprove-2.1.3.org/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/Plugin.java 2010-08-23 12:21:27.000000000 +0900 --- uApprove-2.1.3/idp-plugin/src/main/java/ch/SWITCH/aai/uApprove/idpplugin/Plugin.java 2010-08-23 12:43:54.000000000 +0900 *************** *** 17,26 **** --- 17,29 ---- import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.opensaml.saml2.metadata.provider.MetadataProvider; + import org.opensaml.saml2.metadata.provider.MetadataProviderException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.SWITCH.aai.uApprove.components.Attribute; + import ch.SWITCH.aai.uApprove.components.Metadata; import ch.SWITCH.aai.uApprove.components.ConfigurationManager; import ch.SWITCH.aai.uApprove.components.TermsOfUseManager; import ch.SWITCH.aai.uApprove.components.UApproveException; *************** *** 38,43 **** --- 41,55 ---- import edu.vt.middleware.crypt.symmetric.SymmetricAlgorithm; import edu.vt.middleware.crypt.util.Base64Converter; + + + import ch.SWITCH.aai.uApprove.components.Attribute; + import edu.internet2.middleware.shibboleth.common.attribute.AttributeRequestException; + import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute; + import edu.internet2.middleware.shibboleth.common.attribute.provider.SAML2AttributeAuthority; + import edu.internet2.middleware.shibboleth.common.profile.provider.BaseSAMLProfileRequestContext; + import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration; + import edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager; /** * Class Plugin: * *************** *** 88,93 **** --- 100,106 ---- boolean globalARA, boolean approvalGiven) throws UApproveException { LOG.info("continue2Idp, reason: " + reason); + // create user hack if (userInfo == null) { userInfo = storage.addUserLogInfoData(username, "1.0", new Date() *************** *** 117,127 **** // method to continue to the uApprove web application (leave IdP) private String post2Viewer(String reason, boolean resetConsent, String returnURL, String principal, String entityId, ! Collection attributesReleased, HttpServletRequest request, LoginContext loginCtx) throws UApproveException, PassiveAuthenticationException { LOG.info("Continue to uApprove viewer, reason: " + reason); LOG.debug(" returnURL=" + returnURL); ! boolean isPassive = loginCtx.isPassiveAuthRequired(); boolean isPassiveSupported = ConfigurationManager.makeBoolean(ConfigurationManager.getParam(ConfigurationManager.PLUGIN_ISPASSIVE_SUPPORT)); LOG.debug("isPassive={}, isPassiveSupport={}", isPassive, isPassiveSupported); --- 130,141 ---- // method to continue to the uApprove web application (leave IdP) private String post2Viewer(String reason, boolean resetConsent, String returnURL, String principal, String entityId, ! Collection attributesReleased, String mandatoryAttributes, ! HttpServletRequest request, LoginContext loginCtx) throws UApproveException, PassiveAuthenticationException { LOG.info("Continue to uApprove viewer, reason: " + reason); LOG.debug(" returnURL=" + returnURL); ! boolean isPassive = loginCtx.isPassiveAuthRequired(); boolean isPassiveSupported = ConfigurationManager.makeBoolean(ConfigurationManager.getParam(ConfigurationManager.PLUGIN_ISPASSIVE_SUPPORT)); LOG.debug("isPassive={}, isPassiveSupport={}", isPassive, isPassiveSupported); *************** *** 145,150 **** --- 159,170 ---- : ""; LOG.debug(" action=" + action); + String attributesSelected = ""; + if (reason.equals(CONTV_REASON_ATTRCHANGED)) { + attributesSelected = Attribute.serializeAttributeIDs(attributesReleased); + } + LOG.debug("attributesSelected=" + attributesSelected); + String postForm = "" + " " + "