下面列出了java.net.ContentHandler#org.wso2.carbon.ui.CarbonUIUtil 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@inheritDoc}
*/
@Override
public void authenticate(HttpServletRequest request) throws AuthenticationException {
String userName = request.getRemoteUser();
userName = userName.substring(userName.indexOf("\\") + 1);
if (log.isDebugEnabled()) {
log.debug("Authenticate request received : Authtype - " + request.getAuthType() +
", User - " + userName);
}
ServletContext servletContext = request.getSession().getServletContext();
HttpSession session = request.getSession();
String backendServerURL = request.getParameter("backendURL");
if (backendServerURL == null) {
backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession());
}
session.setAttribute(CarbonConstants.SERVER_URL, backendServerURL);
String rememberMe = request.getParameter("rememberMe");
handleSecurity(userName, (rememberMe != null), request);
request.setAttribute("username", userName);
}
/**
* Initializes STSUtil
*
* @param cookie Cookie string
* @throws Exception
*/
public STSUtil(ServletConfig config, HttpSession session, String cookie) throws Exception {
ServiceClient client = null;
Options option = null;
String serverUrl = null;
// Obtaining the client-side ConfigurationContext instance.
configContext = (ConfigurationContext) config.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
// Server URL which is defined in the server.xml
serverUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);
this.serviceEndPoint = serverUrl + "STSAdminService";
try {
this.stub = new STSAdminServiceStub(configContext, serviceEndPoint);
} catch (AxisFault e) {
log.error("Error while creating STSAdminServiceStub", e);
throw new Exception(e);
}
client = stub._getServiceClient();
option = client.getOptions();
option.setManageSession(true);
option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}
/**
* Initializes STSUtil
*
* @param cookie Cookie string
* @throws Exception
*/
public CarbonSTSClient(ServletConfig config, HttpSession session, String cookie)
throws Exception {
ServiceClient client = null;
Options option = null;
String serverUrl = null;
// Obtaining the client-side ConfigurationContext instance.
configContext = (ConfigurationContext) config.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
// Server URL which is defined in the server.xml
serverUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);
this.serviceEndPoint = serverUrl + "STSAdminService";
try {
this.stub = new STSAdminServiceStub(configContext, serviceEndPoint);
} catch (AxisFault e) {
log.error("Error while creating STSAdminServiceStub", e);
throw new Exception(e);
}
client = stub._getServiceClient();
option = client.getOptions();
option.setManageSession(true);
option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}
/**
* @param request
* @return
* @throws AxisFault
*/
private IWAAuthenticatorStub getIWAClient(HttpServletRequest request)
throws AxisFault, IdentityException {
HttpSession session = request.getSession();
ServletContext servletContext = session.getServletContext();
String backendServerURL = request.getParameter("backendURL");
if (backendServerURL == null) {
backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession());
}
ConfigurationContext configContext = (ConfigurationContext) servletContext
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String serviceEPR = backendServerURL + "IWAAuthenticator";
IWAAuthenticatorStub stub = new IWAAuthenticatorStub(configContext, serviceEPR);
ServiceClient client = stub._getServiceClient();
client.engageModule("rampart");
Policy rampartConfig = IdentityBaseUtil.getDefaultRampartConfig();
Policy signOnly = IdentityBaseUtil.getSignOnlyPolicy();
Policy mergedPolicy = signOnly.merge(rampartConfig);
Options options = client.getOptions();
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, mergedPolicy);
options.setManageSession(true);
return stub;
}
private void init(HttpServletRequest request) throws Exception {
HttpSession session = request.getSession();
String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) session.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
client = new ReportTemplateClient(configContext, serverURL, cookie);
Map<String, ArrayList<FileItemData>> fileItemsMap = getFileItemsMap();
formFieldsMap = getFormFieldsMap();
images = fileItemsMap.get("logo");
String type = null;
if(formFieldsMap.get("reportType") != null){
type = formFieldsMap.get("reportType").get(0);
}
if(type == null){
tableReport= (TableReportDTO)session.getAttribute("table-report");
}
else {
chartReport = (ChartReportDTO)session.getAttribute("chart-report");
}
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws
Exception {
String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
HttpSession session = request.getSession();
String serverURL = CarbonUIUtil.getServerURL(getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
ReportTemplateClient client;
String errorString = "";
client = new ReportTemplateClient(configContext, serverURL, cookie);
String reportname = request.getParameter("reportName");
String[] reports = getSubReportsName(request);
if (reports != null) {
client.addNewCompositeReport(reports, reportname);
response.sendRedirect("../reporting_custom/list-reports.jsp?region=region5&item=reporting_list");
} else {
errorString = "No reports was sleected to form the composite report";
request.setAttribute("errorString", errorString);
response.sendRedirect("../reporting-template/add-composite-report.jsp");
}
}
public EmailVerificationServiceClient(ServletConfig config, HttpSession session)
throws RegistryException {
String cookie = (String)session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) config.
getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
epr = backendServerURL + "EmailVerificationService";
try {
stub = new EmailVerificationServiceStub(configContext, epr);
ServiceClient client = stub._getServiceClient();
Options option = client.getOptions();
option.setManageSession(true);
option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
} catch (AxisFault axisFault) {
String msg = "Failed to initiate Add Services service client. " + axisFault.getMessage();
log.error(msg, axisFault);
throw new RegistryException(msg, axisFault);
}
}
public static String getRelativeUrl() {
BundleContext context = CarbonUIUtil.getBundleContext();
ServiceReference reference = context.getServiceReference(RegistryService.class
.getName());
RegistryService registryService = (RegistryService) context.getService(reference);
String url = null;
try {
Registry systemRegistry = registryService.getConfigSystemRegistry();
Resource resource = systemRegistry.get("/carbon/connection/props");
String servicePath = resource.getProperty("service-path");
String contextRoot = resource.getProperty("context-root");
contextRoot = contextRoot.equals("/") ? "" : contextRoot;
url = contextRoot + servicePath + "/Java2WSDLService";
} catch (Exception e) {
log.error(e);
}
return url;
}
public static String getRelativeUrl() {
BundleContext context = CarbonUIUtil.getBundleContext();
ServiceReference reference =
context.getServiceReference(RegistryService.class.getName());
RegistryService registryService = (RegistryService) context.getService(reference);
String url = null;
try {
Registry systemRegistry = registryService.getConfigSystemRegistry();
Resource resource = systemRegistry.get(RegistryResources.CONNECTION_PROPS);
String servicePath = resource.getProperty("service-path");
String contextRoot = resource.getProperty("context-root");
contextRoot = contextRoot.equals("/") ? "" : contextRoot;
url = contextRoot + servicePath + "/WSDL2CodeService";
} catch (Exception e) {
log.error(e);
}
return url;
}
public static String getRelativeUrl() {
BundleContext context = CarbonUIUtil.getBundleContext();
ServiceReference reference =
context.getServiceReference(RegistryService.class.getName());
RegistryService registryService = (RegistryService) context.getService(reference);
String url = null;
try {
Registry systemRegistry = registryService.getConfigSystemRegistry();
Resource resource = systemRegistry.get(RegistryResources.CONNECTION_PROPS);
String servicePath = resource.getProperty("service-path");
String contextRoot = resource.getProperty("context-root");
contextRoot = contextRoot.equals("/") ? "" : contextRoot;
url = contextRoot + servicePath + "/WSDL2CodeService";
} catch (Exception e) {
log.error(e);
}
return url;
}
public RegistryAdminServiceClient(String cookie, ServletConfig config, HttpSession session)
throws AxisFault {
String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(),
session);
ConfigurationContext ctx = (ConfigurationContext) config.
getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
this.session = session;
String serviceEPR = serverURL + "RegistryAdminService";
stub = new RegistryAdminServiceStub(ctx, serviceEPR);
ServiceClient client = stub._getServiceClient();
Options options = client.getOptions();
options.setManageSession(true);
if (cookie != null) {
options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
}
}
/**
* Returns an instance of <code>OpenIDAdminClient</code>.
* Only one instance of this will be created for a session.
* This method is used to reuse the same client within a session.
*
* @param session
* @return {@link OpenIDAdminClient}
* @throws AxisFault
*/
public static OpenIDAdminClient getOpenIDAdminClient(HttpSession session) throws AxisFault {
OpenIDAdminClient client =
(OpenIDAdminClient) session.getAttribute(OpenIDConstants.SessionAttribute.OPENID_ADMIN_CLIENT);
if (client == null) { // a session timeout or the fist request
String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) session.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
client = new OpenIDAdminClient(configContext, serverURL, cookie);
session.setAttribute(OpenIDConstants.SessionAttribute.OPENID_ADMIN_CLIENT, client);
}
return client;
}
/**
* Get the admin console url from the request.
*
* @param request httpServletReq that hits the ACS Servlet
* @return Admin Console URL https://10.100.1.221:8443/acs/carbon/
*/
private String getAdminConsoleURL(HttpServletRequest request) {
String url = CarbonUIUtil.getAdminConsoleURL(request);
if (!url.endsWith("/")) {
url = url + "/";
}
if (url.indexOf("/acs") != -1) {
url = url.replace("/acs", "");
}
return url;
}
private void handleFederatedSAMLRequest(HttpServletRequest req, HttpServletResponse resp,
String ssoTokenID, String samlRequest,
String relayState, String authMode, Subject subject,
String rpSessionId)
throws IOException, ServletException, SAML2SSOUIAuthenticatorException {
// Instantiate the service client.
HttpSession session = req.getSession();
String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) session.getServletContext()
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
SAMLSSOServiceClient ssoServiceClient = new SAMLSSOServiceClient(serverURL, configContext);
String method = req.getMethod();
boolean isPost = false;
if ("post".equalsIgnoreCase(method)) {
isPost = true;
}
SAMLSSOReqValidationResponseDTO signInRespDTO =
ssoServiceClient.validate(samlRequest,
null, ssoTokenID,
rpSessionId,
authMode, isPost);
if (signInRespDTO.getValid()) {
handleRequestFromLoginPage(req, resp, ssoTokenID,
signInRespDTO.getAssertionConsumerURL(),
signInRespDTO.getId(), signInRespDTO.getIssuer(),
subject.getNameID().getValue(), subject.getNameID()
.getValue(),
signInRespDTO.getRpSessionId(),
signInRespDTO.getRequestMessageString(), relayState);
}
}
/**
* Generate an authentication request with passive support.
*
* @return AuthnRequest Object
* @throws Exception
*/
public AuthnRequest buildAuthenticationRequest(String subjectName, String nameIdPolicyFormat, boolean isPassive)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Building Authentication Request");
}
Util.doBootstrap();
AuthnRequest authnRequest = (AuthnRequest) Util
.buildXMLObject(AuthnRequest.DEFAULT_ELEMENT_NAME);
authnRequest.setID(Util.createID());
authnRequest.setVersion(SAMLVersion.VERSION_20);
authnRequest.setIssueInstant(new DateTime());
authnRequest.setIssuer(buildIssuer());
authnRequest.setNameIDPolicy(buildNameIDPolicy(nameIdPolicyFormat));
authnRequest.setIsPassive(isPassive);
authnRequest.setDestination(Util.getIdentityProviderSSOServiceURL());
String acs = Util.getAssertionConsumerServiceURL();
if (acs != null && acs.trim().length() > 0) {
authnRequest.setAssertionConsumerServiceURL(acs);
} else {
authnRequest.setAssertionConsumerServiceURL(CarbonUIUtil.getAdminConsoleURL("").replace("carbon/", "acs"));
}
if (subjectName != null) {
Subject subject = new SubjectBuilder().buildObject();
NameID nameId = new NameIDBuilder().buildObject();
nameId.setValue(subjectName);
nameId.setFormat(NameIdentifier.EMAIL);
subject.setNameID(nameId);
authnRequest.setSubject(subject);
}
Util.setSignature(authnRequest, XMLSignature.ALGO_ID_SIGNATURE_RSA, new SignKeyDataHolder());
return authnRequest;
}
@Override
public void unauthenticate(Object o) throws Exception {
HttpServletRequest request = (HttpServletRequest) o;
HttpSession session = request.getSession();
String username = (String) session.getAttribute(CarbonConstants.LOGGED_USER);
ServletContext servletContext = session.getServletContext();
ConfigurationContext configContext = (ConfigurationContext) servletContext
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String backendServerURL = CarbonUIUtil.getServerURL(servletContext, session);
try {
String cookie = (String) session.getAttribute(ServerConstants.
ADMIN_SERVICE_AUTH_TOKEN);
OIDCAuthenticationClient authClient = new
OIDCAuthenticationClient(configContext, backendServerURL, cookie, session);
authClient.logout(session);
log.info(username + "@" + PrivilegedCarbonContext.getThreadLocalCarbonContext().
getTenantDomain() +" successfully logged out");
} catch (Exception ignored) {
String msg = "OIDC logout failed";
log.error(msg, ignored);
throw new Exception(msg, ignored);
}
String logoutUrl = Util.getIdentityProviderURI() + "logout";
request.setAttribute(OIDCConstants.HTTP_ATTR_IS_LOGOUT_REQ, true);
request.setAttribute(OIDCConstants.EXTERNAL_LOGOUT_PAGE, logoutUrl);
}
/**
* Get the admin console url from the request.
*
* @param request httpServletReq that hits the ACS Servlet
* @return Admin Console URL https://10.100.1.221:9443/oidcacs/carbon/
*/
private String getAdminConsoleURL(HttpServletRequest request) {
String url = CarbonUIUtil.getAdminConsoleURL(request);
if (!url.endsWith("/")) {
url = url + "/";
}
if (url.contains("/oidcacs")) {
url = url.replace("/oidcacs", "");
}
return url;
}
public static NDataSourceAdminServiceClient getInstance(ServletConfig config,
HttpSession session) throws AxisFault {
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
return new NDataSourceAdminServiceClient(cookie, backendServerURL, configContext);
}
public static JrxmlFileUploaderClient getInstance(ServletConfig config, HttpSession session) throws AxisFault {
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) config.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
return new JrxmlFileUploaderClient(cookie,backendServerURL,configContext);
}
public static DBReportingServiceClient getInstance(ServletConfig config, HttpSession session)
throws AxisFault {
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) config.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
return new DBReportingServiceClient(cookie,backendServerURL,configContext);
}
public static ReportResourceSupplierClient getInstance(ServletConfig config, HttpSession session)
throws AxisFault {
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) config.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
return new ReportResourceSupplierClient(cookie, backendServerURL, configContext);
}
public static ReportResourceSupplierClient getInstance(ServletConfig config, HttpSession session)
throws AxisFault {
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) config.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
return new ReportResourceSupplierClient(cookie, backendServerURL, configContext);
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws
Exception {
HttpSession session = request.getSession();
String serverURL = CarbonUIUtil.getServerURL(getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
ReportTemplateClient client;
String errorString = "";
client = new ReportTemplateClient(configContext, serverURL, cookie);
String reportName = request.getParameter("reportName");
String reportType = request.getParameter("reportType");
String downloadFileName = null;
if (reportType.equals("pdf")) {
response.setContentType("application/pdf");
downloadFileName = reportName + ".pdf";
} else if (reportType.equals("xls")) {
response.setContentType("application/vnd.ms-excel");
downloadFileName = reportName + ".xls";
} else if (reportType.equals("html")) {
response.setContentType("text/html");
}
if (downloadFileName != null) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
}
DataHandler dataHandler = null;
if (client != null) {
dataHandler = client.generateReport(reportName, reportType);
}
ServletOutputStream outputStream = response.getOutputStream();
if (dataHandler != null) {
dataHandler.writeTo(outputStream);
}
}
/**
* Gets the broker client for EventBrokerService
* Suppressing warning of unused declaration as it used by the UI (JSP pages)
*
* @param config the servlet configuration
* @param session the http session
* @param request the http servlet request
* @return the broker client
*/
@SuppressWarnings("UnusedDeclaration")
public static BrokerClient getBrokerClient(ServletConfig config, HttpSession session,
HttpServletRequest request) {
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
backendServerURL = backendServerURL + "EventBrokerService";
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
return new BrokerClient(configContext, backendServerURL, cookie);
}
public int doStartTag() throws JspException {
//check permission.
HttpServletRequest req = (HttpServletRequest)
pageContext.getRequest();
if(!CarbonUIUtil.isUserAuthorized(req, "/permission/admin/manage/report")){
return EVAL_PAGE;
}
JspWriter writer = pageContext.getOut();
String context = "<div style='float:right;padding-bottom:5px;padding-right:15px;'>";
if(pdfReport){
context = context+ "<a target='_blank' class='icon-link' style='background-image:url(../admin/images/pdficon.gif);' href=\"../report" + "?" +"reportDataSession="+ reportDataSession + "&component=" + component + "&template=" + template + "&type=pdf" + "\">Generate Pdf Report</a>";
}
if(htmlReport){
context = context+ "<a target='_blank' class='icon-link' style='background-image:url(../admin/images/htmlicon.gif);' href=\"../report" + "?" + "reportDataSession="+ reportDataSession + "&component=" + component + "&template=" + template + "&type=html" + "\">Generate Html Report</a>";
}
if(excelReport){
context = context+ "<a target='_blank' class='icon-link' style='background-image:url(../admin/images/excelicon.gif);' href=\"../report" + "?" + "reportDataSession="+ reportDataSession + "&component=" + component + "&template=" + template + "&type=excel" +"\">Generate Excel Report</a>";
}
context = context + "</div><div style='clear:both;'></div>";
try {
writer.write(context);
} catch (IOException e) {
String msg = "Cannot write reporting tag content";
throw new JspException(msg, e);
}
return EVAL_PAGE;
}
public static Locale getLocaleFromPageContext(PageContext pageContext)
{
if (pageContext.getSession().getAttribute(CarbonUIUtil.SESSION_PARAM_LOCALE) != null) {
return CarbonUIUtil.toLocale(pageContext.getSession().getAttribute(CarbonUIUtil.SESSION_PARAM_LOCALE).toString());
}else{
return pageContext.getRequest().getLocale();
}
}
/**
* When a FileUpload request is received, this method will be called.
*
* @param request The HTTP Request
* @param response The HTTP Response
* @return true - if the file uploading was successful, false - otherwise
* @throws IOException If an unrecoverable error occurs during file upload
*/
public boolean execute(HttpServletRequest request,
HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
request.setAttribute(CarbonConstants.ADMIN_SERVICE_COOKIE, cookie);
request.setAttribute(CarbonConstants.WEB_CONTEXT, webContext);
request.setAttribute(CarbonConstants.SERVER_URL,
CarbonUIUtil.getServerURL(request.getSession().getServletContext(),
request.getSession()));
String requestURI = request.getRequestURI();
//TODO - fileupload is hardcoded
int indexToSplit = requestURI.indexOf("fileupload/") + "fileupload/".length();
String actionString = requestURI.substring(indexToSplit);
// Register execution handlers
FileUploadExecutionHandlerManager execHandlerManager =
new FileUploadExecutionHandlerManager();
CarbonXmlFileUploadExecHandler carbonXmlExecHandler =
new CarbonXmlFileUploadExecHandler(request, response, actionString);
execHandlerManager.addExecHandler(carbonXmlExecHandler);
OSGiFileUploadExecHandler osgiExecHandler =
new OSGiFileUploadExecHandler(request, response);
execHandlerManager.addExecHandler(osgiExecHandler);
AnyFileUploadExecHandler anyFileExecHandler =
new AnyFileUploadExecHandler(request, response);
execHandlerManager.addExecHandler(anyFileExecHandler);
execHandlerManager.startExec();
return true;
}
public static boolean isUserOnBoardingEnabled(ServletContext context, HttpSession session) {
if (!isAskPasswordAdminUIEnabled) {
return false;
}
String backendServerURL = CarbonUIUtil.getServerURL(context, session);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
ConfigurationContext configContext =
(ConfigurationContext) context.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
Map<String, Map<String, List<ConnectorConfig>>> connectorList;
try {
IdentityGovernanceAdminClient client =
new IdentityGovernanceAdminClient(cookie, backendServerURL, configContext);
connectorList = client.getConnectorList();
} catch (Exception e) {
log.error("Error while getting connector list from governance service, at URL :" +
backendServerURL, e);
return false;
}
if (connectorList != null) {
for (Map.Entry<String, Map<String, List<ConnectorConfig>>> entry : connectorList.entrySet()) {
Map<String, List<ConnectorConfig>> subCatList = entry.getValue();
for (String subCatKey : subCatList.keySet()) {
List<ConnectorConfig> connectorConfigs = subCatList.get(subCatKey);
for (ConnectorConfig connectorConfig : connectorConfigs) {
Property[] properties = connectorConfig.getProperties();
for (Property property : properties) {
if (property != null) {
if (EMAIL_VERIFICATION_ENABLE_PROP_NAME.equals(property.getName())) {
String propValue = property.getValue();
boolean isEmailVerificationEnabled = false;
if (!StringUtils.isEmpty(propValue)) {
isEmailVerificationEnabled = Boolean.parseBoolean(propValue);
}
return isEmailVerificationEnabled;
}
}
}
}
}
}
}
return false;
}
private void process(HttpServletRequest request, HttpServletResponse response,
SessionDTO sessionDTO, AuthenticationResult authnResult) throws ServletException, IOException {
HttpSession session = request.getSession();
session.removeAttribute(PassiveRequestorConstants.PASSIVE_REQ_ATTR_MAP);
RequestToken reqToken = new RequestToken();
Map<ClaimMapping, String> attrMap = authnResult.getSubject().getUserAttributes();
StringBuilder buffer = null;
if (MapUtils.isNotEmpty(attrMap)) {
buffer = new StringBuilder();
for (Iterator<Entry<ClaimMapping, String>> iterator = attrMap.entrySet().iterator(); iterator
.hasNext(); ) {
Entry<ClaimMapping, String> entry = iterator.next();
buffer.append("{" + entry.getKey().getRemoteClaim().getClaimUri() + "|" + entry.getValue() + "}#CODE#");
}
}
reqToken.setAction(sessionDTO.getAction());
if (buffer != null) {
reqToken.setAttributes(buffer.toString());
} else {
reqToken.setAttributes(sessionDTO.getAttributes());
}
reqToken.setContext(sessionDTO.getContext());
reqToken.setReplyTo(sessionDTO.getReplyTo());
reqToken.setPseudo(sessionDTO.getPseudo());
reqToken.setRealm(sessionDTO.getRealm());
reqToken.setRequest(sessionDTO.getRequest());
reqToken.setRequestPointer(sessionDTO.getRequestPointer());
reqToken.setPolicy(sessionDTO.getPolicy());
reqToken.setPseudo(session.getId());
reqToken.setUserName(authnResult.getSubject().getAuthenticatedSubjectIdentifier());
reqToken.setTenantDomain(sessionDTO.getTenantDomain());
String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
ConfigurationContext configContext =
(ConfigurationContext) session.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
IdentityPassiveSTSClient passiveSTSClient = null;
passiveSTSClient = new IdentityPassiveSTSClient(serverURL, configContext);
ResponseToken respToken = passiveSTSClient.getResponse(reqToken);
if (respToken != null && respToken.getResults() != null) {
persistRealms(reqToken, request.getSession());
sendData(response, respToken, reqToken.getAction(),
authnResult.getAuthenticatedIdPs());
}
}
private void handleRequestFromLoginPage(HttpServletRequest req, HttpServletResponse resp,
String ssoTokenID, String assertionConsumerUrl, String id, String issuer, String userName, String subject,
String rpSession, String requestMsgString, String relayState)
throws IOException, ServletException, SAML2SSOUIAuthenticatorException {
HttpSession session = req.getSession();
// instantiate the service client
String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) session.getServletContext()
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
SAMLSSOServiceClient ssoServiceClient = new SAMLSSOServiceClient(serverURL, configContext);
// Create SAMLSSOAuthnReqDTO using the request Parameters
SAMLSSOAuthnReqDTO authnReqDTO = new SAMLSSOAuthnReqDTO();
authnReqDTO.setAssertionConsumerURL(assertionConsumerUrl);
authnReqDTO.setId(id);
authnReqDTO.setIssuer(issuer);
//TODO FIX NEED TO BE DONE
authnReqDTO.setUser(null);
authnReqDTO.setPassword("federated_idp_login");
authnReqDTO.setSubject(subject);
authnReqDTO.setRpSessionId(rpSession);
authnReqDTO.setRequestMessageString(requestMsgString);
// authenticate the user
SAMLSSORespDTO authRespDTO = ssoServiceClient.authenticate(authnReqDTO, ssoTokenID);
if (authRespDTO.getSessionEstablished()) { // authentication is SUCCESSFUL
// Store the cookie
storeSSOTokenCookie(ssoTokenID, req, resp);
// add relay state, assertion string and ACS URL as request parameters.
req.setAttribute(SAMLConstants.RELAY_STATE, relayState);
req.setAttribute(SAMLConstants.ASSERTION_STR, authRespDTO.getRespString());
req.setAttribute(SAMLConstants.ASSRTN_CONSUMER_URL, authRespDTO.getAssertionConsumerURL());
req.setAttribute(SAMLConstants.SUBJECT, authRespDTO.getSubject());
RequestDispatcher reqDispatcher = req.getRequestDispatcher("/carbon/sso-acs/federation_ajaxprocessor.jsp");
reqDispatcher.forward(req, resp);
return;
}
}