use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.
the class AuthContextLocal method login.
/**
* Performs the Login for the given AuthContext
* @param type authentication index type
* @param indexName authentication index name
* @param principal principal name of the user to be authenticated
* @param password password for the user
* @param subject authentication subject
* @param envMap Environment map, this is applicable only when the type
* is <code>AuthContext.IndexType.RESOURCE</code>
* @param locale locale setting
* @throws AuthLoginException if error occurs during login
*/
protected void login(AuthContext.IndexType type, String indexName, Principal principal, char[] password, Subject subject, Map envMap, String locale) throws AuthLoginException {
try {
/*if (!getStatus().equals(AuthContext.Status.NOT_STARTED)) {
if (authDebug.messageEnabled()) {
authDebug.message("AuthContextLocal::login called " +
"when the current login status is : " + getStatus());
}
throw new AuthLoginException(amAuthContextLocal,
"invalidMethod", new Object[]{getStatus()});
}*/
// switch the login status
loginStatus = AuthContext.Status.IN_PROGRESS;
String redirectUrl = null;
// specially processing for resouce/IP/Environement based auth
if ((type != null) && type.equals(AuthContext.IndexType.RESOURCE)) {
// this is resouce/IP/Env based authentication
// call Policy Decision Util to find out the actual auth type
// required by policy
List result = Collections.EMPTY_LIST;
try {
result = PolicyDecisionUtils.doResourceIPEnvAuth(indexName, organizationName, envMap);
} catch (PolicyException pe) {
// ignore, continue to default realm based authentication
// may need to revisit this in the future
authDebug.warning("AuthContextLocal.login() policy error " + "indexName=" + indexName, pe);
type = null;
indexName = null;
}
if (authDebug.messageEnabled()) {
authDebug.message("AuthContextLocal.login: policy decision=" + result);
}
if (result.size() == 2) {
type = (AuthContext.IndexType) result.get(0);
indexName = (String) result.get(1);
} else if (result.size() == 1) {
// this is the redirection case (Policy Redirection Advice)
redirectUrl = (String) result.get(0);
// append goto parameter for federation case
Set tmp = (Set) envMap.get(ISAuthConstants.GOTO_PARAM);
if ((tmp != null) && !tmp.isEmpty()) {
String gotoParam = (String) tmp.iterator().next();
if ((gotoParam != null) && (gotoParam.length() != 0)) {
if ((redirectUrl != null) && (redirectUrl.indexOf("?") != -1)) {
redirectUrl = redirectUrl + "&" + ISAuthConstants.GOTO_PARAM + "=" + URLEncDec.encode(gotoParam);
} else {
redirectUrl = redirectUrl + "?" + ISAuthConstants.GOTO_PARAM + "=" + URLEncDec.encode(gotoParam);
}
}
}
type = null;
indexName = null;
} else {
// no policy decision, use default realm login
type = null;
indexName = null;
}
}
HashMap loginParamsMap = new HashMap();
loginParamsMap.put(INDEX_TYPE, type);
loginParamsMap.put(INDEX_NAME, indexName);
loginParamsMap.put(PRINCIPAL, principal);
loginParamsMap.put(PASSWORD, password);
loginParamsMap.put(SUBJECT, subject);
loginParamsMap.put(LOCALE, locale);
if (redirectUrl != null) {
loginParamsMap.put(REDIRECT_URL, redirectUrl);
}
if (authDebug.messageEnabled()) {
authDebug.message("loginParamsMap : " + loginParamsMap.toString());
}
authDebug.message("calling AMLoginContext::exceuteLogin : ");
amlc.executeLogin(loginParamsMap);
authDebug.message("after AMLoginContext::exceuteLogin : ");
if (amlc.getStatus() == LoginStatus.AUTH_SUCCESS) {
loginStatus = AuthContext.Status.SUCCESS;
} else if (amlc.getStatus() == LoginStatus.AUTH_FAILED) {
loginStatus = AuthContext.Status.FAILED;
}
if (authDebug.messageEnabled()) {
authDebug.message("Status at the end of login() : " + loginStatus);
}
} catch (AuthLoginException e) {
if (authDebug.messageEnabled()) {
authDebug.message("Exception in ac.login : " + e.toString());
}
throw e;
}
}
use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.
the class PolicyModelImpl method getResponseProviderInstance.
private ResponseProvider getResponseProviderInstance(String realmName, String typeName) {
ResponseProvider provider = null;
try {
PolicyManager policyMgr = getPolicyManager(realmName);
if (policyMgr != null) {
ResponseProviderTypeManager mgr = policyMgr.getResponseProviderTypeManager();
provider = mgr.getResponseProvider(typeName);
}
} catch (AMConsoleException e) {
debug.warning("PolicyModelImpl.getResponseProviderInstance", e);
} catch (NameNotFoundException e) {
debug.warning("PolicyModelImpl.getResponseProviderInstance", e);
} catch (PolicyException e) {
debug.warning("PolicyModelImpl.getResponseProviderInstance", e);
}
return provider;
}
use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.
the class PolicyPropertyXMLBuilderBase method appendChoiceValues.
private void appendChoiceValues(String name, Syntax syntax, StringBuffer xml) {
int syn = AMDisplayType.getDisplaySyntax(syntax);
switch(syn) {
case AMDisplayType.SYNTAX_SINGLE_CHOICE:
case AMDisplayType.SYNTAX_MULTIPLE_CHOICE:
try {
Set validValues = getValidValues(name);
if ((validValues != null) && !validValues.isEmpty()) {
Set sorted = new TreeSet(validValues);
for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
String val = (String) iter.next();
Object[] params = { val, val };
xml.append(MessageFormat.format(OPTION_TAG, params));
}
}
} catch (PolicyException e) {
debug.warning("PolicyPropertyXMLBuilderBase.appendChoiceValues", e);
}
break;
}
}
use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.
the class PolicyModelImpl method getDisplayNameForSubjectValues.
/**
* Returns a map of values to localized label.
*
* @param realmName Name of realm.
* @param subjectTypeName Name of Subject Type.
* @param values Valid values.
* @return a map of values to localized label.
*/
public Map getDisplayNameForSubjectValues(String realmName, String subjectTypeName, Set values) {
Map map = null;
if ((values != null) && !values.isEmpty()) {
map = new HashMap(values.size() * 2);
Locale locale = getUserLocale();
try {
PolicyManager policyMgr = getPolicyManager(realmName);
if (policyMgr != null) {
SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
Subject subject = subjectTypeMgr.getSubject(subjectTypeName);
for (Iterator i = values.iterator(); i.hasNext(); ) {
String v = (String) i.next();
map.put(v, subject.getDisplayNameForValue(v, locale));
}
}
} catch (AMConsoleException e) {
debug.warning("PolicyModelImpl.getDisplayNameForSubjectValues", e);
} catch (NameNotFoundException e) {
debug.warning("PolicyModelImpl.getDisplayNameForSubjectValues", e);
} catch (PolicyException e) {
debug.warning("PolicyModelImpl.getDisplayNameForSubjectValues", e);
}
}
return (map == null) ? Collections.EMPTY_MAP : map;
}
use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.
the class PolicyModelImpl method getResponseProviderViewBeanURL.
/**
* Returns properties view bean URL of a response provider.
*
* @param realmName Name of realm.
* @param typeName Name of response provider Type.
* @return properties view bean URL of a response provider.
*/
public String getResponseProviderViewBeanURL(String realmName, String typeName) {
String url = null;
try {
PolicyManager policyMgr = getPolicyManager(realmName);
if (policyMgr != null) {
ResponseProviderTypeManager mgr = policyMgr.getResponseProviderTypeManager();
ResponseProvider provider = mgr.getResponseProvider(typeName);
url = mgr.getViewBeanURL(provider);
}
} catch (AMConsoleException e) {
debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
} catch (NameNotFoundException e) {
debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
} catch (PolicyException e) {
debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
}
return url;
}
Aggregations