Example usage for javax.xml.bind JAXBElement getClass

List of usage examples for javax.xml.bind JAXBElement getClass

Introduction

In this page you can find the example usage for javax.xml.bind JAXBElement getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:cz.lbenda.dataman.rc.DbConfigFactory.java

public static void load(final String document) {
    if (StringUtils.isBlank(document)) {
        return;//from w w  w .ja v a 2s . co m
    }
    try {
        JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class);
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement o = (JAXBElement) u.unmarshal(new StringReader(document));
        if (o.getValue() instanceof DatamanType) {
            DatamanType dc = (DatamanType) o.getValue();
            if (dc.getSessions() == null || dc.getSessions().getSession().isEmpty()) {
                LOG.info("No configuration for loading");
            } else {
                configurations.clear();
                for (SessionType session : dc.getSessions().getSession()) {
                    DbConfig sc = new DbConfig();
                    configurations.add(sc);
                    sc.fromSessionType(session, true);
                }
            }
        } else {
            LOG.error("The string didn't contains dataman configuration: " + o.getClass().getName());
        }
    } catch (JAXBException e) {
        LOG.error("Problem with reading dataman configuration\nXML:" + document + "\n" + e.toString(), e);
    }
}

From source file:be.fedict.hsm.client.HSMProxyClient.java

/**
 * Gives back the X509 certificate chain for the given key alias.
 * //  w w w. j a  va 2  s  .c  o  m
 * @param alias
 * @return the X509 certificate chain as a list.
 * @throws CertificateException
 */
public List<X509Certificate> getCertificateChain(String alias) throws CertificateException {
    GetCertificateChainRequest getCertificateChainRequest = this.hsmObjectFactory
            .createGetCertificateChainRequest();
    getCertificateChainRequest.setProfile(DSSConstants.HSM_PROXY_DSS_PROFILE_URI);
    String requestId = "request-" + UUID.randomUUID().toString();
    getCertificateChainRequest.setRequestID(requestId);

    {
        AnyType optionalInputs = this.dssObjectFactory.createAnyType();
        getCertificateChainRequest.setOptionalInputs(optionalInputs);
        KeySelector keySelector = this.dssObjectFactory.createKeySelector();
        optionalInputs.getAny().add(keySelector);
        KeyInfoType keyInfo = this.dsObjectFactory.createKeyInfoType();
        keySelector.setKeyInfo(keyInfo);
        keyInfo.getContent().add(this.dsObjectFactory.createKeyName(alias));
    }

    ResponseBaseType response = this.dssPort.getCertificateChain(getCertificateChainRequest);
    // TODO: error handling
    List<Object> optionalOutputContentList = response.getOptionalOutputs().getAny();
    for (Object optionalOutputContent : optionalOutputContentList) {
        LOG.debug("optional output type: " + optionalOutputContent.getClass().getName());
        if (optionalOutputContent instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) optionalOutputContent;
            KeyInfoType keyInfo = (KeyInfoType) jaxbElement.getValue();
            List<Object> keyInfoContent = keyInfo.getContent();
            JAXBElement keyInfoObject = (JAXBElement) keyInfoContent.get(0);
            LOG.debug("key info object type: " + keyInfoObject.getClass().getName());
            X509DataType x509Data = (X509DataType) keyInfoObject.getValue();
            List<Object> x509DataContent = x509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName();
            List<X509Certificate> certificateChain = new LinkedList<X509Certificate>();
            for (Object x509DataObject : x509DataContent) {
                LOG.debug("x509 data object type: " + x509DataObject.getClass().getName());
                JAXBElement x509DataElement = (JAXBElement) x509DataObject;
                LOG.debug("type: " + x509DataElement.getValue().getClass().getName());
                byte[] encodedCertificate = (byte[]) x509DataElement.getValue();
                X509Certificate certificate = (X509Certificate) this.certificateFactory
                        .generateCertificate(new ByteArrayInputStream(encodedCertificate));
                certificateChain.add(certificate);
            }
            return certificateChain;
        }
    }
    return null;
}

From source file:cz.lbenda.dataman.db.ExtConfFactory.java

