use of org.wso2.carbon.identity.mgt.config.Config in project carbon-identity-framework by wso2.
the class CacheBackedApplicationDAO method addToCache.
private void addToCache(ServiceProvider serviceProvider, String tenantDomain) {
if (log.isDebugEnabled()) {
log.debug("Add cache for the application " + serviceProvider.getApplicationName() + "@" + tenantDomain);
}
IdentityServiceProviderCacheKey nameKey = new IdentityServiceProviderCacheKey(serviceProvider.getApplicationName());
IdentityServiceProviderCacheEntry nameEntry = new IdentityServiceProviderCacheEntry(serviceProvider);
appCacheByName.addToCache(nameKey, nameEntry, tenantDomain);
ServiceProviderIDCacheKey idKey = new ServiceProviderIDCacheKey(serviceProvider.getApplicationID());
ServiceProviderIDCacheEntry idEntry = new ServiceProviderIDCacheEntry(serviceProvider);
appCacheByID.addToCache(idKey, idEntry, tenantDomain);
ServiceProviderResourceIdCacheKey resourceIdCacheKey = new ServiceProviderResourceIdCacheKey(serviceProvider.getApplicationResourceId());
ServiceProviderResourceIdCacheEntry entry = new ServiceProviderResourceIdCacheEntry(serviceProvider);
appCacheByResourceId.addToCache(resourceIdCacheKey, entry, tenantDomain);
if (serviceProvider.getInboundAuthenticationConfig() != null && serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs() != null) {
InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
for (InboundAuthenticationRequestConfig config : configs) {
if (config.getInboundAuthKey() != null) {
ServiceProviderCacheInboundAuthKey clientKey = new ServiceProviderCacheInboundAuthKey(config.getInboundAuthKey(), config.getInboundAuthType());
ServiceProviderCacheInboundAuthEntry clientEntry = new ServiceProviderCacheInboundAuthEntry(serviceProvider.getApplicationName(), tenantDomain);
appCacheByInboundAuth.addToCache(clientKey, clientEntry, tenantDomain);
}
}
}
}
use of org.wso2.carbon.identity.mgt.config.Config in project carbon-identity-framework by wso2.
the class ThriftAuthenticationServiceComponent method startThriftTcpAuthenticatorService.
private void startThriftTcpAuthenticatorService(ThriftAuthenticatorService thriftAuthenticatorService) throws Exception {
int portOffset = readPortOffset();
ServerConfiguration serverConfig = ServerConfiguration.getInstance();
String serverUrl = CarbonUtils.getServerURL(serverConfig, configurationContext.getServerConfigContext());
OMElement hostnameElement = ThriftAuthenticationConfigParser.getInstance().getConfigElement("Hostname");
String hostName;
if (hostnameElement == null) {
try {
hostName = new URL(serverUrl).getHost();
} catch (MalformedURLException e) {
hostName = HostAddressFinder.findAddress("localhost");
if (!serverUrl.matches("local:/.*/services/")) {
log.info("Thrift Authentication Service url :" + serverUrl + " is using local, hence hostname is assigned as '" + hostName + "'");
}
}
} else {
hostName = hostnameElement.getText();
}
OMElement portElement = ThriftAuthenticationConfigParser.getInstance().getConfigElement("Port");
int port;
if (portElement != null) {
port = Integer.parseInt(portElement.getText());
} else {
throw new Exception("Error, Thrift Authentication Service config does not have a port defined!");
}
port = port + portOffset;
String keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location");
if (keyStore == null) {
keyStore = System.getProperty("Security.KeyStore.Location");
if (keyStore == null) {
throw new Exception("Cannot initialize Thrift Authentication Service, Security.KeyStore.Location is null");
}
}
String keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password");
if (keyStorePassword == null) {
keyStorePassword = System.getProperty("Security.KeyStore.Password");
if (keyStorePassword == null) {
throw new Exception("Cannot initialize Thrift Authentication Service, Security.KeyStore.Password is null ");
}
}
OMElement clientTimeoutElement = ThriftAuthenticationConfigParser.getInstance().getConfigElement(ThriftAuthenticationConstants.CLIENT_TIMEOUT);
int clientTimeout;
if (clientTimeoutElement != null) {
try {
clientTimeout = Integer.parseInt(clientTimeoutElement.getText());
} catch (Throwable e) {
String msg = "Error, in Thrift Auth Client Timeout, hence using the default timeout: " + ThriftAuthenticationConstants.DEFAULT_CLIENT_TIMEOUT + "ms";
log.error(msg, e);
clientTimeout = ThriftAuthenticationConstants.DEFAULT_CLIENT_TIMEOUT;
}
} else {
String msg = "Thrift Authentication Service Client Timeout is not set, hence using the default timeout: " + ThriftAuthenticationConstants.DEFAULT_CLIENT_TIMEOUT + "ms";
log.info(msg);
clientTimeout = ThriftAuthenticationConstants.DEFAULT_CLIENT_TIMEOUT;
}
TCPThriftAuthenticationService = new TCPThriftAuthenticationService(hostName, port, keyStore, keyStorePassword, clientTimeout, thriftAuthenticatorService);
TCPThriftAuthenticationService.start();
}
use of org.wso2.carbon.identity.mgt.config.Config in project carbon-identity-framework by wso2.
the class ApplicationBean method updateOutBoundAuthenticationConfig.
/**
* @param request
*/
public void updateOutBoundAuthenticationConfig(HttpServletRequest request) {
String[] authSteps = request.getParameterValues("auth_step");
if (authSteps != null && authSteps.length > 0) {
List<AuthenticationStep> authStepList = new ArrayList<AuthenticationStep>();
for (String authstep : authSteps) {
AuthenticationStep authStep = new AuthenticationStep();
authStep.setStepOrder(Integer.parseInt(authstep));
boolean isSubjectStep = request.getParameter("subject_step_" + authstep) != null && "on".equals(request.getParameter("subject_step_" + authstep)) ? true : false;
authStep.setSubjectStep(isSubjectStep);
boolean isAttributeStep = request.getParameter("attribute_step_" + authstep) != null && "on".equals(request.getParameter("attribute_step_" + authstep)) ? true : false;
authStep.setAttributeStep(isAttributeStep);
String[] localAuthenticatorNames = request.getParameterValues("step_" + authstep + "_local_auth");
if (localAuthenticatorNames != null && localAuthenticatorNames.length > 0) {
List<LocalAuthenticatorConfig> localAuthList = new ArrayList<LocalAuthenticatorConfig>();
for (String name : localAuthenticatorNames) {
if (name != null) {
LocalAuthenticatorConfig localAuth = new LocalAuthenticatorConfig();
localAuth.setName(name);
if (localAuthenticatorConfigs != null) {
for (LocalAuthenticatorConfig config : localAuthenticatorConfigs) {
if (config.getName().equals(name)) {
localAuth.setDisplayName(config.getDisplayName());
break;
}
}
}
localAuthList.add(localAuth);
}
}
if (localAuthList != null && !localAuthList.isEmpty()) {
authStep.setLocalAuthenticatorConfigs(localAuthList.toArray(new LocalAuthenticatorConfig[localAuthList.size()]));
}
}
String[] federatedIdpNames = request.getParameterValues("step_" + authstep + "_fed_auth");
if (federatedIdpNames != null && federatedIdpNames.length > 0) {
List<IdentityProvider> fedIdpList = new ArrayList<>();
for (String name : federatedIdpNames) {
if (StringUtils.isNotBlank(name)) {
IdentityProvider idp = new IdentityProvider();
idp.setIdentityProviderName(name);
IdentityProvider referringIdP = federatedIdentityProvidersMap.get(name);
String authenticatorName = request.getParameter("step_" + authstep + "_idp_" + name + "_fed_authenticator");
if (StringUtils.isNotBlank(authenticatorName)) {
String authenticatorDisplayName = null;
for (FederatedAuthenticatorConfig config : referringIdP.getFederatedAuthenticatorConfigs()) {
if (authenticatorName.equals(config.getName())) {
authenticatorDisplayName = config.getDisplayName();
break;
}
}
FederatedAuthenticatorConfig authenticator = new FederatedAuthenticatorConfig();
authenticator.setName(authenticatorName);
authenticator.setDisplayName(authenticatorDisplayName);
idp.setDefaultAuthenticatorConfig(authenticator);
idp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { authenticator });
fedIdpList.add(idp);
}
}
}
if (fedIdpList != null && !fedIdpList.isEmpty()) {
authStep.setFederatedIdentityProviders(fedIdpList.toArray(new IdentityProvider[fedIdpList.size()]));
}
}
if ((authStep.getFederatedIdentityProviders() != null && authStep.getFederatedIdentityProviders().length > 0) || (authStep.getLocalAuthenticatorConfigs() != null && authStep.getLocalAuthenticatorConfigs().length > 0)) {
authStepList.add(authStep);
}
}
if (serviceProvider.getLocalAndOutBoundAuthenticationConfig() == null) {
serviceProvider.setLocalAndOutBoundAuthenticationConfig(new LocalAndOutboundAuthenticationConfig());
}
if (CollectionUtils.isNotEmpty(authStepList)) {
LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
localAndOutboundAuthenticationConfig.setAuthenticationSteps(authStepList.toArray(new AuthenticationStep[authStepList.size()]));
}
}
}
use of org.wso2.carbon.identity.mgt.config.Config in project carbon-identity-framework by wso2.
the class DefaultStepHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws FrameworkException {
if (context.getAnalyticsData(FrameworkConstants.AnalyticsData.CURRENT_AUTHENTICATOR_START_TIME) == null) {
context.setAnalyticsData(FrameworkConstants.AnalyticsData.CURRENT_AUTHENTICATOR_START_TIME, System.currentTimeMillis());
}
StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(context.getCurrentStep());
List<AuthenticatorConfig> authConfigList = stepConfig.getAuthenticatorList();
String authenticatorNames = FrameworkUtils.getAuthenticatorIdPMappingString(authConfigList);
String loginPage = ConfigurationFacade.getInstance().getAuthenticationEndpointURL();
String fidp = request.getParameter(FrameworkConstants.RequestParams.FEDERATED_IDP);
Map<String, AuthenticatedIdPData> authenticatedIdPs = context.getCurrentAuthenticatedIdPs();
// NOTE : currentAuthenticatedIdPs (if not null) always contains the previousAuthenticatedIdPs
if (MapUtils.isEmpty(authenticatedIdPs)) {
if (LOG.isDebugEnabled()) {
LOG.debug("No current authenticated IDPs in the authentication context. " + "Continuing with the previous authenticated IDPs");
}
authenticatedIdPs = context.getPreviousAuthenticatedIdPs();
}
if (LOG.isDebugEnabled()) {
if (MapUtils.isEmpty(authenticatedIdPs)) {
LOG.debug("No previous authenticated IDPs found in the authentication context.");
} else {
LOG.debug(String.format("Found authenticated IdPs. Count: %d", authenticatedIdPs.size()));
}
}
if (context.isPassiveAuthenticate() && MapUtils.isNotEmpty(context.getAuthenticatedIdPsOfApp())) {
authenticatedIdPs = context.getAuthenticatedIdPsOfApp();
}
Map<String, AuthenticatorConfig> authenticatedStepIdps = FrameworkUtils.getAuthenticatedStepIdPs(stepConfig, authenticatedIdPs);
// check passive authentication
if (context.isPassiveAuthenticate()) {
if (authenticatedStepIdps.isEmpty()) {
context.setRequestAuthenticated(false);
} else {
String authenticatedIdP = authenticatedStepIdps.entrySet().iterator().next().getKey();
AuthenticatedIdPData authenticatedIdPData = authenticatedIdPs.get(authenticatedIdP);
populateStepConfigWithAuthenticationDetails(stepConfig, authenticatedIdPData, authenticatedStepIdps.get(authenticatedIdP));
request.setAttribute(FrameworkConstants.RequestParams.FLOW_STATUS, AuthenticatorFlowStatus.SUCCESS_COMPLETED);
}
stepConfig.setCompleted(true);
return;
} else {
long authTime = 0;
String maxAgeParam = request.getParameter(FrameworkConstants.RequestParams.MAX_AGE);
if (StringUtils.isNotBlank(maxAgeParam) && StringUtils.isNotBlank(context.getSessionIdentifier())) {
String loginTenantDomain = context.getLoginTenantDomain();
long maxAge = Long.parseLong((maxAgeParam));
if (FrameworkUtils.getSessionContextFromCache(context.getSessionIdentifier(), loginTenantDomain).getProperty(FrameworkConstants.UPDATED_TIMESTAMP) != null) {
authTime = Long.parseLong(FrameworkUtils.getSessionContextFromCache(context.getSessionIdentifier(), loginTenantDomain).getProperty(FrameworkConstants.UPDATED_TIMESTAMP).toString());
} else {
authTime = Long.parseLong(FrameworkUtils.getSessionContextFromCache(context.getSessionIdentifier(), loginTenantDomain).getProperty(FrameworkConstants.CREATED_TIMESTAMP).toString());
}
long currentTime = System.currentTimeMillis();
if (maxAge < (currentTime - authTime) / 1000) {
context.setForceAuthenticate(true);
} else {
context.setPreviousAuthTime(true);
}
}
}
if (request.getParameter(FrameworkConstants.RequestParams.USER_ABORT) != null && Boolean.parseBoolean(request.getParameter(FrameworkConstants.RequestParams.USER_ABORT))) {
request.setAttribute(FrameworkConstants.RequestParams.FLOW_STATUS, AuthenticatorFlowStatus.USER_ABORT);
stepConfig.setCompleted(true);
return;
}
// if Request has fidp param and if this is the first step
if (fidp != null && stepConfig.getOrder() == 1) {
handleHomeRealmDiscovery(request, response, context);
return;
} else if (context.isReturning()) {
// if this is a request from the multi-option page
if (request.getParameter(FrameworkConstants.RequestParams.AUTHENTICATOR) != null && !request.getParameter(FrameworkConstants.RequestParams.AUTHENTICATOR).isEmpty()) {
handleRequestFromLoginPage(request, response, context);
return;
} else {
// if this is a response from external parties (e.g. federated IdPs)
handleResponse(request, response, context);
return;
}
} else if (ConfigurationFacade.getInstance().isDumbMode() && authenticatedIdPs.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing in Dumb mode");
}
try {
request.setAttribute(FrameworkConstants.RequestParams.FLOW_STATUS, AuthenticatorFlowStatus.INCOMPLETE);
response.sendRedirect(loginPage + ("?" + context.getContextIdIncludedQueryParams()) + "&authenticators=" + URLEncoder.encode(authenticatorNames, "UTF-8") + "&hrd=true");
} catch (IOException e) {
throw new FrameworkException(e.getMessage(), e);
}
} else {
if (!(context.isForceAuthenticate() || stepConfig.isForced()) && !authenticatedStepIdps.isEmpty()) {
Map.Entry<String, AuthenticatorConfig> entry = authenticatedStepIdps.entrySet().iterator().next();
String idp = entry.getKey();
AuthenticatorConfig authenticatorConfig = entry.getValue();
if (context.isReAuthenticate()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Re-authenticating with " + idp + " IdP");
}
try {
context.setExternalIdP(ConfigurationFacade.getInstance().getIdPConfigByName(idp, context.getTenantDomain()));
} catch (IdentityProviderManagementException e) {
LOG.error("Exception while getting IdP by name", e);
}
doAuthentication(request, response, context, authenticatorConfig);
return;
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Already authenticated. Skipping the step");
}
// skip the step if this is a normal request
AuthenticatedIdPData authenticatedIdPData = authenticatedIdPs.get(idp);
populateStepConfigWithAuthenticationDetails(stepConfig, authenticatedIdPData, authenticatedStepIdps.get(idp));
context.getCurrentAuthenticatedIdPs().put(idp, authenticatedIdPData);
stepConfig.setCompleted(true);
request.setAttribute(FrameworkConstants.RequestParams.FLOW_STATUS, AuthenticatorFlowStatus.SUCCESS_COMPLETED);
return;
}
} else {
// Find if step contains only a single authenticator with a single
// IdP. If yes, don't send to the multi-option page. Call directly.
boolean sendToPage = false;
boolean isAuthFlowHandlerOrBasicAuthInMultiOptionStep = false;
AuthenticatorConfig authenticatorConfig = null;
// Are there multiple authenticators?
if (authConfigList.size() > 1) {
sendToPage = true;
// redirecting to the multi option page.
for (AuthenticatorConfig config : authConfigList) {
if ((config.getApplicationAuthenticator() instanceof AuthenticationFlowHandler) || (config.getApplicationAuthenticator() instanceof LocalApplicationAuthenticator && (BASIC_AUTH_MECHANISM).equalsIgnoreCase(config.getApplicationAuthenticator().getAuthMechanism()))) {
authenticatorConfig = config;
isAuthFlowHandlerOrBasicAuthInMultiOptionStep = true;
sendToPage = false;
break;
}
}
} else {
// Are there multiple IdPs in the single authenticator?
authenticatorConfig = authConfigList.get(0);
if (authenticatorConfig.getIdpNames().size() > 1) {
sendToPage = true;
}
}
if (!sendToPage) {
// call directly
if (!authenticatorConfig.getIdpNames().isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Step contains only a single IdP. Going to call it directly");
}
// set the IdP to be called in the context
try {
context.setExternalIdP(ConfigurationFacade.getInstance().getIdPConfigByName(authenticatorConfig.getIdpNames().get(0), context.getTenantDomain()));
} catch (IdentityProviderManagementException e) {
LOG.error("Exception while getting IdP by name", e);
}
}
doAuthentication(request, response, context, authenticatorConfig);
/* If an authentication flow handler is redirected with incomplete status,
it will redirect to multi option page, as multi-option is available */
if ((request.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS)) == AuthenticatorFlowStatus.INCOMPLETE && isAuthFlowHandlerOrBasicAuthInMultiOptionStep) {
sendToMultiOptionPage(stepConfig, request, context, response, authenticatorNames);
}
return;
} else {
// else send to the multi option page.
sendToMultiOptionPage(stepConfig, request, context, response, authenticatorNames);
return;
}
}
}
}
use of org.wso2.carbon.identity.mgt.config.Config in project carbon-identity-framework by wso2.
the class DirectoryServerApplicationMgtListener method doPreDeleteApplication.
@Override
public boolean doPreDeleteApplication(String applicationName, String tenantDomain, String userName) throws IdentityApplicationManagementException {
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
ServiceProvider serviceProvider = appDAO.getApplication(applicationName, tenantDomain);
if (serviceProvider != null && serviceProvider.getInboundAuthenticationConfig() != null && serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs() != null) {
InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
for (InboundAuthenticationRequestConfig config : configs) {
if (KERBEROS.equalsIgnoreCase(config.getInboundAuthType()) && config.getInboundAuthKey() != null) {
DirectoryServerManager directoryServerManager = new DirectoryServerManager();
try {
directoryServerManager.removeServer(config.getInboundAuthKey());
} catch (DirectoryServerManagerException e) {
String error = "Error while removing a kerberos: " + config.getInboundAuthKey();
throw new IdentityApplicationManagementException(error, e);
}
break;
}
}
}
return true;
}
Aggregations