public abstract class AbstractCredentialHandler, V extends AbstractBaseCredentials, U>
implements CredentialHandler {
<<<<<<< HEAD
private static final String DEFAULT_ACCOUNT_LOGIN_PROPERTY_NAME = "loginName";
private String defaultAccountLoginNameProperty = DEFAULT_ACCOUNT_LOGIN_PROPERTY_NAME;
private List> defaultAccountTypes;
@Override
public void setup(S store) {
configureDefaultSupportedAccountTypes(store);
}
/**
* Custom {@link CredentialHandler} implementations may override this method to perform the lookup of {@link
* Account}
* instances based on the loginName.
*
* @param context
* @param loginName The login name of the account that will be used to retrieve the instance.
*
* @return
*/
protected Account getAccount(IdentityContext context, String loginName) {
IdentityManager identityManager = getIdentityManager(context);
for (Class extends Account> accountType : getDefaultAccountTypes()) {
IdentityQuery query = (IdentityQuery) identityManager.createIdentityQuery(accountType);
String defaultAccountLoginNameProperty = this.defaultAccountLoginNameProperty;
if (Agent.class.isAssignableFrom(accountType)) {
defaultAccountLoginNameProperty = DEFAULT_ACCOUNT_LOGIN_PROPERTY_NAME;
}
if (isDebugEnabled()) {
CREDENTIAL_LOGGER.credentialRetrievingAccount(loginName, accountType, defaultAccountLoginNameProperty);
}
query.setParameter(Account.QUERY_ATTRIBUTE.byName(defaultAccountLoginNameProperty), loginName);
List result = query.getResultList();
if (!result.isEmpty()) {
return result.get(0);
}
}
return null;
=======
private static final String DEFAULT_LOGIN_NAME_PROPERTY = "loginName";
/**
* This is the name of the identity type property that will be used to retrieve the account's
* login name, used for account lookup.
*/
public static final String LOGIN_NAME_PROPERTY = "LOGIN_NAME_PROPERTY";
public static final String SUPPORTED_ACCOUNT_TYPES_PROPERTY = "SUPPORTED_ACCOUNT_TYPES";
private String loginNameProperty = DEFAULT_LOGIN_NAME_PROPERTY;
private List> supportedAccountTypes = null;
public void setup(S store) {
Map options = store.getConfig().getCredentialHandlerProperties();
if (options != null) {
String loginNameProperty = (String) options.get(LOGIN_NAME_PROPERTY);
if (loginNameProperty != null) {
this.loginNameProperty = loginNameProperty;
}
@SuppressWarnings("unchecked")
Class extends Account>[] accountTypes = (Class extends Account>[]) options.get(
SUPPORTED_ACCOUNT_TYPES_PROPERTY);
if (accountTypes != null) {
supportedAccountTypes = new ArrayList>();
for (Class extends Account> accountType : accountTypes) {
supportedAccountTypes.add(accountType);
}
}
}
}
protected Account getAccount(final IdentityContext context, String loginName) {
IdentityManager identityManager = getIdentityManager(context);
if (isDebugEnabled()) {
CREDENTIAL_LOGGER.debugf("Trying to find account with [%s] property value of [%s].",
loginNameProperty, loginName);
}
List extends Account> accounts = null;
if (supportedAccountTypes != null) {
for (Class extends Account> accountType : supportedAccountTypes) {
accounts = identityManager.createIdentityQuery(accountType)
.setParameter(AttributedType.QUERY_ATTRIBUTE.byName(loginNameProperty),
loginName).getResultList();
if (!accounts.isEmpty()) {
break;
}
}
}
if (accounts == null || accounts.isEmpty()) {
accounts = identityManager.createIdentityQuery(User.class)
.setParameter(AttributedType.QUERY_ATTRIBUTE.byName(loginNameProperty),
loginName).getResultList();
}
if (accounts == null || accounts.isEmpty()) {
accounts = identityManager.createIdentityQuery(Agent.class)
.setParameter(AttributedType.QUERY_ATTRIBUTE.byName(loginNameProperty),
loginName).getResultList();
}
if (accounts.isEmpty()) {
return null;
} else if (accounts.size() == 1) {
IdentityType result = accounts.get(0);
if (!Account.class.isAssignableFrom(result.getClass())) {
throw new IdentityManagementException("Error - the IdentityType returned is not an Account: [" +
result.toString() + "]");
}
return (Account) result;
} else {
throw new IdentityManagementException("Error - multiple Account objects found with same login name");
}
>>>>>>> 452f5b08f055a35c8179aaed5a51315605a516a6
}
@Override |