private void loadExConfType(Reader reader) {
    if (reader == null) {
        loadExConfType((ExConfType) null);
    } else {//from   w  w w. java  2s. com
        try {
            JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.exconf.ObjectFactory.class);
            Unmarshaller u = jc.createUnmarshaller();
            JAXBElement o = (JAXBElement) u.unmarshal(reader);
            if (o.getValue() instanceof ExConfType) {
                loadExConfType((ExConfType) o.getValue());
            } else {
                LOG.error("The file didn't contains expected configuration: " + o.getClass().getName());
            }
        } catch (JAXBException e) {
            LOG.error("Problem with reading extended configuration: " + e.toString(), e);
        }
    }
}

From source file:com.cisco.dvbu.ps.deploytool.services.TriggerManagerImpl.java

private void populateTriggerAttributes(TriggerResource triggerResource, TriggerType triggerType, long loopCount,
        TriggerScheduleListType scheduleList) {

    triggerType.setId("TR-" + loopCount);
    triggerType.setResourcePath(triggerResource.getPath());
    triggerType.setIsEnabled(triggerResource.isEnabled());
    triggerType.setAnnotation(triggerResource.getAnnotation());
    if (logger.isDebugEnabled()) {
        logger.debug("Processing trigger: " + triggerResource.getPath());
        logger.debug("Rest field is of type: " + triggerResource.getRest().getClass().getName());
        logger.debug("Looping through list:");
    }/* ww w. j  a v  a2  s . co  m*/

    long objLoopCount = 0;
    String conditionType = null;
    String actionType = null;
    AttributeList conditionAttributes = null;
    Schedule conditionSchedule = null;
    AttributeList actionAttributes = null;
    BigInteger maxEventsQueued = null;

    for (JAXBElement<?> triggerObj : triggerResource.getRest()) {
        objLoopCount++;

        if (logger.isDebugEnabled()) {
            logger.debug("Rest field[" + objLoopCount + "] is of type: " + triggerObj.getClass().getName());
            logger.debug("JAXB Name: " + triggerObj.getName());
            logger.debug("JAXB Declared Type: " + triggerObj.getDeclaredType());

        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("conditionType")) {
            logger.debug("Processing conditionType");
            conditionType = (String) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("conditionAttributes")) {
            logger.debug("Processing condition attributes");
            conditionAttributes = (AttributeList) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("conditionSchedule")) {
            logger.debug("Processing condition schedule");
            conditionSchedule = (Schedule) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("actionType")) {
            logger.debug("Processing actionType");
            actionType = (String) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("actionAttributes")) {
            logger.debug("Processing action attributes");
            actionAttributes = (AttributeList) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("maxEventsQueued")) {
            logger.debug("Processing max events queued");
            maxEventsQueued = (BigInteger) triggerObj.getValue();
        }
    }

    triggerType.setMaxEventsQueued(maxEventsQueued);
    if (logger.isDebugEnabled()) {
        logger.debug("Condition type: " + conditionType);
        logger.debug("Action type: " + actionType);
    }

    triggerType.setCondition(populateTriggerCondition(conditionType, conditionAttributes, conditionSchedule,
            "TR-" + loopCount, scheduleList));
    triggerType.setAction(populateTriggerAction(actionType, actionAttributes, "TR-" + loopCount));

    if (logger.isDebugEnabled()) {
        if (scheduleList.getSchedule().isEmpty()) {
            logger.debug("Schedule List is empty");
        } else {
            logger.debug("Schedule List size: " + scheduleList.getSchedule().size());
        }
    }
}

From source file:org.apache.openaz.xacml.admin.model.ExpressionContainer.java

private void initializeChildren(ApplyType apply, FunctionDefinition function) {
    int index = 1;
    for (JAXBElement<?> child : apply.getExpression()) {
        ///*from  w ww.  jav a 2 s . com*/
        // Validate the child
        //
        if (child.getValue() == null) {
            logger.warn("child element " + index + "has a null object.");
            index++;
            continue;
        }
        if (logger.isTraceEnabled()) {
            logger.trace("Child " + index + " is " + child.getValue());
        }
        //
        // Get the argument for this child
        //
        if (function == null) {
            throw new IllegalArgumentException("Apply has children but no function defined.");
        }
        FunctionArgument argument = XACMLFunctionValidator.getFunctionArgument(index, function);
        if (logger.isTraceEnabled()) {
            logger.trace("Child's argument is: " + argument);
        }
        if (argument == null) {
            //throw new Exception("Unable to find function argument: " + index + " " + function.getId() + " " + function.getShortname());
            return;
        }
        //
        // See if its another apply type
        //
        if (child.getValue() instanceof ApplyType) {
            //
            // Save it
            //
            this.applys.put((ApplyType) child.getValue(), new ApplyParent(apply, argument));
            //
            // Get its function information
            //
            Map<String, FunctionDefinition> functions = JPAUtils.getFunctionIDMap();
            FunctionDefinition childFunction = functions.get(((ApplyType) child.getValue()).getFunctionId());
            if (childFunction == null) {
                logger.warn("Apply object " + index + " does not have a function defined");
            } else {
                //
                // Bring in its children
                //
                this.initializeChildren((ApplyType) child.getValue(), childFunction);
            }
        } else if (child.getValue() instanceof AttributeValueType) {
            //
            // Save it
            //
            this.values.put((AttributeValueType) child.getValue(), new ApplyParent(apply, argument));
        } else if (child.getValue() instanceof AttributeDesignatorType) {
            //
            // Save it
            //
            this.designators.put((AttributeDesignatorType) child.getValue(), new ApplyParent(apply, argument));
        } else if (child.getValue() instanceof AttributeSelectorType) {
            //
            // Save it
            //
            this.selectors.put((AttributeSelectorType) child.getValue(), new ApplyParent(apply, argument));
        } else if (child.getValue() instanceof VariableReferenceType) {
            //
            // Save it
            //
            this.variables.put((VariableReferenceType) child.getValue(), new ApplyParent(apply, argument));
        } else if (child.getValue() instanceof FunctionType) {
            //
            // Save it
            //
            this.functions.put((FunctionType) child.getValue(), new ApplyParent(apply, argument));
        } else if (child.getValue() instanceof ExpressionType) {
            //
            // Save it
            //
            this.expressions.put((ExpressionType) child.getValue(), new ApplyParent(apply, argument));
        } else {
            logger.error("Unknown child type: " + child.getClass().getCanonicalName());
        }
        index++;
    }
}

From source file:org.atricore.idbus.capabilities.sso.main.sp.producers.AssertionConsumerProducer.java

