Search in sources :

Example 1 with AaaLogin

use of com.emc.cloud.platform.ucs.in.model.AaaLogin in project coprhd-controller by CoprHD.

the class UCSMSession method relogin.

private void relogin() throws ClientGeneralException {
    try {
        writeLock();
        LOGGER.info("Attempt to login {}", hostAddress);
        // recheck login status
        if (isSessionValid()) {
            LOGGER.debug("After rechecking. Re-login session not required for {}", hostAddress);
            return;
        }
        ComputeSessionCache cache = null;
        AaaLogin aaaLogin = new AaaLogin();
        aaaLogin.setInName(username);
        aaaLogin.setInPassword(password);
        Object response = ucsmTransportWrapper.execute(serviceURI, objectFactory.createAaaLogin(aaaLogin), Object.class);
        Assert.notNull(response, "Authentication Call resulted in Null Response");
        Assert.isTrue(response instanceof com.emc.cloud.platform.ucs.out.model.AaaLogin, "Invalid Response Type!");
        com.emc.cloud.platform.ucs.out.model.AaaLogin loginResponse = (com.emc.cloud.platform.ucs.out.model.AaaLogin) response;
        if (loginResponse != null && loginResponse.getOutCookie() != null && !loginResponse.getOutCookie().isEmpty()) {
            cache = new ComputeSessionCache(loginResponse.getOutCookie(), System.currentTimeMillis(), parseNumber(loginResponse.getOutRefreshPeriod()).longValue(), oneWayHash);
            encryptAndUpdateSessionCache(cache);
        } else {
            throw new ClientGeneralException(ClientMessageKeys.UNAUTHORIZED, new String[] { serviceURI, "", "Unable to authenticate username/credentials pair" });
        }
    } finally {
        writeUnlock();
    }
}
Also used : AaaLogin(com.emc.cloud.platform.ucs.in.model.AaaLogin) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 2 with AaaLogin

use of com.emc.cloud.platform.ucs.in.model.AaaLogin in project coprhd-controller by CoprHD.

the class ClientHttpMethodsImpl method endpointLogin.

private Authentication endpointLogin(String serviceURI, String username, String password) throws ClientGeneralException {
    Authentication authentication = null;
    ClientHttpRequest httpRequest = requestFactory.create();
    AaaLogin aaaLogin = new AaaLogin();
    aaaLogin.setInName(username);
    aaaLogin.setInPassword(password);
    com.emc.cloud.platform.ucs.out.model.AaaLogin response = httpRequest.httpPostXMLObject(getServiceURI(), objectFactory.createAaaLogin(aaaLogin), com.emc.cloud.platform.ucs.out.model.AaaLogin.class);
    if (response != null && response.getOutCookie() != null && !response.getOutCookie().isEmpty()) {
        authentication = new UsernamePasswordAuthenticationToken(username, password, Collections.EMPTY_LIST);
        ((UsernamePasswordAuthenticationToken) authentication).setDetails(response);
        SecurityContextHolder.getContext().setAuthentication(authentication);
    } else {
        throw new ClientGeneralException(ClientMessageKeys.UNAUTHORIZED, new String[] { getServiceURI(), "", "Unable to authenticate username/credentials pair" });
    }
    return authentication;
}
Also used : Authentication(org.springframework.security.core.Authentication) AaaLogin(com.emc.cloud.platform.ucs.in.model.AaaLogin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

AaaLogin (com.emc.cloud.platform.ucs.in.model.AaaLogin)2 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1