All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xlcloud.console.context.IdentityContext Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2012 AMG.lab, a Bull Group Company
 * 
 * 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.xlcloud.console.context;

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.xlcloud.logging.LoggingUtils;
import org.xlcloud.rest.client.OAuth2BearerToken;

import com.iplanet.sso.SSOToken;

/**
 * Identity context with logged-in user data. Contains also SAML-specific info
 * 
 * @author Jakub Wachowski, AMG.net
 *
 */
@SessionScoped
public class IdentityContext implements Serializable {

    private static final long serialVersionUID = -5957957391560920496L;

    //TODO: change to userName?
    private String name;
    private Long userId;
    private Long accountId;
    private SSOToken ssoToken;

    @Produces @OAuth2BearerToken
    private String accessToken;
    
    //TODO move to some other context?
    private String idpSessionId;
    private String nameIdFormat;
    
    
    public IdentityContext() {
        
    }
    
    /**
     * Constructor for IdentityContext
     * @param name username
     * @param userId user id
     * @param accountId account id
     */
    public IdentityContext(String name, Long userId, Long accountId) {
        this.name = name;
        this.userId = userId;
        this.accountId = accountId;
    }

    /**
     * @return username
     */
    public String getName() {
        return name;
    }

    /**
     * @return user id
     */
    public Long getUserId() {
        return userId;
    }

    /**
     * @return account id
     */
    public Long getAccountId() {
        return accountId;
    }
    
    /**
     * @return the idp's session id
     */
    public String getIdpSessionId() {
        return idpSessionId;
    }

    /**
     * @return format of the NameID - used to create a proper LogoutRequest
     */
    public String getNameIdFormat() {
        return nameIdFormat;
    }
    
    /**
     * @return the ssoToken
     */
    public SSOToken getSsoToken() {
        return ssoToken;
    }
    
    /**
     * @return the accessToken
     */
    public String getAccessToken() {
        return accessToken;
    }
    
    /**
     * @param ssoToken the ssoToken to set
     */
    public void setSsoToken(SSOToken ssoToken) {
        this.ssoToken = ssoToken;
    }
    
    
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    
    /**
     * @param userId the userId to set
     */
    public void setUserId(Long userId) {
        this.userId = userId;
    }

    
    /**
     * @param accountId the accountId to set
     */
    public void setAccountId(Long accountId) {
        this.accountId = accountId;
    }

    
    /**
     * @param idpSessionId the idpSessionId to set
     */
    public void setIdpSessionId(String idpSessionId) {
        this.idpSessionId = idpSessionId;
    }

    
    /**
     * @param nameIdFormat the nameIdFormat to set
     */
    public void setNameIdFormat(String nameIdFormat) {
        this.nameIdFormat = nameIdFormat;
    }

    /**
     * @param accessToken the accessToken to set
     */
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }
    
    /** {@inheritDoc} */
    @Override
    public String toString() {
        return new ToStringBuilder(this).append("userName", name).append("userId", userId)
                .append("accountId", accountId).append("accessToken", LoggingUtils.maskPartially(accessToken)).toString();
    }

    public boolean isGlobalUser() {
        return (getAccountId() == null);
    }

    public boolean isAccountUser() {
        return !isGlobalUser();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy