Projects >> picketlink >>38f5b54a487167066ec1d557f051d5de089add1b

Chunk
Conflicting content
 */
package org.picketlink.idm.credential.handler;

<<<<<<< HEAD
import org.picketlink.common.reflection.Reflections;
=======
import static org.picketlink.idm.IDMLog.CREDENTIAL_LOGGER;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

>>>>>>> 452f5b08f055a35c8179aaed5a51315605a516a6
import org.picketlink.idm.IdentityManagementException;
import org.picketlink.idm.IdentityManager;
import org.picketlink.idm.credential.AbstractBaseCredentials;
Solution content
 */
package org.picketlink.idm.credential.handler;

import org.picketlink.idm.IdentityManagementException;
import org.picketlink.idm.IdentityManager;
import org.picketlink.idm.credential.AbstractBaseCredentials;
File
AbstractCredentialHandler.java
Developer's decision
None
Kind of conflict
Import
Chunk
Conflicting content
import org.picketlink.idm.model.IdentityType;
import org.picketlink.idm.model.basic.Agent;
import org.picketlink.idm.model.basic.User;
<<<<<<< HEAD
import org.picketlink.idm.query.IdentityQuery;
import org.picketlink.idm.spi.IdentityContext;
import org.picketlink.idm.spi.IdentityStore;

import java.util.ArrayList;
import java.util.List;

import static org.picketlink.idm.IDMLog.CREDENTIAL_LOGGER;
import static org.picketlink.idm.credential.Credentials.Status;

=======
import org.picketlink.idm.spi.IdentityContext;
import org.picketlink.idm.spi.IdentityStore;

>>>>>>> 452f5b08f055a35c8179aaed5a51315605a516a6
/**
 * 

Base class for {@link CredentialHandler} implementations.

*
Solution content
import org.picketlink.idm.model.IdentityType;
import org.picketlink.idm.model.basic.Agent;
import org.picketlink.idm.model.basic.User;
import org.picketlink.idm.query.IdentityQuery;
import org.picketlink.idm.spi.IdentityContext;
import org.picketlink.idm.spi.IdentityStore;

import java.util.ArrayList;
import java.util.List;

import static org.picketlink.idm.IDMLog.CREDENTIAL_LOGGER;
import static org.picketlink.idm.IDMMessages.MESSAGES;

/**
 * 

Base class for {@link CredentialHandler} implementations.

*
File
AbstractCredentialHandler.java
Developer's decision
Manual
Kind of conflict
Import
Chunk
Conflicting content
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 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[] accountTypes = (Class[]) options.get( SUPPORTED_ACCOUNT_TYPES_PROPERTY); if (accountTypes != null) { supportedAccountTypes = new ArrayList>(); for (Class 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 accounts = null; if (supportedAccountTypes != null) { for (Class 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
Solution content
public abstract class AbstractCredentialHandler, V extends AbstractBaseCredentials, U>
        implements CredentialHandler {

    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 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.size() == 1) { IdentityType account = result.get(0); if (!Account.class.isInstance(account)) { throw MESSAGES.credentialInvalidAccountType(account.getClass()); } return (Account) account; } else if (result.size() > 1) { CREDENTIAL_LOGGER.errorf("Multiple Account objects found with the same login name [%s] for type [%s]: [%s]", defaultAccountLoginNameProperty, accountType, result); throw MESSAGES.credentialMultipleAccountsFoundForType(defaultAccountLoginNameProperty, accountType); } } return null; } @Override
File
AbstractCredentialHandler.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
Comment
For statement
If statement
Method declaration
Method invocation
Method signature
Return statement
Variable