/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
 * contributors by the @authors tag. See the copyright.txt in the
 * distribution for a full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.as.quickstarts.picketlink.authorization.idm.jpa.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.picketlink.idm.jpa.annotations.CredentialType;
import org.picketlink.idm.jpa.annotations.CredentialValue;
import org.picketlink.idm.jpa.annotations.EffectiveDate;
import org.picketlink.idm.jpa.annotations.ExpiryDate;
import org.picketlink.idm.jpa.annotations.IdentityCredential;
import org.picketlink.idm.jpa.annotations.Parent;

/**
 * <p>JPA {@link Entity} used to store credential values</p>
 * 
 * @author <a href="mailto:psilva@redhat.com">Pedro Silva</a>
 *
 */
@IdentityCredential
@Entity
public class CredentialObject implements Serializable {

    private static final long serialVersionUID = -5133066075760567565L;

    @Id
    @GeneratedValue
    private Long id;

    @CredentialType
    private String type;

    @CredentialValue
    private String credential;

    @EffectiveDate
    @Temporal (TemporalType.TIMESTAMP)
    private Date effectiveDate;

    @ExpiryDate
    @Temporal (TemporalType.TIMESTAMP)
    private Date expiryDate;

    @Parent
    @ManyToOne
    private IdentityObject identityType;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getCredential() {
        return credential;
    }

    public void setCredential(String credential) {
        this.credential = credential;
    }

    public Date getEffectiveDate() {
        return effectiveDate;
    }

    public void setEffectiveDate(Date effectiveDate) {
        this.effectiveDate = effectiveDate;
    }

    public Date getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(Date expiryDate) {
        this.expiryDate = expiryDate;
    }

    public IdentityObject getIdentityType() {
        return identityType;
    }

    public void setIdentityType(IdentityObject identityType) {
        this.identityType = identityType;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (!getClass().isInstance(obj)) {
            return false;
        }

        CredentialObject other = (CredentialObject) obj;

        return getId() != null && other.getId() != null && getId().equals(other.getId());
    }

    @Override
    public int hashCode() {
        int result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getId() != null ? getId().hashCode() : 0);
        return result;
    }
}
@@ -1530,15 +1530,36 @@
 tial
- values
+, for a user or other agent.
 %3C/p%3E
@@ -1798,152 +1798,432 @@
     
-@Id%0A    @GeneratedValue%0A    private Long id;%0A%0A    @CredentialType%0A    private String type;%0A%0A    @CredentialValue%0A    private String credential;%0A
+/**%0A     * The synthetic id of the credential, generated by the database%0A     */%0A    @Id%0A    @GeneratedValue%0A    private Long id;%0A%0A    %0A    /**%0A     * The type of the credential, e.g. password, certificate%0A     */%0A    @CredentialType%0A    private String type;%0A%0A    /**%0A     * The value of the credential%0A     */%0A    @CredentialValue%0A    private String credential;%0A%0A    /**%0A     * The date the credential is valid from%0A     */
 %0A   
@@ -2306,24 +2306,79 @@
 ctiveDate;%0A%0A
+    /**%0A     * The date the credential expires%0A     */%0A
     @ExpiryD
@@ -2446,24 +2446,87 @@
 xpiryDate;%0A%0A
+    /**%0A     * The identity which owns this credential%0A     */%0A
     @Parent%0A

Improve javadoc