use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.
the class RestAuthenticationHandler method authenticate.
/**
* Handles either the creation or retrieval of the Login Process, dependent on if the request is a new
* authentication request or a continuation of one.
*
* @param request The HttpServletRequest.
* @param response The HttpServletResponse.
* @param postBody The post body of the request.
* @param authIndexType The authentication index type.
* @param indexValue The authentication index value.
* @param sessionUpgradeSSOTokenId The SSO Token Id of the user's current session, null if not performing a session
* upgrade.
* @return The Response of the authentication request.
*/
private JsonValue authenticate(HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String authIndexType, String indexValue, String sessionUpgradeSSOTokenId) throws RestAuthException {
LoginProcess loginProcess = null;
try {
AuthIndexType indexType = getAuthIndexType(authIndexType);
String authId = null;
String sessionId = null;
if (postBody != null) {
authId = getAuthId(postBody);
if (authId != null) {
SignedJwt jwt = authIdHelper.reconstructAuthId(authId);
sessionId = getSessionId(jwt);
indexType = getAuthIndexType(jwt);
indexValue = getAuthIndexValue(jwt);
String realmDN = getRealmDomainName(jwt);
AuditRequestContext.putProperty(SESSION_ID, sessionId);
authIdHelper.verifyAuthId(realmDN, authId);
}
}
LoginConfiguration loginConfiguration = new LoginConfiguration().httpRequest(request).httpResponse(response).indexType(indexType).indexValue(indexValue).sessionId(sessionId).forceAuth(request.getParameter(AuthUtils.FORCE_AUTH)).sessionUpgrade(sessionUpgradeSSOTokenId);
loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
return processAuthentication(request, response, postBody, authId, loginProcess, loginConfiguration);
} catch (RestAuthException e) {
if (loginProcess != null) {
String failureUrl = urlValidator.getRedirectUrl(loginProcess.getAuthContext().getOrgDN(), loginProcess.getFailureURL(), null);
e.setFailureUrl(failureUrl);
}
throw e;
} catch (L10NMessageImpl e) {
throw new RestAuthException(amAuthErrorCodeResponseStatusMapping.getAuthLoginExceptionResponseStatus(e.getErrorCode()), e);
} catch (JsonException e) {
throw new RestAuthException(ResourceException.INTERNAL_ERROR, e);
} catch (SignatureException e) {
throw new RestAuthException(ResourceException.INTERNAL_ERROR, e);
} catch (AuthLoginException e) {
throw new RestAuthException(amAuthErrorCodeResponseStatusMapping.getAuthLoginExceptionResponseStatus(e.getErrorCode()), e);
} catch (JwsSigningException jse) {
DEBUG.error("JwsSigningException", jse);
throw new RestAuthException(ResourceException.INTERNAL_ERROR, "JwsSigningException, " + jse.getMessage());
}
}
use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.
the class PLLNotificationServlet method doPost.
/*
* Accepts POST requests, reads Inpt Stream, forwards the NotificationSet
* XML Flushes the ResponseSet XML to OutputStream @param
* HttpServletNotification Reference to HttpServletNotification object
* @param HttpServletResponse Reference to HttpServletResponse object
*
* @see javax.servlet.http.HttpServlet
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
// Check content length
try {
RequestUtils.checkContentLength(request);
} catch (L10NMessageImpl e) {
ISLocaleContext localeContext = new ISLocaleContext();
localeContext.setLocale(request);
java.util.Locale locale = localeContext.getLocale();
throw new ServletException(e.getL10NMessage(locale));
}
int length = request.getContentLength();
if (length == -1) {
throw new ServletException(PLLBundle.getString("unknownLength"));
}
byte[] reqData = new byte[length];
InputStream in = request.getInputStream();
int rlength = 0;
int offset = 0;
while (rlength != length) {
int r = in.read(reqData, offset, length - offset);
if (r == -1) {
throw new ServletException(PLLBundle.getString("readRequestError"));
}
rlength += r;
offset += r;
}
String xml = new String(reqData, 0, length, "UTF-8");
ServletOutputStream out = response.getOutputStream();
try {
try {
handleNotification(xml);
out.print("OK");
} catch (ServletException e) {
out.print("NOT OK");
}
out.flush();
} finally {
if (out != null) {
out.close();
}
}
}
use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.
the class AuthContext method getSSOToken.
/**
* Returns the Single-Sign-On (SSO) Token for the authenticated
* user. If the user has not successfully authenticated
* <code>Exception</code> will be thrown.
* <p>
* Single sign token can be used as the authenticated token.
*
* @return Single-Sign-On token for the valid user after successful
* authentication.
* @throws L10NMessageImpl if the user is not authenticated or an error is
* encountered in retrieving the user's single sign on token.
* @supported.api
*/
public SSOToken getSSOToken() throws L10NMessageImpl {
if (localFlag) {
if (!acLocal.getStatus().equals(Status.SUCCESS)) {
throw new L10NMessageImpl(amAuthContext, "statusNotSuccess", null);
}
return (acLocal.getSSOToken());
} else {
// Get the loginStatus node
if (!loginStatus.equals(Status.SUCCESS)) {
throw new L10NMessageImpl(amAuthContext, "statusNotSuccess", null);
}
Node loginStatusNode = XMLUtils.getRootNode(receivedDocument, AuthXMLTags.LOGIN_STATUS);
if (loginStatusNode == null) {
throw new L10NMessageImpl(amAuthContext, "noStatusNode", null);
}
String ssoTokenIDTmp = XMLUtils.getNodeAttributeValue(loginStatusNode, AuthXMLTags.SSOTOKEN);
try {
return new com.iplanet.sso.providers.dpro.SSOProviderImpl().createSSOToken(ssoTokenIDTmp, true);
} catch (SSOException ssoe) {
throw new L10NMessageImpl(amAuthContext, "createSSOTokenError", null);
}
}
}
use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.
the class AuthContext method processRequest.
protected Document processRequest(String xmlRequest) throws AuthLoginException {
Document doc = null;
try {
Request request = new Request(xmlRequest);
RequestSet set = new RequestSet(AuthXMLTags.AUTH_SERVICE);
set.addRequest(request);
URL url = authServiceURL;
if (url.getProtocol().equals("https") && (nickName != null)) {
Class[] paramtype = { String.class };
Object[] param = { nickName };
String protHandler = protHandlerPkg + ".https.Handler";
Constructor construct = Class.forName(protHandler).getConstructor(paramtype);
URLStreamHandler handler = (URLStreamHandler) construct.newInstance(param);
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), handler);
}
if (authDebug.messageEnabled()) {
authDebug.message("Service URL : " + url.toString());
}
Vector responses = PLLClient.send(url, set, cookieTable);
if ((responses.isEmpty()) || (responses.size() != 1)) {
throw new L10NMessageImpl(amAuthContext, "responseError", null);
}
Response res = (Response) responses.elementAt(0);
String responseStr = (String) res.getContent();
doc = XMLUtils.getXMLDocument(new ByteArrayInputStream(responseStr.getBytes("UTF-8")));
} catch (Exception e) {
authDebug.message("error in getting service url", e);
throw new AuthLoginException(amAuthContext, "xmlProcessError", null, e);
}
return (doc);
}
use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.
the class Gateway method doPost.
/**
* Performs the HTTP POST operation.
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Obtain goto URL and check if there are auth parameters
String authScheme = null;
String authLevel = null;
String gotoUrl = null;
ActionDecision ad = null;
Map advices = null;
String orgName = null;
// Check content length
try {
RequestUtils.checkContentLength(request);
} catch (L10NMessageImpl e) {
ISLocaleContext localeContext = new ISLocaleContext();
localeContext.setLocale(request);
java.util.Locale locale = localeContext.getLocale();
if (debug.messageEnabled()) {
debug.message("GatewayServlet: " + e.getL10NMessage(locale));
}
throw new ServletException(e.getL10NMessage(locale));
}
// Construct the default forwarding URL
StringBuilder forwardUrl = new StringBuilder(200);
forwardUrl.append(LOGIN_URL);
String queryString = request.getQueryString();
Enumeration paramNames = request.getParameterNames();
while ((queryString != null) && paramNames.hasMoreElements()) {
String key = (String) paramNames.nextElement();
if (key.equalsIgnoreCase(GOTO_URL)) {
gotoUrl = request.getParameter(key);
} else if (key.equalsIgnoreCase(AUTH_SCHEME)) {
authScheme = request.getParameter(key);
} else if (key.equalsIgnoreCase(AUTH_LEVEL)) {
authLevel = request.getParameter(key);
}
}
if (debug.messageEnabled()) {
debug.message("GatewayServlet: queryString : " + queryString);
debug.message("GatewayServlet: gotoUrl : " + gotoUrl);
}
if (gotoUrl != null) {
ad = getActionDecision(gotoUrl);
if (ad != null) {
advices = ad.getAdvices();
orgName = getOrgNameFromAdvice(advices);
}
}
AuthServiceConfigInfo info = null;
// Construct the forward URL
if ((gotoUrl != null) && ((authScheme == null) && (authLevel == null))) {
if (debug.messageEnabled()) {
debug.message("GatewayServlet: gotoUrl : " + gotoUrl);
}
// we have only goto URL, hence find from policy if there are
// any advices on authentication modules
forwardUrl.append('?').append(queryString);
String advice = getPolicyAdvice(ad);
info = getGWServletUtilsFromMap(advices);
if (advice != null) {
StringBuffer adv = new StringBuffer();
int index1 = advice.indexOf("=");
if (index1 != -1) {
adv = adv.append(advice.substring(0, index1 + 1));
int index2 = advice.indexOf(":");
if (index2 != -1) {
orgName = advice.substring(index1 + 1, index2);
adv = adv.append(advice.substring(index2 + 1));
advice = adv.toString();
}
}
}
if (debug.messageEnabled()) {
debug.message("GatewayServlet: advice from getPolicyAdvice(): " + advice);
}
if (advice != null && advice.length() > 0) {
forwardUrl.append('&').append(advice);
}
} else if ((authScheme != null) || (authLevel != null)) {
// Either query string contains goto url & auth parameters
// which could be auth level or module, or no goto url
forwardUrl.append('?').append(queryString);
if (authScheme != null) {
info = getGWServletUtilsByScheme(orgName, authScheme);
} else if (authLevel != null) {
info = getGWServletUtilsByLevel(orgName, authLevel);
}
}
// If module is Cert, redirect to Cert module URL
String fUrl = forwardUrl.toString();
if (debug.messageEnabled()) {
debug.message("GatewayServlet >>> Need to change URL !");
debug.message("OLD URL : " + fUrl);
}
if ((info != null) && (info.getPortNumber() != null)) {
fUrl = CERT_PROTOCOL + request.getServerName() + ":" + info.getPortNumber() + SystemProperties.get(AuthXMLTags.SERVER_DEPLOY_URI) + fUrl;
if ((orgName != null) && (fUrl.indexOf("org=") == -1)) {
fUrl = fUrl + "&" + ORG_NAME + "=" + DNtoName(orgName);
}
response.sendRedirect(fUrl);
} else {
// Forward the request to Login servlet
if ((orgName != null) && (fUrl.indexOf("org=") == -1)) {
fUrl = fUrl + "&" + ORG_NAME + "=" + DNtoName(orgName);
}
// Forward the request to Login servlet
RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(fUrl);
dispatcher.forward(request, response);
}
if (debug.messageEnabled()) {
debug.message("New URL : " + fUrl);
}
}
Aggregations