package org.apereo.cas.services;

import com.google.common.base.Throwables;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apereo.cas.support.oauth.services.OAuthRegisteredService;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

/**
 * This is {@link OidcRegisteredService}.
 *
 * @author Misagh Moayyed
 * @since 5.0.0
 */
@Entity
@DiscriminatorValue("oidc")
public class OidcRegisteredService extends OAuthRegisteredService {

    private static final long serialVersionUID = 1310899699465091444L;

    @Column(length = 255, updatable = true, insertable = true)
    private String jwks;

    @Column(updatable = true, insertable = true)
    private boolean signIdToken = true;

    public OidcRegisteredService() {
        setJsonFormat(Boolean.TRUE);
    }

    public boolean isSignIdToken() {
        return signIdToken;
    }

    public void setSignIdToken(final boolean signIdToken) {
        this.signIdToken = signIdToken;
    }

    public String getJwks() {
        return jwks;
    }

    public void setJwks(final String jwks) {
        this.jwks = jwks;
    }

    @Override
    protected AbstractRegisteredService newInstance() {
        return new OidcRegisteredService();
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }
        final OidcRegisteredService rhs = (OidcRegisteredService) obj;
        final EqualsBuilder builder = new EqualsBuilder();
        return builder
                .appendSuper(super.equals(obj))
                .append(this.jwks, rhs.jwks)
                .append(this.signIdToken, rhs.signIdToken)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder()
                .appendSuper(super.hashCode())
                .append(jwks)
                .append(signIdToken)
                .toHashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .appendSuper(super.toString())
                .append("jwks", jwks)
                .append("signIdToken", signIdToken)
                .toString();
    }

    @Override
    public void copyFrom(final RegisteredService source) {
        super.copyFrom(source);
        try {
            final OidcRegisteredService oidcService = (OidcRegisteredService) source;
            setJwks(oidcService.getJwks());
            setSignIdToken(oidcService.isSignIdToken());
        } catch (final Exception e) {
            throw Throwables.propagate(e);
        }
    }
}

@@ -871,16 +871,96 @@
  true;%0A%0A
+    @Column(updatable = true, insertable = true)%0A    private boolean implicit;%0A%0A
     publ
@@ -984,24 +984,24 @@
 Service() %7B%0A
-
         setJ
@@ -1339,32 +1339,193 @@
  = jwks;%0A    %7D%0A%0A
+    public boolean isImplicit() %7B%0A        return implicit;%0A    %7D%0A%0A    public void setImplicit(final boolean implicit) %7B%0A        this.implicit = implicit;%0A    %7D%0A%0A
     @Override%0A  
@@ -2136,24 +2136,77 @@
 , rhs.jwks)%0A
+                .append(this.implicit, rhs.implicit)%0A
             
@@ -2473,32 +2473,66 @@
 nd(signIdToken)%0A
+                .append(implicit)%0A
                 
@@ -2720,24 +2720,70 @@
 wks%22, jwks)%0A
+                .append(%22implicit%22, implicit)%0A
             
@@ -3063,16 +3063,16 @@
 source;%0A
-
         
@@ -3103,24 +3103,75 @@
 getJwks());%0A
+            setImplicit(oidcService.isImplicit());%0A
             

Add implicit support to oidc svc