/** * build user based on the content given. * * @param loginsLine * @param lastLoginLine * @return the build user. */ private SolarisEntry buildUser(String username, String loginsLine, String lastLoginLine) { if (lastLoginLine == null) { return LoginsCommand.getEntry(loginsLine, username); } else { SolarisEntry.Builder entryBuilder = new SolarisEntry.Builder(username).addAttr(NativeAttribute.NAME, username); // logins SolarisEntry entry = LoginsCommand.getEntry(loginsLine, username); entryBuilder.addAllAttributesFrom(entry); // last Attribute attribute = LastCommand.parseOutput(username, lastLoginLine); entryBuilder.addAttr(NativeAttribute.LAST_LOGIN, attribute.getValue()); return entryBuilder.build(); } }
@Override public SolarisEntry buildAccountEntry(String username, Set<NativeAttribute> attrsToGet) { /** * bunch of boolean flags says if the command is needed to be launched (based on attributes to * get) */ boolean isLogins = LoginsCommand.isLoginsRequired(attrsToGet); boolean isProfiles = attrsToGet.contains(NativeAttribute.PROFILES); boolean isAuths = attrsToGet.contains(NativeAttribute.AUTHS); boolean isLast = attrsToGet.contains(NativeAttribute.LAST_LOGIN); boolean isRoles = attrsToGet.contains(NativeAttribute.ROLES); // if (conn.isNis()) { // return buildNISUser(username); // } SolarisEntry.Builder entryBuilder = new SolarisEntry.Builder(username).addAttr(NativeAttribute.NAME, username); // we need to execute Logins command always, to figure out if the user // exists at all. SolarisEntry loginsEntry = LoginsCommand.getAttributesFor(username, conn); // Null indicates that the user was not found. if (loginsEntry == null) { return null; } if (isLogins) { entryBuilder.addAllAttributesFrom(loginsEntry); } if (isProfiles) { final Attribute profiles = ProfilesCommand.getProfilesAttributeFor(username, conn); entryBuilder.addAttr(NativeAttribute.PROFILES, profiles.getValue()); } if (isAuths) { final Attribute auths = AuthsCommand.getAuthsAttributeFor(username, conn); entryBuilder.addAttr(NativeAttribute.AUTHS, auths.getValue()); } if (isLast) { final Attribute last = LastCommand.getLastAttributeFor(username, conn); entryBuilder.addAttr(NativeAttribute.LAST_LOGIN, last.getValue()); } if (isRoles) { final Attribute roles = RolesCommand.getRolesAttributeFor(username, conn); entryBuilder.addAttr(NativeAttribute.ROLES, roles.getValue()); } return entryBuilder.build(); }