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

com.hp.autonomy.hod.sso.SpringSecurityTokenProxyService Maven / Gradle / Ivy

There is a newer version: 0.9.2
Show newest version
/*
 * Copyright 2015 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.hod.sso;

import com.hp.autonomy.hod.client.api.authentication.EntityType;
import com.hp.autonomy.hod.client.api.authentication.TokenType;
import com.hp.autonomy.hod.client.token.TokenProxy;
import com.hp.autonomy.hod.client.token.TokenProxyService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * {@link TokenProxyService} which retrieves the token proxy from the Spring Security Context if the stored
 * authentication is a {@link HodAuthentication}.
 */
public class SpringSecurityTokenProxyService implements TokenProxyService {
    @Override
    public TokenProxy getTokenProxy() {
        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (!(authentication instanceof HodAuthentication)) {
            return null;
        }

        // Usage of this class requires that the application is using HodAuthentications
        //noinspection unchecked
        return ((HodAuthentication) authentication).getTokenProxy();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy