use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class PolicyRequestHandler method process.
/**
* Process the requests aÎnd return the responses.
*
* @param requests Requests specified in the policy request
* @return the set of the response
*/
public ResponseSet process(PLLAuditor auditor, List<Request> requests, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext) {
ResponseSet resSet = new ResponseSet(PolicyService.POLICY_SERVICE);
int size = requests.size();
auditor.setComponent(POLICY);
for (Request req : requests) {
Response res = null;
try {
res = processRequest(req, auditor);
} catch (PolicyEvaluationException pe) {
if (debug.messageEnabled()) {
debug.message("PolicyRequesthandler.process" + " caught PolicyEvaluationException:", pe);
}
PolicyService ps = new PolicyService();
try {
String rev = getPolicyServiceRevision();
ps.setRevision(rev);
} catch (PolicyEvaluationException pee) {
debug.error("PolicyRequesthandler.process" + " can not get service revision number, " + ",revision defaulting to :" + PolicyService.ON_ERROR_REVISION_NUMBER, pee);
ps.setRevision(PolicyService.ON_ERROR_REVISION_NUMBER);
}
PolicyResponse pRes = new PolicyResponse();
pRes.setMethodID(PolicyResponse.POLICY_EXCEPTION);
pRes.setRequestId(pe.getRequestId());
pRes.setExceptionMsg(pe.getMessage());
pRes.setIssueInstant(System.currentTimeMillis());
ps.setMethodID(PolicyService.POLICY_RESPONSE_ID);
ps.setPolicyResponse(pRes);
res = new Response(ps.toXMLString());
auditor.auditAccessFailure(pe.getMessage());
}
if (res != null) {
resSet.addResponse(res);
}
}
return resSet;
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class SessionPLLSender method sendPLLRequest.
/**
* Returns a Session Response object based on the XML document received from
* remote Session Server. This is in response to a request that we send to
* the session server.
*
* @param svcurl The URL of the Session Service.
* @param sreq The Session Request XML document.
* @return a Vector of responses from the remote server
* @exception com.iplanet.dpro.session.SessionException if there was an error in sending the XML
* document or if the response has multiple components.
*/
public SessionResponse sendPLLRequest(URL svcurl, SessionRequest sreq) throws SessionException {
try {
String cookies = sessionCookies.getCookieName() + "=" + sreq.getSessionID();
if (!SystemProperties.isServerMode()) {
SessionID sessionID = new SessionID(sreq.getSessionID());
cookies = cookies + ";" + sessionCookies.getLBCookie(sessionID);
}
final Request req = new Request(sreq.toXMLString());
final RequestSet set = new RequestSet(SESSION_SERVICE);
set.addRequest(req);
final Vector responses = PLLClient.send(svcurl, cookies, set);
if (responses.size() != 1) {
throw new SessionException(SessionBundle.rbName, "unexpectedResponse", null);
}
final Response res = (Response) responses.elementAt(0);
return SessionResponse.parseXML(res.getContent());
} catch (Exception e) {
throw new SessionException(e);
}
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class ResourceResultCache method sendPLLRequest.
/**
* Return a PolicyService object based on the XML document received
* from remote Policy Server. This is in response to a request that we
* send to the Policy server.
* @param policyServiceUrl The URL of the Policy Service
* @param preq The SessionRequest XML document
* @return PolicyService
* @exception SendRequestException is thrown if there was an error in
* sending the XML document or PolicyException if there are any parsing
* errors.
*/
public static PolicyService sendPLLRequest(URL policyServiceUrl, PolicyRequest preq) throws SendRequestException, PolicyException {
String lbcookie = null;
try {
lbcookie = getLBCookie(preq);
} catch (Exception e) {
throw new SendRequestException(e);
}
PolicyService policyService = new PolicyService();
policyService.setMethodID(PolicyService.POLICY_REQUEST_ID);
policyService.setPolicyRequest(preq);
String xmlString = policyService.toXMLString();
Request request = new Request(xmlString);
RequestSet requestSet = new RequestSet(PolicyService.POLICY_SERVICE);
requestSet.addRequest(request);
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.sendPLLRequest:" + "sending PLL request to URL=" + policyServiceUrl + ":\nPLL message=" + xmlString);
}
Vector responses = PLLClient.send(policyServiceUrl, lbcookie, requestSet);
Response response = (Response) responses.elementAt(0);
PolicyService ps = PolicyService.parseXML(response.getContent());
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.sendPLLRequest:" + "result=" + ps.toXMLString());
}
return ps;
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class ResourceResultCache method getResultsFromServer.
/**
* Returns a set of <code>ResourceResult</code> objects from server.
* Fresh resource results
* are fetched from policy server and returned.
* @param appToken application sso token to identify the client to policy
* service
*
* @param serviceName name of service for which to get resource results
* @param token session token of user for whom to get resource results
* @param resourceName resource name for which to get resource results
* @param scope the scope to be used while getting resource results
* @param actionNames action names for which to get resource results
* @param env environment map to use to get resource results
*
* @return a set of <code>ResourceResult</code> objects
*
* @throws PolicyException if can not get resource results
* @throws SSOException if session token is not valid
* @throws InvalidAppSSOTokenException if application session token
* is not valid
*/
private Set getResultsFromServer(SSOToken appToken, String serviceName, SSOToken token, String resourceName, String scope, Set actionNames, Map env) throws InvalidAppSSOTokenException, SSOException, PolicyException {
Set resourceResults = null;
Response response = null;
try {
URL policyServiceUrl = getPolicyServiceURL(token);
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.getResultsFromServer():" + ":serviceName=" + serviceName + ":token=" + token.getPrincipal().getName() + ":resourceName=" + resourceName + ":scope=" + scope + ":actionNames=" + actionNames + ":env" + ":policyServiceURL=" + policyServiceUrl + ":entering");
}
ResourceResultRequest rrRequest = new ResourceResultRequest();
rrRequest.setServiceName(serviceName);
rrRequest.setResourceName(resourceName);
rrRequest.setResourceScope(scope);
rrRequest.setUserSSOToken(token.getTokenID().toString());
Set responseAttributes = null;
if (env != null) {
rrRequest.setEnvParms(env);
responseAttributes = getResponseAttributes(env);
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.getResultsFromServer():" + "responseAttributes to get=" + responseAttributes);
}
if (responseAttributes != null) {
rrRequest.setResponseAttributes(responseAttributes);
}
}
PolicyRequest policyRequest = new PolicyRequest();
policyRequest.setAppSSOToken(appToken.getTokenID().toString());
policyRequest.setMethodID(PolicyRequest.POLICY_REQUEST_GET_RESOURCE_RESULTS);
policyRequest.setRequestId(newRequestID());
policyRequest.setResourceResultRequest(rrRequest);
PolicyService ps = sendPLLRequest(policyServiceUrl, policyRequest);
if (ps != null) {
PolicyResponse pr = ps.getPolicyResponse();
String exceptionMessage = pr.getExceptionMsg();
if (exceptionMessage != null) {
if (exceptionMessage.indexOf(PolicyResponse.APP_SSO_TOKEN_INVALID) >= 0) {
if (debug.warningEnabled()) {
debug.warning("ResourceResultCache." + "getResultsFromServer():" + " response exception " + exceptionMessage);
debug.warning("ResourceResultCache." + "getResultsFromServer():" + " appSSOToken is invalid");
debug.warning("ResourceResultCache." + "throwing InvalidAppSSOTokenException");
}
String[] args = { exceptionMessage };
throw new InvalidAppSSOTokenException(ResBundleUtils.rbName, "server_reported_invalid_app_sso_token", args, null);
} else {
debug.warning("ResourceResultCache." + "getResultsFromServer():" + "response exception message=" + exceptionMessage);
String[] args = { exceptionMessage };
throw new PolicyEvaluationException(ResBundleUtils.rbName, "server_reported_exception", args, null);
}
} else {
resourceResults = pr.getResourceResults();
}
}
} catch (SendRequestException sre) {
String[] args = { sre.getMessage() };
throw new PolicyEvaluationException(ResBundleUtils.rbName, "pll_send_request_exception", args, sre);
}
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.getResultsFromServer():" + "returning");
}
return resourceResults;
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class LogRecWrite method execute.
/**
* Return result of the request processing in <code>Response</code>
* @return result of the request processing in <code>Response</code>
*/
public Response execute(AuditEventPublisher auditEventPublisher, AuditEventFactory auditEventFactory) {
Response res = new Response("OK");
SsoServerLoggingSvcImpl slsi = null;
SsoServerLoggingHdlrEntryImpl slei = null;
if (MonitoringUtil.isRunning()) {
slsi = Agent.getLoggingSvcMBean();
slei = slsi.getHandler(SsoServerLoggingSvcImpl.REMOTE_HANDLER_NAME);
}
Logger logger = (Logger) Logger.getLogger(_logname);
if (Debug.messageEnabled()) {
Debug.message("LogRecWrite: exec: logname = " + _logname);
}
Level level = Level.parse(((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).level);
String msg = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).msg;
Map logInfoMap = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).logInfoMap;
Object[] parameters = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).parameters;
try {
msg = new String(com.sun.identity.shared.encode.Base64.decode(msg));
} catch (RuntimeException ex) {
// write msg as it is.
if (Debug.messageEnabled()) {
Debug.message("LogRecWrite: message is not base64 encoded");
}
}
LogRecord rec = new LogRecord(level, msg);
if (logInfoMap != null) {
String loginIDSid = (String) logInfoMap.get(LogConstants.LOGIN_ID_SID);
if (loginIDSid != null && loginIDSid.length() > 0) {
SSOToken loginIDToken = null;
try {
SSOTokenManager ssom = SSOTokenManager.getInstance();
loginIDToken = ssom.createSSOToken(loginIDSid);
} catch (SSOException e) {
if (Debug.warningEnabled()) {
Debug.warning("LogService::process(): SSOException", e);
}
rec.setLogInfoMap(logInfoMap);
}
if (loginIDToken != null) {
// here fill up logInfo into the newlr
rec = LogSSOTokenDetails.logSSOTokenInfo(rec, loginIDToken);
// now take one be one values from logInfoMap and overwrite
// any populated value from sso token.
Set keySet = logInfoMap.keySet();
Iterator i = keySet.iterator();
String key = null;
String value = null;
while (i.hasNext()) {
key = (String) i.next();
value = (String) logInfoMap.get(key);
if (value != null && value.length() > 0) {
if (key.equalsIgnoreCase(LogConstants.DATA)) {
try {
value = new String(com.sun.identity.shared.encode.Base64.decode(value));
} catch (RuntimeException ex) {
// ignore & write msg as it is.
if (Debug.messageEnabled()) {
Debug.message("LogRecWrite: data is not " + "base64 encoded");
}
}
}
rec.addLogInfo(key, value);
}
}
}
} else {
rec.setLogInfoMap(logInfoMap);
}
}
rec.addLogInfo(LogConstants.LOG_LEVEL, rec.getLevel().toString());
rec.setParameters(parameters);
SSOToken loggedByToken = null;
String realm = NO_REALM;
try {
SSOTokenManager ssom = SSOTokenManager.getInstance();
loggedByToken = ssom.createSSOToken(_loggedBySid);
Map<String, Set<String>> appAttributes = IdUtils.getIdentity(loggedByToken).getAttributes();
realm = getFirstItem(appAttributes.get(EVALUATION_REALM), NO_REALM);
} catch (IdRepoException | SSOException ssoe) {
Debug.error("LogRecWrite: exec:SSOException: ", ssoe);
}
if (MonitoringUtil.isRunning()) {
slei.incHandlerRequestCount(1);
}
auditAccessMessage(auditEventPublisher, auditEventFactory, rec, realm);
logger.log(rec, loggedByToken);
// Log file record write okay and return OK
if (MonitoringUtil.isRunning()) {
slei.incHandlerSuccessCount(1);
}
return res;
}
Aggregations