private void attemptSessionRefresh() throws ClientGeneralException { try { writeLock(); // write lock defence code LOGGER.debug("Attempt to refresh session for {}", hostAddress); if (isSessionValid()) { LOGGER.debug("Session is valid for {}. No need to refresh", hostAddress); return; } ComputeSessionCache cache = decryptAndRetrieveSessionCache(); if (cache == null || cache.getHashKey() == null || !cache.getHashKey().equals(oneWayHash)) { encryptAndUpdateSessionCache(new ComputeSessionCache()); return; } AaaRefresh aaaRefresh = new AaaRefresh(); aaaRefresh.setInName(username); aaaRefresh.setInPassword(password); aaaRefresh.setCookie(cache.getSessionId()); aaaRefresh.setInCookie(cache.getSessionId()); Object response = ucsmTransportWrapper.execute( serviceURI, objectFactory.createAaaRefresh(aaaRefresh), Object.class); Assert.notNull(response, "Authentication Call resulted in Null Response"); Assert.isTrue( response instanceof com.emc.cloud.platform.ucs.out.model.AaaRefresh, "Invalid Response Type!"); com.emc.cloud.platform.ucs.out.model.AaaRefresh refreshResponse = (com.emc.cloud.platform.ucs.out.model.AaaRefresh) response; if (refreshResponse != null && refreshResponse.getOutCookie() != null && !refreshResponse.getOutCookie().isEmpty()) { LOGGER.info("Session has been refreshed"); cache = new ComputeSessionCache( refreshResponse.getOutCookie(), System.currentTimeMillis(), parseNumber(refreshResponse.getOutRefreshPeriod()).longValue(), oneWayHash); encryptAndUpdateSessionCache(cache); } else { LOGGER.info("Session for {} cannot be refreshed", hostAddress); encryptAndUpdateSessionCache(new ComputeSessionCache()); } } finally { writeUnlock(); } }
@Test(groups = "onDemand") public void testMarshalling() throws ClientGeneralException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, JAXBException { String lsServerDN = "org-root/ls-vlad2-os-install"; String powerState = "up"; ConfigConfMo configConfMo = new ConfigConfMo(); configConfMo.setInHierarchical("true"); com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer(); lsServer.setDn(lsServerDN); LsPower lsPower = new LsPower(); lsPower.setRn("power"); lsPower.setState(powerState); lsServer.getContent().add(factory.createLsPower(lsPower)); ConfigConfig configConfig = new ConfigConfig(); configConfig.setManagedObject(factory.createLsServer(lsServer)); configConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig)); JAXBElement<ConfigConfMo> jaxbElement = factory.createConfigConfMo(configConfMo); StringWriter writer = new StringWriter(); if (jaxbElement != null) { Marshaller marshaller = ucsInContext.createMarshaller(); marshaller.marshal(jaxbElement, writer); } String payload = writer.toString(); System.out.println("Payload : " + payload); }
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(); } }