public final int compareTo(Identity identity) { return getPrincipalName().compareTo(identity.getPrincipalName()); }
@Override public final boolean equals(Object obj) { if (!(obj instanceof Identity)) { return false; } Identity identity = (Identity) obj; return getGuid().equals(identity.getGuid()); }
protected String replaceTokens(String str, Principal identity) { str = str.replace("${guid}", escapeString(identity.getGuid())); str = str.replace("${principalName}", escapeString(identity.getPrincipalName())); if (identity instanceof Identity) { Identity id = (Identity) identity; Map<String, String[]> attributes = id.getAttributes(); if (attributes != null) { for (Map.Entry<String, String[]> en : attributes.entrySet()) { str = replaceToken(str, "${" + en.getKey() + "}", escapeString(StringUtil.getValue(en.getValue()))); } } } return replaceTokens(str); }
/** * Checks that the supplied credentials are valid for authentication * * @param identity * @param password * @return <tt>true</tt> if the credentials are valid * @throws ConnectorException */ protected boolean areCredentialsValid(Identity identity, char[] password) throws ConnectorException { try { final Object obj = ((Invocable) engine).invokeFunction("areCredentialsValid", identity, new String(password)); if(obj instanceof PasswordChangeRequiredException) { throw (PasswordChangeRequiredException)obj; } Boolean ok = (Boolean) obj; if (ok && identity.getPasswordStatus().getType().equals(PasswordStatusType.changeRequired)) { throw new PasswordChangeRequiredException(); } return ok; } catch (ScriptException e) { processScriptExecption(e); throw new ConnectorException("Failed script execution.", e); } catch (NoSuchMethodException e) { return super.areCredentialsValid(identity, password); } }
/** * Very inefficient default implementation. It is highly recommended * sub-classes override this. * * @param name * @return identity * @see {@link Connector#getIdentityByName(String)} * @throws PrincipalNotFoundException * @throws {@link ConnectorException} */ public Identity getIdentityByName(String name) throws PrincipalNotFoundException, ConnectorException { for (Iterator<Identity> identityIterator = allIdentities(); identityIterator.hasNext();) { Identity identity = identityIterator.next(); if (identity.getPrincipalName().equals(name)) { return identity; } } throw new PrincipalNotFoundException(name + " not found."); }
private void assertValidCredentials(Identity identity, char[] password) throws ConnectorException, InvalidLoginCredentialsException { if (!areCredentialsValid(identity, password)) { throw new InvalidLoginCredentialsException("Invalid username or password: '" + identity.getPrincipalName() + "'"); } }
@Override public Identity createIdentity(Identity identity, char[] password) throws ConnectorException { String encodedPassword = new String(encoderManager.encode(password, configuration.getIdentityPasswordEncoding(), configuration.getCharset(), null, null)); Statement statement = null; ResultSet resultSet = null; try { statement = connect.createStatement(); String sql = configuration.getCreateSQL(identity, encodedPassword, new String(password)); statement.executeUpdate(sql); } catch (SQLException e) { throw new ConnectorException(e); } finally { closeStatement(statement); closeResultSet(resultSet); } return getIdentityByName(identity.getPrincipalName()); }
return resultSet.next(); } else { sql = configuration.getSelectIdentitySQL(identity.getPrincipalName()); resultSet = statement.executeQuery(sql); if (resultSet.next()) {