Java Code Examples for org.wso2.carbon.utils.CarbonUtils#setBasicAccessSecurityHeaders()
The following examples show how to use
org.wso2.carbon.utils.CarbonUtils#setBasicAccessSecurityHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserSignUpWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Method to delete a user * @param serverURL * @param adminUsername * @param adminPassword * @param userName * @throws Exception */ protected static void deleteUser(String serverURL, String adminUsername, String adminPassword, String userName) throws Exception { if (log.isDebugEnabled()) { log.debug("Remove the rejected user :" + userName); } String url = serverURL + "UserAdmin"; int index = userName.indexOf(UserCoreConstants.DOMAIN_SEPARATOR); //remove the PRIMARY part from the user name if (index > 0) { if(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME.equalsIgnoreCase(userName.substring(0, index))){ userName = userName.substring(index + 1); } } UserAdminStub userAdminStub = new UserAdminStub(url); CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient()); userAdminStub.deleteUser(userName); }
Example 2
Source File: RemoteAuthorizationManagerClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Query the remote user manager and retrieve the list of role names in users-store * * * @return the list of roles * @throws APIManagementException If and error occurs while accessing the admin service */ public String[] getRoleNames() throws APIManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, userStoreManager._getServiceClient()); if (cookie != null) { userStoreManager._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie); } try { String[] roles = userStoreManager.getRoleNames(); ServiceContext serviceContext = userStoreManager. _getServiceClient().getLastOperationContext().getServiceContext(); cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return roles; } catch (Exception e) { throw new APIManagementException("Error while accessing backend services for " + "getting list of all the roles.", e); } }
Example 3
Source File: RemoteAuthorizationManagerClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Query the remote user manager and retrieve the list of role names associated for the given * user name. This is used when authorization for certain actions are appropriately delegated * to other components (ex:- Lifecycle Management). * * @param user Username * @return the list of roles to which the user belongs to. * @throws APIManagementException If and error occurs while accessing the admin service */ public String[] getRolesOfUser(String user) throws APIManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, userStoreManager._getServiceClient()); if (cookie != null) { userStoreManager._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie); } try { String[] roles = userStoreManager.getRoleListOfUser(user); ServiceContext serviceContext = userStoreManager. _getServiceClient().getLastOperationContext().getServiceContext(); cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return roles; } catch (Exception e) { throw new APIManagementException("Error while accessing backend services for " + "user role list", e); } }
Example 4
Source File: BasicAuthCredentialValidator.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Initialize the validator with the synapse environment. * * @throws APISecurityException If an authentication failure or some other error occurs */ BasicAuthCredentialValidator() throws APISecurityException { this.gatewayKeyCacheEnabled = isGatewayTokenCacheEnabled(); this.getGatewayUsernameCache(); ConfigurationContext configurationContext = ServiceReferenceHolder.getInstance().getAxis2ConfigurationContext(); APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration(); String username = config.getFirstProperty(APIConstants.API_KEY_VALIDATOR_USERNAME); String password = config.getFirstProperty(APIConstants.API_KEY_VALIDATOR_PASSWORD); String url = config.getFirstProperty(APIConstants.API_KEY_VALIDATOR_URL); if (url == null) { throw new APISecurityException(APISecurityConstants.API_AUTH_GENERAL_ERROR, "API key manager URL unspecified"); } try { apiKeyMgtRemoteUserStoreMgtServiceStub = new APIKeyMgtRemoteUserStoreMgtServiceStub(configurationContext, url + "APIKeyMgtRemoteUserStoreMgtService"); ServiceClient client = apiKeyMgtRemoteUserStoreMgtServiceStub._getServiceClient(); Options options = client.getOptions(); options.setCallTransportCleanup(true); options.setManageSession(true); CarbonUtils.setBasicAccessSecurityHeaders(username, password, client); } catch (AxisFault axisFault) { throw new APISecurityException(APISecurityConstants.API_AUTH_GENERAL_ERROR, axisFault.getMessage(), axisFault); } }
Example 5
Source File: UserSignUpWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Method updates Roles users with subscriber role * @param serverURL * @param adminUsername * @param adminPassword * @param userName * @param role * @throws Exception */ protected static void updateRolesOfUser(String serverURL, String adminUsername, String adminPassword, String userName, String role) throws Exception { if (log.isDebugEnabled()) { log.debug("Adding Subscriber role to " + userName); } String url = serverURL + "UserAdmin"; RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService(); UserRealm realm = realmService.getBootstrapRealm(); UserStoreManager manager = realm.getUserStoreManager(); if (!manager.isExistingRole(role)){ log.error("Could not find role " + role + " in the user store"); throw new Exception("Could not find role " + role + " in the user store"); } UserAdminStub userAdminStub = new UserAdminStub(url); CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient()); FlaggedName[] flaggedNames = userAdminStub.getRolesOfUser(userName, "*", -1); List<String> roles = new ArrayList<String>(); if (flaggedNames != null) { for (FlaggedName flaggedName : flaggedNames) { if (flaggedName.getSelected()) { roles.add(flaggedName.getItemName()); } } } roles.add(role); userAdminStub.updateRolesOfUser(userName, roles.toArray(new String[roles.size()])); }
Example 6
Source File: APIGatewayAdminClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public APIGatewayAdminClient(Environment environment) throws AxisFault { //String qualifiedName = apiId.getProviderName() + "--" + apiId.getApiName() + ":v" + apiId.getVersion(); //String qualifiedDefaultApiName = apiId.getProviderName() + "--" + apiId.getApiName(); //String providerDomain = apiId.getProviderName(); //providerDomain = APIUtil.replaceEmailDomainBack(providerDomain); ConfigurationContext ctx = ServiceReferenceHolder.getInstance().getAxis2ConfigurationContext(); apiGatewayAdminStub = new APIGatewayAdminStub(ctx, environment.getServerURL() + "APIGatewayAdmin"); setup(apiGatewayAdminStub, environment); CarbonUtils.setBasicAccessSecurityHeaders(environment.getUserName(), environment.getPassword(), apiGatewayAdminStub._getServiceClient()); }
Example 7
Source File: RemoteUserManagerClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public RemoteUserManagerClient(String cookie) throws APIManagementException { APIManagerConfiguration config = ServiceReferenceHolder.getInstance() .getAPIManagerConfigurationService() .getAPIManagerConfiguration(); String serviceURL = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL); String username = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME); String password = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD); if (serviceURL == null || username == null || password == null) { throw new APIManagementException("Required connection details for authentication"); } try { String clientRepo = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment" + File.separator + "client"; String clientAxisConf = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "axis2"+ File.separator +"axis2_client.xml"; ConfigurationContext configContext = ConfigurationContextFactory. createConfigurationContextFromFileSystem(clientRepo,clientAxisConf); userStoreManagerStub = new RemoteUserStoreManagerServiceStub(configContext, serviceURL + "RemoteUserStoreManagerService"); ServiceClient svcClient = userStoreManagerStub._getServiceClient(); CarbonUtils.setBasicAccessSecurityHeaders(username, password, svcClient); Options options = svcClient.getOptions(); options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS); options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS); options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS); options.setCallTransportCleanup(true); options.setManageSession(true); options.setProperty(HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault axisFault) { throw new APIManagementException( "Error while initializing the remote user store manager stub", axisFault); } }
Example 8
Source File: LocalEntryAdminClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public LocalEntryAdminClient(Environment environment, String tenantDomain) throws AxisFault { this.tenantDomain = tenantDomain; ConfigurationContext configurationContext = ServiceReferenceHolder.getContextService().getClientConfigContext(); localEntryAdminServiceStub = new APILocalEntryAdminStub(configurationContext, environment.getServerURL() + "APILocalEntryAdmin"); setup(localEntryAdminServiceStub, environment, configurationContext); CarbonUtils.setBasicAccessSecurityHeaders(environment.getUserName(), environment.getPassword(), localEntryAdminServiceStub._getServiceClient()); }
Example 9
Source File: ValidationServiceClient.java From product-private-paas with Apache License 2.0 | 5 votes |
public ValidationServiceClient(String backendServerURL, String username, String password) throws Exception { String serviceURL = backendServerURL + "OAuth2TokenValidationService"; try { stub = new OAuth2TokenValidationServiceStub(serviceURL); CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, stub._getServiceClient()); } catch (AxisFault e) { log.error("Error initializing OAuth2 Client"); throw new Exception("Error initializing OAuth Client", e); } }
Example 10
Source File: BasicAuthUIAuthenticator.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public String doAuthentication(Object credentials, boolean isRememberMe, ServiceClient client, HttpServletRequest request) throws AuthenticationException { DefaultAuthenticatorCredentials defaultCredentials = (DefaultAuthenticatorCredentials) credentials; if (isRememberMe && defaultCredentials.getUserName() == null && defaultCredentials.getPassword() == null) { // This is to login with Remember Me. Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(CarbonConstants.REMEMBER_ME_COOKE_NAME)) { CarbonUIAuthenticationUtil.setCookieHeaders(cookie, client); String cookieValue = cookie.getValue(); return getUserNameFromCookie(cookieValue); } } } } else { CarbonUtils.setBasicAccessSecurityHeaders(defaultCredentials.getUserName(), defaultCredentials.getPassword(), isRememberMe, client); return defaultCredentials.getUserName(); } throw new AuthenticationException("Invalid user credentials."); }
Example 11
Source File: ServerAdminClient.java From product-ei with Apache License 2.0 | 5 votes |
public ServerAdminClient(String serverURL, String userName, String password) throws AxisFault { this.session = null; String serviceEPR = serverURL + "ServerAdmin"; serverAdminStub = new ServerAdminStub(serviceEPR); ServiceClient client = serverAdminStub._getServiceClient(); Options options = client.getOptions(); options.setManageSession(true); options.setTimeOutInMilliSeconds(10000); CarbonUtils.setBasicAccessSecurityHeaders(userName, password, client); }
Example 12
Source File: SamplesInvoker.java From product-ei with Apache License 2.0 | 5 votes |
private static void initUserAdminStub() throws Exception { userAdminStub = new UserAdminStub(USER_MANAGEMENT_SERVICE_URL); ServiceClient serviceClient = userAdminStub._getServiceClient(); Options serviceClientOptions = serviceClient.getOptions(); serviceClientOptions.setManageSession(true); CarbonUtils.setBasicAccessSecurityHeaders("admin", "admin", serviceClient); }
Example 13
Source File: UserSignUpWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Method updates Roles users with list of roles * @param serverURL * @param adminUsername * @param adminPassword * @param userName * @param tenantID * @param role * @throws Exception */ protected static void updateRolesOfUser(String serverURL, String adminUsername, String adminPassword, String userName, List<String> roleList, String tenantDomain) throws Exception { if (log.isDebugEnabled()) { log.debug("Adding roles to " + userName + "in " + tenantDomain + " Domain"); } String url = serverURL + "UserAdmin"; RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService(); int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager() .getTenantId(tenantDomain); UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId); UserStoreManager manager = realm.getUserStoreManager(); if(manager.isExistingUser(userName)) { // check whether given roles exist for (String role : roleList) { if (!manager.isExistingRole(role)) { log.error("Could not find role " + role + " in the user store"); throw new Exception("Could not find role " + role + " in the user store"); } } UserAdminStub userAdminStub = new UserAdminStub(url); CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient()); FlaggedName[] flaggedNames = userAdminStub.getRolesOfUser(userName, "*", -1); List<String> roles = new ArrayList<String>(); if (flaggedNames != null) { for (FlaggedName flaggedName : flaggedNames) { if (flaggedName.getSelected()) { roles.add(flaggedName.getItemName()); } } } roles.addAll(roleList); userAdminStub.updateRolesOfUser(userName, roles.toArray(new String[roles.size()])); } else { log.error("User does not exist. Unable to approve user " + userName); } }
Example 14
Source File: AuthenticateStub.java From micro-integrator with Apache License 2.0 | 2 votes |
/** * Authenticate the given web service stub against the Product user manager. This * will make it possible to use the stub for invoking Product admin services. * * @param stub Axis2 service stub which needs to be authenticated */ public static void authenticateStub(String userName, String password, Stub stub) { CarbonUtils.setBasicAccessSecurityHeaders(userName, password, stub._getServiceClient()); }
Example 15
Source File: AuthenticateStub.java From product-es with Apache License 2.0 | 2 votes |
/** * Authenticate the given web service stub against the Product user manager. This * will make it possible to use the stub for invoking Product admin services. * * @param stub Axis2 service stub which needs to be authenticated */ public static void authenticateStub(String userName, String password, Stub stub) { CarbonUtils.setBasicAccessSecurityHeaders(userName, password, stub._getServiceClient()); }
Example 16
Source File: AuthenticateStub.java From product-ei with Apache License 2.0 | 2 votes |
/** * Authenticate the given web service stub against the Product user manager. This * will make it possible to use the stub for invoking Product admin services. * * @param stub Axis2 service stub which needs to be authenticated */ public static void authenticateStub(String userName, String password, Stub stub) { CarbonUtils.setBasicAccessSecurityHeaders(userName, password, stub._getServiceClient()); }
Example 17
Source File: AuthenticateStubUtil.java From product-ei with Apache License 2.0 | 2 votes |
/** * Authenticate the given web service stub against the Product user manager. This * will make it possible to use the stub for invoking Product admin services. * * @param stub Axis2 service stub which needs to be authenticated */ public static void authenticateStub(String userName, String password, Stub stub) { CarbonUtils.setBasicAccessSecurityHeaders(userName, password, stub._getServiceClient()); }
Example 18
Source File: AuthenticateStubUtil.java From product-ei with Apache License 2.0 | 2 votes |
/** * Authenticate the given web service stub against the Product user manager. This * will make it possible to use the stub for invoking Product admin services. * * @param stub Axis2 service stub which needs to be authenticated */ public static void authenticateStub(String userName, String password, Stub stub) { CarbonUtils.setBasicAccessSecurityHeaders(userName, password, stub._getServiceClient()); }
Example 19
Source File: AuthenticateStubUtil.java From product-ei with Apache License 2.0 | 2 votes |
/** * Authenticate the given web service stub against the Product user manager. This * will make it possible to use the stub for invoking Product admin services. * * @param stub Axis2 service stub which needs to be authenticated */ public static void authenticateStub(String userName, String password, Stub stub) { CarbonUtils.setBasicAccessSecurityHeaders(userName, password, stub._getServiceClient()); }
Example 20
Source File: AuthenticateStubUtil.java From micro-integrator with Apache License 2.0 | 2 votes |
/** * Authenticate the given web service stub against the Product user manager. This * will make it possible to use the stub for invoking Product admin services. * * @param stub Axis2 service stub which needs to be authenticated */ public static void authenticateStub(String userName, String password, Stub stub) { CarbonUtils.setBasicAccessSecurityHeaders(userName, password, stub._getServiceClient()); }