private Subject buildSubjectFromResponse(ResponseType response) {

    Subject outSubject = new Subject();

    String issuerAlias = response.getIssuer().getValue();
    FederatedProvider issuer = getCotManager().lookupFederatedProviderByAlias(issuerAlias);

    if (response.getAssertionOrEncryptedAssertion().size() > 0) {

        AssertionType assertion = null;/*from w  ww  .  ja  v a2s  . c  o m*/

        if (response.getAssertionOrEncryptedAssertion().get(0) instanceof AssertionType) {
            assertion = (AssertionType) response.getAssertionOrEncryptedAssertion().get(0);
        } else {
            throw new RuntimeException("Response should be already decripted!");
        }

        // store subject identification information
        if (assertion.getSubject() != null) {

            List subjectContentItems = assertion.getSubject().getContent();

            for (Object o : subjectContentItems) {

                JAXBElement subjectContent = (JAXBElement) o;

                if (subjectContent.getValue() instanceof NameIDType) {

                    NameIDType nameId = (NameIDType) subjectContent.getValue();
                    // Create Subject ID Attribute
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding NameID to IDP Subject {" + nameId.getSPNameQualifier() + "}"
                                + nameId.getValue() + ":" + nameId.getFormat());
                    }
                    outSubject.getPrincipals().add(new SubjectNameID(nameId.getValue(), nameId.getFormat(),
                            nameId.getNameQualifier(), nameId.getSPNameQualifier()));

                } else if (subjectContent.getValue() instanceof BaseIDAbstractType) {
                    // TODO : Can we do something with this ?
                    throw new IllegalArgumentException("Unsupported Subject BaseID type "
                            + subjectContent.getValue().getClass().getName());

                } else if (subjectContent.getValue() instanceof EncryptedType) {
                    throw new IllegalArgumentException("Response should be already decripted!");

                } else if (subjectContent.getValue() instanceof SubjectConfirmationType) {
                    // TODO : Store subject confirmation data ?
                } else {
                    logger.error("Unknown subject content type : " + subjectContent.getClass().getName());
                }

            }

        }

        // store subject user attributes
        List<StatementAbstractType> stmts = assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement();
        if (logger.isDebugEnabled())
            logger.debug("Found " + stmts.size() + " statements");

        for (StatementAbstractType stmt : stmts) {

            if (logger.isDebugEnabled())
                logger.debug("Processing statement " + stmts);

            if (stmt instanceof AttributeStatementType) {

                AttributeStatementType attrStmt = (AttributeStatementType) stmt;

                List attrs = attrStmt.getAttributeOrEncryptedAttribute();

                if (logger.isDebugEnabled())
                    logger.debug("Found " + attrs.size() + " attributes in attribute statement");

                for (Object attrOrEncAttr : attrs) {

                    if (attrOrEncAttr instanceof AttributeType) {

                        AttributeType attr = (AttributeType) attrOrEncAttr;

                        List<Object> attributeValues = attr.getAttributeValue();

                        if (logger.isDebugEnabled())
                            logger.debug("Processing attribute " + attr.getName());

                        for (Object attributeValue : attributeValues) {

                            if (logger.isDebugEnabled())
                                logger.debug("Processing attribute value " + attributeValue);

                            if (attributeValue instanceof String) {

                                if (logger.isDebugEnabled()) {
                                    logger.debug("Adding String Attribute Statement to IDP Subject "
                                            + attr.getName() + ":" + attr.getNameFormat() + "="
                                            + attr.getAttributeValue());
                                }

                                outSubject.getPrincipals()
                                        .add(new SubjectAttribute(attr.getName(), (String) attributeValue)

                                );

                            } else if (attributeValue instanceof Integer) {

                                if (logger.isDebugEnabled()) {
                                    logger.debug("Adding Integer Attribute Value to IDP Subject "
                                            + attr.getName() + ":" + attr.getNameFormat() + "="
                                            + attr.getAttributeValue());
                                }

                                outSubject.getPrincipals()
                                        .add(new SubjectAttribute(attr.getName(), (Integer) attributeValue)

                                );

                            } else if (attributeValue instanceof Element) {
                                Element e = (Element) attributeValue;
                                if (logger.isDebugEnabled()) {
                                    logger.debug("Adding Attribute Statement to IDP Subject from DOM Element "
                                            + attr.getName() + ":" + attr.getNameFormat() + "="
                                            + e.getTextContent());
                                }

                                outSubject.getPrincipals()
                                        .add(new SubjectAttribute(attr.getName(), e.getTextContent())

                                );

                            } else if (attributeValue == null) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("Adding String Attribute Statement to IDP Subject "
                                            + attr.getName() + ":" + attr.getNameFormat() + "=" + "null");
                                }

                                outSubject.getPrincipals().add(new SubjectAttribute(attr.getName(), "")

                                );

                            } else {
                                logger.error(
                                        "Unknown Attribute Value type " + attributeValue.getClass().getName());
                            }

                        }
                    } else {
                        // TODO : Decrypt attribute using IDP's encryption key
                        logger.debug("Unknown attribute type " + attrOrEncAttr);
                    }
                }
            }

            // store subject authentication attributes
            if (stmt instanceof AuthnStatementType) {
                AuthnStatementType authnStmt = (AuthnStatementType) stmt;

                List<JAXBElement<?>> authnContextItems = authnStmt.getAuthnContext().getContent();

                for (JAXBElement<?> authnContext : authnContextItems) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding Authentiation Context to IDP Subject " + authnContext.getValue()
                                + ":" + SubjectAuthenticationAttribute.Name.AUTHENTICATION_CONTEXT);
                    }

                    outSubject.getPrincipals()
                            .add(new SubjectAuthenticationAttribute(
                                    SubjectAuthenticationAttribute.Name.AUTHENTICATION_CONTEXT,
                                    (String) authnContext.getValue()));

                }

                if (authnStmt.getAuthnInstant() != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding Authentiation Attribute to IDP Subject "
                                + authnStmt.getAuthnInstant().toString() + ":"
                                + SubjectAuthenticationAttribute.Name.AUTHENTICATION_INSTANT);
                    }
                    outSubject.getPrincipals()
                            .add(new SubjectAuthenticationAttribute(
                                    SubjectAuthenticationAttribute.Name.AUTHENTICATION_INSTANT,
                                    authnStmt.getAuthnInstant().toString()));
                }

                if (authnStmt.getSessionIndex() != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "Adding Authentiation Attribute to IDP Subject " + authnStmt.getSessionIndex()
                                        + ":" + SubjectAuthenticationAttribute.Name.SESSION_INDEX);
                    }
                    outSubject.getPrincipals().add(new SubjectAuthenticationAttribute(
                            SubjectAuthenticationAttribute.Name.SESSION_INDEX, authnStmt.getSessionIndex()));
                }

                if (authnStmt.getSessionNotOnOrAfter() != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding Authentiation Attribute to IDP Subject "
                                + authnStmt.getSessionNotOnOrAfter().toString() + ":"
                                + SubjectAuthenticationAttribute.Name.SESSION_NOT_ON_OR_AFTER);
                    }
                    outSubject.getPrincipals()
                            .add(new SubjectAuthenticationAttribute(
                                    SubjectAuthenticationAttribute.Name.SESSION_NOT_ON_OR_AFTER,
                                    authnStmt.getSessionNotOnOrAfter().toString()));
                }

                if (authnStmt.getSubjectLocality() != null
                        && authnStmt.getSubjectLocality().getAddress() != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding Authentiation Attribute to IDP Subject "
                                + authnStmt.getSubjectLocality().getAddress() + ":"
                                + SubjectAuthenticationAttribute.Name.SUBJECT_LOCALITY_ADDRESS);
                    }
                    outSubject.getPrincipals()
                            .add(new SubjectAuthenticationAttribute(
                                    SubjectAuthenticationAttribute.Name.SUBJECT_LOCALITY_ADDRESS,
                                    authnStmt.getSubjectLocality().getAddress()));
                }

                if (authnStmt.getSubjectLocality() != null
                        && authnStmt.getSubjectLocality().getDNSName() != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding Authentiation Attribute to IDP Subject "
                                + authnStmt.getSubjectLocality().getDNSName() + ":"
                                + SubjectAuthenticationAttribute.Name.SUBJECT_LOCALITY_DNSNAME);
                    }
                    outSubject.getPrincipals()
                            .add(new SubjectAuthenticationAttribute(
                                    SubjectAuthenticationAttribute.Name.SUBJECT_LOCALITY_DNSNAME,
                                    authnStmt.getSubjectLocality().getDNSName()));
                }
            }

            // Store subject authorization attributes
            if (stmt instanceof AuthzDecisionStatementType) {
                AuthzDecisionStatementType authzStmt = (AuthzDecisionStatementType) stmt;

                for (ActionType action : authzStmt.getAction()) {

                    if (action.getNamespace() != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug(
                                    "Adding Authz Decision Action NS to IDP Subject " + action.getNamespace()
                                            + ":" + SubjectAuthorizationAttribute.Name.ACTION_NAMESPACE);
                        }
                        outSubject.getPrincipals().add(new SubjectAuthorizationAttribute(
                                SubjectAuthorizationAttribute.Name.ACTION_NAMESPACE, action.getNamespace()));
                    }

                    if (action.getValue() != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug(
                                    "Adding Authz Decision Action Value to IDP Subject " + action.getValue()
                                            + ":" + SubjectAuthorizationAttribute.Name.ACTION_VALUE);
                        }
                        outSubject.getPrincipals().add(new SubjectAuthorizationAttribute(
                                SubjectAuthorizationAttribute.Name.ACTION_VALUE, action.getValue()));
                    }

                }

                if (authzStmt.getDecision() != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "Adding Authz Decision Action to IDP Subject " + authzStmt.getDecision().value()
                                        + ":" + SubjectAuthorizationAttribute.Name.DECISION);
                    }
                    outSubject.getPrincipals().add(new SubjectAuthorizationAttribute(
                            SubjectAuthorizationAttribute.Name.DECISION, authzStmt.getDecision().value()));
                }

                if (authzStmt.getResource() != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding Authz Decision Action to IDP Subject " + authzStmt.getResource()
                                + ":" + SubjectAuthorizationAttribute.Name.RESOURCE);
                    }
                    outSubject.getPrincipals().add(new SubjectAuthorizationAttribute(
                            SubjectAuthorizationAttribute.Name.RESOURCE, authzStmt.getResource()));
                }

                // TODO: store evidence

            }

        }

    } else {
        logger.warn("No Assertion present within Response [" + response.getID() + "]");
    }

    SubjectAttribute idpAliasAttr = new SubjectAttribute("urn:org:atricore:idbus:sso:sp:idpAlias", issuerAlias);
    SubjectAttribute idpNameAttr = new SubjectAttribute("urn:org:atricore:idbus:sso:sp:idpName",
            issuer.getName());

    outSubject.getPrincipals().add(idpNameAttr);
    outSubject.getPrincipals().add(idpAliasAttr);

    if (outSubject != null && logger.isDebugEnabled()) {
        logger.debug("IDP Subject:" + outSubject);
    }

    return outSubject;
}