net.prasenjit.auth.domain.Client.java Source code

Java tutorial

Introduction

Here is the source code for net.prasenjit.auth.domain.Client.java

Source

/*
 * Copyright (c) 2016 Prasenjit Purohit
 *
 *    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 net.prasenjit.auth.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.util.StringUtils;

import javax.persistence.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

/**
 * Created by PRASENJIT-NET on 4/4/2016.
 *
 * @author PRASEN
 * @version $Id: $Id
 */
@Data
@Entity
@Table(name = "CLIENTS")
@JsonIgnoreProperties({ "user" })
public class Client implements ClientDetails {
    @Id
    @Column(name = "CLIENT_ID", length = 100, nullable = false)
    private String clientId;
    @Column(name = "CLIENT_SECRET", length = 100, nullable = true)
    private String clientSecret;
    @Column(name = "NAME", length = 100, nullable = true)
    private String name;
    @ManyToOne
    @JoinColumn(name = "USERNAME")
    private User user;
    @Convert(converter = BooleanStringConverter.class)
    @Column(name = "SECRET_REQUIRED", nullable = false)
    private boolean secretRequired;
    @Column(name = "GRANT_TYPES", length = 100, nullable = false)
    private String grantTypes;
    @Column(name = "REDIRECT_URI", length = 2000, nullable = false)
    private String redirectUri;
    @Column(name = "SCOPES", nullable = false, length = 2000)
    private String scopes;
    @Column(name = "ACCESS_VALIDITY_SECOND", nullable = true)
    private Integer accessTokenValiditySeconds;
    @Column(name = "REFRESH_VALIDITY_SECOND", nullable = true)
    private Integer refreshTokenValiditySeconds;

    /**
     * {@inheritDoc}
     */
    @Override
    public Set<String> getResourceIds() {
        return null;
    }

    /** {@inheritDoc} */
    @Override
    public boolean isScoped() {
        return true;
    }

    /** {@inheritDoc} */
    @Override
    public Set<String> getScope() {
        return StringUtils.commaDelimitedListToSet(scopes);
    }

    public void setScope(Set<String> scope) {
        this.scopes = StringUtils.collectionToCommaDelimitedString(scope);
    }

    /** {@inheritDoc} */
    @Override
    public Set<String> getAuthorizedGrantTypes() {
        return StringUtils.commaDelimitedListToSet(grantTypes);
    }

    /**
     * <p>setAuthorizedGrantTypes.</p>
     *
     * @param authorizedGrantTypes a {@link java.util.Set} object.
     */
    public void setAuthorizedGrantTypes(Set<String> authorizedGrantTypes) {
        grantTypes = StringUtils.collectionToCommaDelimitedString(authorizedGrantTypes);
    }

    /** {@inheritDoc} */
    @Override
    public Set<String> getRegisteredRedirectUri() {
        return StringUtils.commaDelimitedListToSet(redirectUri);
    }

    /** {@inheritDoc} */
    @Override
    public Collection<GrantedAuthority> getAuthorities() {
        return Collections.emptyList();
    }

    /** {@inheritDoc} */
    @Override
    public boolean isAutoApprove(String s) {
        return false;
    }

    /** {@inheritDoc} */
    @Override
    public Map<String, Object> getAdditionalInformation() {
        return null;
    }
}