@Override public ResponseType execute(PasswordRequest passwordReq) throws ConnectorDataException { ResponseType responseType = new ResponseType(); responseType.setStatus(StatusCodeType.SUCCESS); ManagedSysEntity mSys = managedSysService.getManagedSysById(passwordReq.getTargetID()); String adminEmail = mSys.getUserId(); String password = this.getPassword(mSys.getId()); String domain = mSys.getHostUrl(); try { GoogleAgent agent = new GoogleAgent(); GenericEntry getUser = agent.getUser(adminEmail, password, domain, passwordReq.getObjectIdentity()); getUser.addProperty("password", passwordReq.getPassword()); agent.updateUser( adminEmail, password, domain, getUser.getAllProperties(), passwordReq.getObjectIdentity()); } catch (Exception e) { responseType.setStatus(StatusCodeType.FAILURE); throw new ConnectorDataException(ErrorCode.CONNECTOR_ERROR, e.getMessage()); } return responseType; }
@Override public ResponseType execute(PasswordRequest passwordRequest) throws ConnectorDataException { ResponseType respType = new ResponseType(); respType.setStatus(StatusCodeType.SUCCESS); /* * PSO - Provisioning Service Object - - ID must uniquely specify an * object on the target or in the target's namespace - Try to make the * PSO ID immutable so that there is consistency across changes. */ String userName = passwordRequest.getObjectIdentity(); /* targetID - */ String targetID = passwordRequest.getTargetID(); /* * A) Use the targetID to look up the connection information under * managed systems */ ConnectorConfiguration configuration = this.getConfiguration(targetID, ConnectorConfiguration.class); String host = configuration.getManagedSys().getHostUrl(); String hostlogin = configuration.getManagedSys().getUserId(); String hostpassword = getDecryptedPassword(configuration.getManagedSys().getPswd()); StringBuffer strBuf = new StringBuffer(); strBuf.append( "cmd /c powershell.exe -command \"& C:\\powershell\\ad\\SetPassword-UserActiveDir.ps1 "); strBuf.append("'" + host + "' "); strBuf.append("'" + hostlogin + "' "); strBuf.append("'" + hostpassword + "' "); strBuf.append("'" + userName + "' "); strBuf.append("'" + passwordRequest.getPassword() + "' \" "); log.debug("Command line string= " + strBuf.toString()); String[] cmdarray = {"cmd", strBuf.toString()}; try { // Runtime.getRuntime().exec(cmdarray); //exec(strBuf.toString()); Process p = Runtime.getRuntime().exec(strBuf.toString()); log.debug("Process =" + p); OutputStream stream = p.getOutputStream(); log.debug("stream=" + stream.toString()); return respType; } catch (Exception e) { log.error(e.getMessage(), e); throw new ConnectorDataException(ErrorCode.CONNECTOR_ERROR, e.getMessage()); } }
@Override public ResponseType execute(PasswordRequest passwordRequest) throws ConnectorDataException { final ResponseType response = new ResponseType(); response.setStatus(StatusCodeType.SUCCESS); AppTableConfiguration configuration = this.getConfiguration(passwordRequest.getTargetID()); if (StringUtils.isBlank(configuration.getPrincipalPassword())) { String message = "Password synchronization is furned off! Need to add attributes: 'INCLUDE_IN_PASSWORD_SYNC' = 'Y' and 'PRINCIPAL_PASSWORD' = NAME OF PASSWORD COLUMN"; log.warn(message); return response; } Connection con = this.getConnection(configuration.getManagedSys()); PreparedStatement statement = null; try { statement = createChangeUserControlParamsStatement( con, configuration, this.getTableName(configuration, this.getObjectType()), passwordRequest.getObjectIdentity(), passwordRequest.getPassword(), true); statement.executeUpdate(); return response; } catch (SQLException se) { log.error(se.getMessage(), se); throw new ConnectorDataException(ErrorCode.CONNECTOR_ERROR, se.getMessage()); } catch (Throwable e) { log.error(e.getMessage(), e); throw new ConnectorDataException(ErrorCode.CONNECTOR_ERROR, e.getMessage()); } finally { this.closeStatement(statement); this.closeConnection(con); } }
@Override public ResponseType execute(PasswordRequest passwordRequest) throws ConnectorDataException { ResponseType respType = new ResponseType(); respType.setStatus(StatusCodeType.SUCCESS); ConnectorConfiguration config = getConfiguration(passwordRequest.getTargetID(), ConnectorConfiguration.class); ManagedSysEntity managedSys = config.getManagedSys(); LdapContext ldapctx = this.connect(managedSys); try { ManagedSystemObjectMatch matchObj = getMatchObject(passwordRequest.getTargetID(), ManagedSystemObjectMatch.USER); String identity = passwordRequest.getObjectIdentity(); // Check identity on CN format or not String identityPatternStr = MessageFormat.format(DN_IDENTITY_MATCH_REGEXP, matchObj.getKeyField()); Pattern pattern = Pattern.compile(identityPatternStr); Matcher matcher = pattern.matcher(identity); String objectBaseDN; if (matcher.matches()) { identity = matcher.group(1); String CN = matchObj.getKeyField() + "=" + identity; objectBaseDN = passwordRequest.getObjectIdentity().substring(CN.length() + 1); } else { // if identity is not in DN format try to find OU info in attributes // MVL 20141211 String OU = getOU(passwordRequest.getExtensibleObject()); String OU = getAttrValue(passwordRequest.getExtensibleObject(), OU_ATTRIBUTE); if (StringUtils.isNotEmpty(OU)) { objectBaseDN = OU + "," + matchObj.getBaseDn(); } else { objectBaseDN = matchObj.getBaseDn(); } } NamingEnumeration results = null; try { log.debug("Looking for user with identity=" + identity + " in " + objectBaseDN); results = lookupSearch(managedSys, matchObj, ldapctx, identity, null, objectBaseDN); } catch (NameNotFoundException nnfe) { log.debug("results=NULL"); log.debug(" results has more elements=0"); respType.setStatus(StatusCodeType.FAILURE); return respType; } String identityDN = null; int count = 0; while (results != null && results.hasMoreElements()) { SearchResult sr = (SearchResult) results.next(); identityDN = sr.getNameInNamespace(); count++; } if (count == 0) { String err = String.format("User %s was not found in %s", identity, objectBaseDN); log.error(err); respType.setStatus(StatusCodeType.FAILURE); return respType; } else if (count > 1) { String err = String.format("More then one user %s was found in %s", identity, objectBaseDN); log.error(err); respType.setStatus(StatusCodeType.FAILURE); return respType; } if (StringUtils.isNotEmpty(identityDN)) { log.debug("New password will be reset for user " + identityDN); Directory dirSpecificImp = DirectorySpecificImplFactory.create(config.getManagedSys().getHandler5()); ModificationItem[] mods = dirSpecificImp.resetPassword(passwordRequest); ldapctx.modifyAttributes(identityDN, mods); log.debug("New password has been reset for user " + identityDN); } } catch (NamingException ne) { log.error(ne.getMessage(), ne); log.debug("Returning response object from reset password with Status of Failure..."); ConnectorDataException ex = null; if (ne instanceof OperationNotSupportedException) { ex = new ConnectorDataException( ErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION, ne.getMessage()); } else { ex = new ConnectorDataException(ErrorCode.DIRECTORY_ERROR, ne.getMessage()); } throw ex; } catch (Exception ne) { log.error(ne.getMessage(), ne); throw new ConnectorDataException(ErrorCode.OTHER_ERROR, ne.getMessage()); } finally { /* close the connection to the directory */ this.closeContext(ldapctx); } return respType; }