当前位置: 首页>>代码示例>>Java>>正文


Java SAMLAssertion.sign方法代码示例

本文整理汇总了Java中gov.nih.nci.cagrid.opensaml.SAMLAssertion.sign方法的典型用法代码示例。如果您正苦于以下问题:Java SAMLAssertion.sign方法的具体用法?Java SAMLAssertion.sign怎么用?Java SAMLAssertion.sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gov.nih.nci.cagrid.opensaml.SAMLAssertion的用法示例。


在下文中一共展示了SAMLAssertion.sign方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAuthenticationAssertion

import gov.nih.nci.cagrid.opensaml.SAMLAssertion; //导入方法依赖的package包/类
public synchronized SAMLAssertion getAuthenticationAssertion(String uid, String firstName, String lastName,
    String email) throws DorianInternalFault {
    try {
        org.apache.xml.security.Init.init();
        X509Certificate cert = getIdPCertificate();
        PrivateKey key = getIdPKey();
        GregorianCalendar cal = new GregorianCalendar();
        Date start = cal.getTime();
        cal.add(Calendar.MINUTE, 2);
        Date end = cal.getTime();
        String issuer = cert.getSubjectDN().toString();
        String federation = cert.getSubjectDN().toString();
        String ipAddress = null;
        String subjectDNS = null;

        SAMLNameIdentifier ni1 = new SAMLNameIdentifier(uid, federation,
            "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
        SAMLSubject sub = new SAMLSubject(ni1, null, null, null);
        sub.addConfirmationMethod(SAMLSubject.CONF_BEARER);
        SAMLNameIdentifier ni2 = new SAMLNameIdentifier(uid, federation,
            "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
        SAMLSubject sub2 = new SAMLSubject(ni2, null, null, null);
        sub2.addConfirmationMethod(SAMLSubject.CONF_BEARER);
        SAMLAuthenticationStatement auth = new SAMLAuthenticationStatement(sub,
            "urn:oasis:names:tc:SAML:1.0:am:password", new Date(), ipAddress, subjectDNS, null);

        QName quid = new QName(SAMLConstants.UID_ATTRIBUTE_NAMESPACE, SAMLConstants.UID_ATTRIBUTE);
        List<String> vals1 = new ArrayList<String>();
        vals1.add(uid);
        SAMLAttribute uidAtt = new SAMLAttribute(quid.getLocalPart(), quid.getNamespaceURI(), null, 0, vals1);

        QName qfirst = new QName(SAMLConstants.FIRST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.FIRST_NAME_ATTRIBUTE);
        List<String> vals2 = new ArrayList<String>();
        vals2.add(firstName);
        SAMLAttribute firstNameAtt = new SAMLAttribute(qfirst.getLocalPart(), qfirst.getNamespaceURI(), null, 0,
            vals2);

        QName qLast = new QName(SAMLConstants.LAST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.LAST_NAME_ATTRIBUTE);
        List<String> vals3 = new ArrayList<String>();
        vals3.add(lastName);
        SAMLAttribute lastNameAtt = new SAMLAttribute(qLast.getLocalPart(), qLast.getNamespaceURI(), null, 0, vals3);

        QName qemail = new QName(SAMLConstants.EMAIL_ATTRIBUTE_NAMESPACE, SAMLConstants.EMAIL_ATTRIBUTE);
        List<String> vals4 = new ArrayList<String>();
        vals4.add(email);
        SAMLAttribute emailAtt = new SAMLAttribute(qemail.getLocalPart(), qemail.getNamespaceURI(), null, 0, vals4);

        List<SAMLAttribute> atts = new ArrayList<SAMLAttribute>();
        atts.add(uidAtt);
        atts.add(firstNameAtt);
        atts.add(lastNameAtt);
        atts.add(emailAtt);

        SAMLAttributeStatement attState = new SAMLAttributeStatement(sub2, atts);

        List<SAMLSubjectStatement> l = new ArrayList<SAMLSubjectStatement>();
        l.add(auth);
        l.add(attState);

        SAMLAssertion saml = new SAMLAssertion(issuer, start, end, null, null, l);
        List<X509Certificate> a = new ArrayList<X509Certificate>();
        a.add(cert);
        saml.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, key, a);

        return saml;
    } catch (Exception e) {
        logError(e.getMessage(), e);
        DorianInternalFault fault = new DorianInternalFault();
        fault.setFaultString("Error creating SAML Assertion.");
        FaultHelper helper = new FaultHelper(fault);
        helper.addFaultCause(e);
        fault = (DorianInternalFault) helper.getFault();
        throw fault;

    }

}
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:78,代码来源:AssertionCredentialsManager.java

示例2: getSAMLAssertion

import gov.nih.nci.cagrid.opensaml.SAMLAssertion; //导入方法依赖的package包/类
private SAMLAssertion getSAMLAssertion(String id, IdPContainer idp, Date start, Date end, String method)
    throws Exception {
    try {
        org.apache.xml.security.Init.init();
        X509Certificate cert = idp.getCert();
        PrivateKey key = idp.getKey();
        String firstName = "first" + id;
        String lastName = "first" + id;
        String email = id + "@test.com";

        String issuer = cert.getSubjectDN().toString();
        String federation = cert.getSubjectDN().toString();
        String ipAddress = null;
        String subjectDNS = null;
        SAMLNameIdentifier ni = new SAMLNameIdentifier(id, federation,
            "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
        SAMLNameIdentifier ni2 = new SAMLNameIdentifier(id, federation,
            "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
        SAMLSubject sub = new SAMLSubject(ni, null, null, null);
        SAMLSubject sub2 = new SAMLSubject(ni2, null, null, null);
        SAMLAuthenticationStatement auth = new SAMLAuthenticationStatement(sub, method, new Date(), ipAddress,
            subjectDNS, null);

        QName quid = new QName(SAMLConstants.UID_ATTRIBUTE_NAMESPACE, SAMLConstants.UID_ATTRIBUTE);
        List vals1 = new ArrayList();
        vals1.add(id);
        SAMLAttribute uidAtt = new SAMLAttribute(quid.getLocalPart(), quid.getNamespaceURI(), quid, 0, vals1);

        QName qfirst = new QName(SAMLConstants.FIRST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.FIRST_NAME_ATTRIBUTE);
        List vals2 = new ArrayList();
        vals2.add(firstName);
        SAMLAttribute firstNameAtt = new SAMLAttribute(qfirst.getLocalPart(), qfirst.getNamespaceURI(), qfirst, 0,
            vals2);

        QName qLast = new QName(SAMLConstants.LAST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.LAST_NAME_ATTRIBUTE);
        List vals3 = new ArrayList();
        vals3.add(lastName);
        SAMLAttribute lastNameAtt = new SAMLAttribute(qLast.getLocalPart(), qLast.getNamespaceURI(), qLast, 0,
            vals3);

        QName qemail = new QName(SAMLConstants.EMAIL_ATTRIBUTE_NAMESPACE, SAMLConstants.EMAIL_ATTRIBUTE);
        List vals4 = new ArrayList();
        vals4.add(email);
        SAMLAttribute emailAtt = new SAMLAttribute(qemail.getLocalPart(), qemail.getNamespaceURI(), qemail, 0,
            vals4);

        List atts = new ArrayList();
        atts.add(uidAtt);
        atts.add(firstNameAtt);
        atts.add(lastNameAtt);
        atts.add(emailAtt);
        SAMLAttributeStatement attState = new SAMLAttributeStatement(sub2, atts);

        List l = new ArrayList();
        l.add(auth);
        l.add(attState);

        SAMLAssertion saml = new SAMLAssertion(issuer, start, end, null, null, l);
        List a = new ArrayList();
        a.add(cert);
        saml.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, key, a);

        return saml;
    } catch (Exception e) {
        DorianInternalFault fault = new DorianInternalFault();
        fault.setFaultString("Error creating SAML Assertion.");
        FaultHelper helper = new FaultHelper(fault);
        helper.addFaultCause(e);
        fault = (DorianInternalFault) helper.getFault();
        throw fault;

    }
}
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:74,代码来源:TestDorian.java

示例3: getTrustedIdp

import gov.nih.nci.cagrid.opensaml.SAMLAssertion; //导入方法依赖的package包/类
private IdPContainer getTrustedIdp(String name, boolean nonStandartCert) throws Exception {
    TrustedIdP idp = new TrustedIdP();
    idp.setName(name);
    idp.setDisplayName(name);
    idp.setStatus(TrustedIdPStatus.Active);
    idp.setUserPolicyClass(AutoApprovalPolicy.class.getName());
    idp.setAuthenticationMethod(getAuthenticationMethods());
    idp.setAuthenticationServiceURL("https://localhost");
    idp.setAuthenticationServiceIdentity("/O=caGrid/OU=Testing/CN=Admin");
    SAMLAttributeDescriptor uid = new SAMLAttributeDescriptor();
    uid.setNamespaceURI(SAMLConstants.UID_ATTRIBUTE_NAMESPACE);
    uid.setName(SAMLConstants.UID_ATTRIBUTE);
    idp.setUserIdAttributeDescriptor(uid);

    SAMLAttributeDescriptor firstName = new SAMLAttributeDescriptor();
    firstName.setNamespaceURI(SAMLConstants.FIRST_NAME_ATTRIBUTE_NAMESPACE);
    firstName.setName(SAMLConstants.FIRST_NAME_ATTRIBUTE);
    idp.setFirstNameAttributeDescriptor(firstName);

    SAMLAttributeDescriptor lastName = new SAMLAttributeDescriptor();
    lastName.setNamespaceURI(SAMLConstants.LAST_NAME_ATTRIBUTE_NAMESPACE);
    lastName.setName(SAMLConstants.LAST_NAME_ATTRIBUTE);
    idp.setLastNameAttributeDescriptor(lastName);

    SAMLAttributeDescriptor email = new SAMLAttributeDescriptor();
    email.setNamespaceURI(SAMLConstants.EMAIL_ATTRIBUTE_NAMESPACE);
    email.setName(SAMLConstants.EMAIL_ATTRIBUTE);
    idp.setEmailAttributeDescriptor(email);
    String id = null;
    String subject = null;
    if (nonStandartCert) {
        id = "Non Standard" + name;
    } else {
        id = name;
    }

    subject = Utils.CA_SUBJECT_PREFIX + ",CN=" + id;
    Credential cred = ca.createIdentityCertificate(id);
    X509Certificate cert = cred.getCertificate();
    assertNotNull(cert);
    assertEquals(cert.getSubjectDN().getName(), subject);
    idp.setIdPCertificate(CertUtil.writeCertificate(cert));

    GregorianCalendar cal2 = new GregorianCalendar();
    Date start2 = cal2.getTime();
    cal2.add(Calendar.MINUTE, 2);
    Date end2 = cal2.getTime();
    String issuer = cert.getSubjectDN().toString();
    String federation = cert.getSubjectDN().toString();
    String ipAddress = null;
    String subjectDNS = null;
    SAMLNameIdentifier ni = new SAMLNameIdentifier(name, federation,
        "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
    SAMLSubject sub = new SAMLSubject(ni, null, null, null);
    SAMLAuthenticationStatement auth = new SAMLAuthenticationStatement(sub,
        "urn:oasis:names:tc:SAML:1.0:am:password", new Date(), ipAddress, subjectDNS, null);

    List l = new ArrayList();
    l.add(auth);
    SAMLAssertion saml = new SAMLAssertion(issuer, start2, end2, null, null, l);
    List a = new ArrayList();
    a.add(cert);
    saml.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, cred.getPrivateKey(), a);
    return new IdPContainer(idp, cert, saml);
}
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:66,代码来源:TestTrustedIdPManager.java

示例4: getAuthenticationAssertion

import gov.nih.nci.cagrid.opensaml.SAMLAssertion; //导入方法依赖的package包/类
public synchronized SAMLAssertion getAuthenticationAssertion(String uid, String firstName, String lastName, String email) throws DorianInternalException {
	try {
		// org.apache.xml.security.Init.init();
		X509Certificate cert = getIdPCertificate();
		PrivateKey key = getIdPKey();
		GregorianCalendar cal = new GregorianCalendar();
		Date start = cal.getTime();
		cal.add(Calendar.MINUTE, 2);
		Date end = cal.getTime();
		String issuer = cert.getSubjectDN().toString();
		String federation = cert.getSubjectDN().toString();
		String ipAddress = null;
		String subjectDNS = null;

		SAMLNameIdentifier ni1 = new SAMLNameIdentifier(uid, federation, "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
		SAMLSubject sub = new SAMLSubject(ni1, null, null, null);
		sub.addConfirmationMethod(SAMLSubject.CONF_BEARER);
		SAMLNameIdentifier ni2 = new SAMLNameIdentifier(uid, federation, "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
		SAMLSubject sub2 = new SAMLSubject(ni2, null, null, null);
		sub2.addConfirmationMethod(SAMLSubject.CONF_BEARER);
		SAMLAuthenticationStatement auth = new SAMLAuthenticationStatement(sub, "urn:oasis:names:tc:SAML:1.0:am:password", new Date(), ipAddress, subjectDNS, null);

		QName quid = new QName(SAMLConstants.UID_ATTRIBUTE_NAMESPACE, SAMLConstants.UID_ATTRIBUTE);
		List<String> vals1 = new ArrayList<String>();
		vals1.add(uid);
		SAMLAttribute uidAtt = new SAMLAttribute(quid.getLocalPart(), quid.getNamespaceURI(), null, 0, vals1);

		QName qfirst = new QName(SAMLConstants.FIRST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.FIRST_NAME_ATTRIBUTE);
		List<String> vals2 = new ArrayList<String>();
		vals2.add(firstName);
		SAMLAttribute firstNameAtt = new SAMLAttribute(qfirst.getLocalPart(), qfirst.getNamespaceURI(), null, 0, vals2);

		QName qLast = new QName(SAMLConstants.LAST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.LAST_NAME_ATTRIBUTE);
		List<String> vals3 = new ArrayList<String>();
		vals3.add(lastName);
		SAMLAttribute lastNameAtt = new SAMLAttribute(qLast.getLocalPart(), qLast.getNamespaceURI(), null, 0, vals3);

		QName qemail = new QName(SAMLConstants.EMAIL_ATTRIBUTE_NAMESPACE, SAMLConstants.EMAIL_ATTRIBUTE);
		List<String> vals4 = new ArrayList<String>();
		vals4.add(email);
		SAMLAttribute emailAtt = new SAMLAttribute(qemail.getLocalPart(), qemail.getNamespaceURI(), null, 0, vals4);

		List<SAMLAttribute> atts = new ArrayList<SAMLAttribute>();
		atts.add(uidAtt);
		atts.add(firstNameAtt);
		atts.add(lastNameAtt);
		atts.add(emailAtt);

		SAMLAttributeStatement attState = new SAMLAttributeStatement(sub2, atts);

		List<SAMLSubjectStatement> l = new ArrayList<SAMLSubjectStatement>();
		l.add(auth);
		l.add(attState);

		SAMLAssertion saml = new SAMLAssertion(issuer, start, end, null, null, l);
		saml = SAMLUtils.canonicalizeSAMLAssertion(saml);
		List<X509Certificate> a = new ArrayList<X509Certificate>();
		a.add(cert);

		

		saml.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, key, a);

		return saml;
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		DorianInternalException fault = FaultHelper.createFaultException(DorianInternalException.class, "Error creating SAML Assertion.");
		FaultHelper.addMessage(fault, e.getMessage());
		throw fault;

	}

}
 
开发者ID:NCIP,项目名称:cagrid2,代码行数:74,代码来源:AssertionCredentialsManager.java

示例5: getSAMLAssertion

import gov.nih.nci.cagrid.opensaml.SAMLAssertion; //导入方法依赖的package包/类
private SAMLAssertion getSAMLAssertion(String id, IdPContainer idp, Date start, Date end, String method) throws Exception {
	try {
		org.apache.xml.security.Init.init();
		String certStr = CertUtil.writeCertificate(idp.getCert());
		X509Certificate cert = CertUtil.loadCertificate(certStr);
		String keyStr = KeyUtil.writePrivateKey(idp.getKey(), "test");
		PrivateKey key = KeyUtil.loadPrivateKey(new ByteArrayInputStream(keyStr.getBytes()), "test");
		String firstName = "first" + id;
		String lastName = "first" + id;
		String email = id + "@test.com";

		String issuer = cert.getSubjectDN().toString();
		String federation = cert.getSubjectDN().toString();
		String ipAddress = null;
		String subjectDNS = null;
		SAMLNameIdentifier ni = new SAMLNameIdentifier(id, federation, "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
		SAMLNameIdentifier ni2 = new SAMLNameIdentifier(id, federation, "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
		SAMLSubject sub = new SAMLSubject(ni, null, null, null);
		SAMLSubject sub2 = new SAMLSubject(ni2, null, null, null);
		SAMLAuthenticationStatement auth = new SAMLAuthenticationStatement(sub, method, new Date(), ipAddress, subjectDNS, null);

		QName quid = new QName(SAMLConstants.UID_ATTRIBUTE_NAMESPACE, SAMLConstants.UID_ATTRIBUTE);
		List vals1 = new ArrayList();
		vals1.add(id);
		SAMLAttribute uidAtt = new SAMLAttribute(quid.getLocalPart(), quid.getNamespaceURI(), quid, 0, vals1);

		QName qfirst = new QName(SAMLConstants.FIRST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.FIRST_NAME_ATTRIBUTE);
		List vals2 = new ArrayList();
		vals2.add(firstName);
		SAMLAttribute firstNameAtt = new SAMLAttribute(qfirst.getLocalPart(), qfirst.getNamespaceURI(), qfirst, 0, vals2);

		QName qLast = new QName(SAMLConstants.LAST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.LAST_NAME_ATTRIBUTE);
		List vals3 = new ArrayList();
		vals3.add(lastName);
		SAMLAttribute lastNameAtt = new SAMLAttribute(qLast.getLocalPart(), qLast.getNamespaceURI(), qLast, 0, vals3);

		QName qemail = new QName(SAMLConstants.EMAIL_ATTRIBUTE_NAMESPACE, SAMLConstants.EMAIL_ATTRIBUTE);
		List vals4 = new ArrayList();
		vals4.add(email);
		SAMLAttribute emailAtt = new SAMLAttribute(qemail.getLocalPart(), qemail.getNamespaceURI(), qemail, 0, vals4);

		List atts = new ArrayList();
		atts.add(uidAtt);
		atts.add(firstNameAtt);
		atts.add(lastNameAtt);
		atts.add(emailAtt);
		SAMLAttributeStatement attState = new SAMLAttributeStatement(sub2, atts);

		List l = new ArrayList();
		l.add(auth);
		l.add(attState);

		SAMLAssertion saml = new SAMLAssertion(issuer, start, end, null, null, l);
		List a = new ArrayList();
		a.add(cert);
		saml.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, key, a);

		return saml;
	} catch (Exception e) {
		DorianInternalException fault = FaultHelper.createFaultException(DorianInternalException.class, "Error creating SAML Assertion.");
		throw fault;

	}
}
 
开发者ID:NCIP,项目名称:cagrid2,代码行数:65,代码来源:TestDorian.java

示例6: getTrustedIdp

import gov.nih.nci.cagrid.opensaml.SAMLAssertion; //导入方法依赖的package包/类
private IdPContainer getTrustedIdp(String name, boolean nonStandartCert) throws Exception {
	TrustedIdP idp = new TrustedIdP();
	idp.setName(name);
	idp.setDisplayName(name);
	idp.setStatus(TrustedIdPStatus.ACTIVE);
	idp.setUserPolicyClass(AutoApprovalPolicy.class.getName());
	SAMLAuthenticationMethod[] methods = getAuthenticationMethods();
	for (SAMLAuthenticationMethod m : methods) {
		idp.getAuthenticationMethod().add(m);
	}
	idp.setAuthenticationServiceURL("https://localhost");
	idp.setAuthenticationServiceIdentity("/O=caGrid/OU=Testing/CN=Admin");
	SAMLAttributeDescriptor uid = new SAMLAttributeDescriptor();
	uid.setNamespaceURI(SAMLConstants.UID_ATTRIBUTE_NAMESPACE);
	uid.setName(SAMLConstants.UID_ATTRIBUTE);
	idp.setUserIdAttributeDescriptor(uid);

	SAMLAttributeDescriptor firstName = new SAMLAttributeDescriptor();
	firstName.setNamespaceURI(SAMLConstants.FIRST_NAME_ATTRIBUTE_NAMESPACE);
	firstName.setName(SAMLConstants.FIRST_NAME_ATTRIBUTE);
	idp.setFirstNameAttributeDescriptor(firstName);

	SAMLAttributeDescriptor lastName = new SAMLAttributeDescriptor();
	lastName.setNamespaceURI(SAMLConstants.LAST_NAME_ATTRIBUTE_NAMESPACE);
	lastName.setName(SAMLConstants.LAST_NAME_ATTRIBUTE);
	idp.setLastNameAttributeDescriptor(lastName);

	SAMLAttributeDescriptor email = new SAMLAttributeDescriptor();
	email.setNamespaceURI(SAMLConstants.EMAIL_ATTRIBUTE_NAMESPACE);
	email.setName(SAMLConstants.EMAIL_ATTRIBUTE);
	idp.setEmailAttributeDescriptor(email);
	String id = null;
	String subject = null;
	if (nonStandartCert) {
		id = "Non Standard" + name;
	} else {
		id = name;
	}

	subject = Utils.CA_SUBJECT_PREFIX + ",CN=" + id;
	Credential cred = ca.createIdentityCertificate(id);
	X509Certificate cert = cred.getCertificate();
	assertNotNull(cert);
	assertEquals(cert.getSubjectDN().getName(), subject);
	idp.setIdPCertificate(CertUtil.writeCertificate(cert));

	GregorianCalendar cal2 = new GregorianCalendar();
	Date start2 = cal2.getTime();
	cal2.add(Calendar.MINUTE, 2);
	Date end2 = cal2.getTime();
	String issuer = cert.getSubjectDN().toString();
	String federation = cert.getSubjectDN().toString();
	String ipAddress = null;
	String subjectDNS = null;
	SAMLNameIdentifier ni = new SAMLNameIdentifier(name, federation, "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
	SAMLSubject sub = new SAMLSubject(ni, null, null, null);
	SAMLAuthenticationStatement auth = new SAMLAuthenticationStatement(sub, "urn:oasis:names:tc:SAML:1.0:am:password", new Date(), ipAddress, subjectDNS, null);

	List l = new ArrayList();
	l.add(auth);
	SAMLAssertion saml = new SAMLAssertion(issuer, start2, end2, null, null, l);
	List a = new ArrayList();
	a.add(cert);
	saml.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, cred.getPrivateKey(), a);
	return new IdPContainer(idp, cert, saml);
}
 
开发者ID:NCIP,项目名称:cagrid2,代码行数:67,代码来源:TestTrustedIdPManager.java

示例7: getSAMLAssertion

import gov.nih.nci.cagrid.opensaml.SAMLAssertion; //导入方法依赖的package包/类
private SAMLAssertion getSAMLAssertion(String id, IdPContainer idp, Date start, Date end, String method) throws Exception {
	try {
		org.apache.xml.security.Init.init();
		String certStr = CertUtil.writeCertificate(idp.getCert());
		X509Certificate cert = CertUtil.loadCertificate(certStr);
		String keyStr = KeyUtil.writePrivateKey(idp.getKey(), "test");
		PrivateKey key = KeyUtil.loadPrivateKey(new ByteArrayInputStream(keyStr.getBytes()), "test");
		String firstName = "first" + id;
		String lastName = "first" + id;
		String email = id + "@test.com";

		String issuer = cert.getSubjectDN().toString();
		String federation = cert.getSubjectDN().toString();
		String ipAddress = null;
		String subjectDNS = null;
		SAMLNameIdentifier ni = new SAMLNameIdentifier(id, federation, "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
		SAMLNameIdentifier ni2 = new SAMLNameIdentifier(id, federation, "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified");
		SAMLSubject sub = new SAMLSubject(ni, null, null, null);
		SAMLSubject sub2 = new SAMLSubject(ni2, null, null, null);
		SAMLAuthenticationStatement auth = new SAMLAuthenticationStatement(sub, method, new Date(), ipAddress, subjectDNS, null);

		QName quid = new QName(SAMLConstants.UID_ATTRIBUTE_NAMESPACE, SAMLConstants.UID_ATTRIBUTE);
		List vals1 = new ArrayList();
		vals1.add(id);
		SAMLAttribute uidAtt = new SAMLAttribute(quid.getLocalPart(), quid.getNamespaceURI(), quid, 0, vals1);

		QName qfirst = new QName(SAMLConstants.FIRST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.FIRST_NAME_ATTRIBUTE);
		List vals2 = new ArrayList();
		vals2.add(firstName);
		SAMLAttribute firstNameAtt = new SAMLAttribute(qfirst.getLocalPart(), qfirst.getNamespaceURI(), qfirst, 0, vals2);

		QName qLast = new QName(SAMLConstants.LAST_NAME_ATTRIBUTE_NAMESPACE, SAMLConstants.LAST_NAME_ATTRIBUTE);
		List vals3 = new ArrayList();
		vals3.add(lastName);
		SAMLAttribute lastNameAtt = new SAMLAttribute(qLast.getLocalPart(), qLast.getNamespaceURI(), qLast, 0, vals3);

		QName qemail = new QName(SAMLConstants.EMAIL_ATTRIBUTE_NAMESPACE, SAMLConstants.EMAIL_ATTRIBUTE);
		List vals4 = new ArrayList();
		vals4.add(email);
		SAMLAttribute emailAtt = new SAMLAttribute(qemail.getLocalPart(), qemail.getNamespaceURI(), qemail, 0, vals4);

		List atts = new ArrayList();
		atts.add(uidAtt);
		atts.add(firstNameAtt);
		atts.add(lastNameAtt);
		atts.add(emailAtt);
		SAMLAttributeStatement attState = new SAMLAttributeStatement(sub2, atts);

		List l = new ArrayList();
		l.add(auth);
		l.add(attState);

		SAMLAssertion saml = new SAMLAssertion(issuer, start, end, null, null, l);
		List a = new ArrayList();
		a.add(cert);
		saml.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, key, a);

		return saml;
	} catch (Exception e) {
		e.printStackTrace();
		DorianInternalException fault = new DorianInternalException(null, "Error creating SAML Assertion.");
		throw fault;

	}
}
 
开发者ID:NCIP,项目名称:cagrid2,代码行数:66,代码来源:TestIdentityFederationManager.java


注:本文中的gov.nih.nci.cagrid.opensaml.SAMLAssertion.sign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。