public String getPassword() { return wrappedCredentials.getPassword(); }
public static String toBasicAuthorizationValue(UsernamePasswordCredentials credentials) { return "Basic "+Base64.encodeBase64String( (credentials.getUserName()+":"+credentials.getPassword()).getBytes() ); }
try { // You can use HTTPS or HTTP as protocol. String myURL = "https://example.com/song.mp3"; mp.reset(); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.setOnPreparedListener(this); mp.setOnErrorListener(this); // These are the two lines, doing the magic ;) It transforms it to a url like this: https://user:password@example.com/song.mp3 UsernamePasswordCredentials credentials = connHelper.getCredetials(); myURL = myURL.replace("://", "://" + URLEncoder.encode(credentials.getUserName(), "UTF-8") + ":" + URLEncoder.encode(credentials.getPassword(), "UTF-8") + "@"); mp.setDataSource(myURL); mp.prepareAsync(); mp.setOnCompletionListener(this); } catch (Exception e) { Log.e("StreamAudioDemo", e.getMessage()); }
/** * This method allows to propagate the authentication information from the current object. * * @param commonDataLoader {@code CommonsDataLoader} to be initialised with authentication information */ public void propagateAuthentication(final CommonDataLoader commonDataLoader) { for (final Map.Entry<HttpHost, UsernamePasswordCredentials> credentialsEntry : authenticationMap.entrySet()) { final HttpHost httpHost = credentialsEntry.getKey(); final UsernamePasswordCredentials credentials = credentialsEntry.getValue(); commonDataLoader.addAuthentication(httpHost.getHostName(), httpHost.getPort(), httpHost.getSchemeName(), credentials.getUserName(), credentials.getPassword()); } }
/** * This method allows to propagate the authentication information from the * current object. * * @param commonsDataLoader * {@code CommonsDataLoader} to be initialized with * authentication information */ public void propagateAuthentication(final CommonsDataLoader commonsDataLoader) { for (final Map.Entry<HttpHost, UsernamePasswordCredentials> credentialsEntry : authenticationMap.entrySet()) { final HttpHost httpHost = credentialsEntry.getKey(); final UsernamePasswordCredentials credentials = credentialsEntry.getValue(); commonsDataLoader.addAuthentication(httpHost.getHostName(), httpHost.getPort(), httpHost.getSchemeName(), credentials.getUserName(), credentials.getPassword()); } }
/** * {@inheritDoc} */ @Override public synchronized void setCredentials(final AuthScope authscope, final Credentials credentials) { if (authscope == null) { throw new IllegalArgumentException("Authentication scope may not be null"); } final CredentialsFactory factory; if (credentials instanceof UsernamePasswordCredentials) { final UsernamePasswordCredentials userCredentials = (UsernamePasswordCredentials) credentials; factory = new UsernamePasswordCredentialsFactory(userCredentials.getUserName(), userCredentials.getPassword()); } else if (credentials instanceof NTCredentials) { final NTCredentials ntCredentials = (NTCredentials) credentials; factory = new NTCredentialsFactory(ntCredentials.getUserName(), ntCredentials.getPassword(), ntCredentials.getWorkstation(), ntCredentials.getDomain()); } else { throw new IllegalArgumentException("Unsupported Credential type: " + credentials.getClass().getName()); } credentialsMap_.put(new AuthScopeProxy(authscope), factory); }
@Override public Request deployCluster(String clusterName, String blueprintName, RecommendationWrapper recommendationWrapper, Map config) throws AmbariApiException { Preconditions.checkNotNull(recommendationWrapper); Preconditions.checkNotNull(recommendationWrapper.getStack()); Preconditions.checkNotNull(recommendationWrapper.getRecommendation()); Preconditions.checkNotNull(recommendationWrapper.getRecommendation().getBlueprint()); Preconditions.checkNotNull(recommendationWrapper.getRecommendation().getBindings()); try { restAdapter.create(BlueprintEndpoint.class).createBlueprint(blueprintName, ImmutableMap.builder() .put("host_groups", recommendationWrapper.getRecommendation().getBlueprint().getHostGroups()) .put("configurations", getConfigurations(config)) .put("Blueprints", recommendationWrapper.getStack()) .build()); List<HostGroup> confHostGroupsList = recommendationWrapper.getRecommendation().getBindings().getHostGroups(); List<HostGroup> nonZeroHostGroupList = new LinkedList<>(); for(HostGroup hostGroupN:confHostGroupsList) { if (hostGroupN.getHosts().size() > 0) { nonZeroHostGroupList.add(hostGroupN); } } return restAdapter.create(ClusterEndpoint.class).createCluster(clusterName, ImmutableMap.builder() .put("blueprint", blueprintName) .put("default_password", usernamePasswordCredentials.getPassword()) .put("host_groups", nonZeroHostGroupList) .build()); } catch (RetrofitError retrofitError) { throw new AmbariApiException(retrofitError); } }
/** * Need to wait server to start before resetting the password. */ protected void generateAndUpdatePassword() { String password = getAttribute(AmbariServer.PASSWORD); if (password == null) { password = getConfig(AmbariServer.PASSWORD); if (password == null) { password = Identifiers.makeRandomId(10); } usernamePasswordCredentials = new UsernamePasswordCredentials(USERNAME, password); ImmutableMap<String, ImmutableMap<String, String>> userRequest = ImmutableMap.of("Users", ImmutableMap.of( "user_name", USERNAME, "old_password", INITIAL_PASSWORD, "password", usernamePasswordCredentials.getPassword() )); waitForServiceUp(); restAdapter.create(UsersEndpoint.class).updateUser(userRequest); restAdapter = new RestAdapter.Builder() .setEndpoint(ambariUri) .setClient(ambariRestClient) .setRequestInterceptor(new AmbariRequestInterceptor(usernamePasswordCredentials)) .setLogLevel(RestAdapter.LogLevel.FULL) .build(); disconnectAuthenticatedSensors(); connectAuthenticatedSensors(); sensors().set(AmbariServer.PASSWORD, password); } }
UsernamePasswordCredentials c = (UsernamePasswordCredentials) creds; username = c.getUserName(); password = c.getPassword();
private void connectAuthenticatedSensors() { hostsHttpFeed = HttpFeed.builder() .entity(this) .period(1000, TimeUnit.MILLISECONDS) .baseUri(String.format("%s/api/v1/hosts", ambariUri)) .credentials(usernamePasswordCredentials.getUserName(), usernamePasswordCredentials.getPassword()) .header(HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(usernamePasswordCredentials)) .poll(new HttpPollConfig<List<String>>(REGISTERED_HOSTS) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), getHosts())) .onFailureOrException(Functions.<List<String>>constant(ImmutableList.<String>of()))) .build(); clusterHttpFeed = HttpFeed.builder() .entity(this) .period(1000, TimeUnit.MILLISECONDS) .baseUri(String.format("%s/api/v1/clusters/%s/requests/%d", ambariUri, getConfig(AmbariCluster.CLUSTER_NAME), 1)) .credentials(usernamePasswordCredentials.getUserName(), usernamePasswordCredentials.getPassword()) .header(HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(usernamePasswordCredentials)) .poll(new HttpPollConfig<String>(CLUSTER_STATE) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), getRequestState())) .onFailureOrException(Functions.<String>constant(null))) .build(); }
public static void writeServiceReference(SparqlServiceReference serviceRef, String targetGraph, Resource root, Model model) throws IllegalAccessException { Resource dgs = ResourceUtils.createSubResource(root, "defaultGraphs"); Resource ngs = ResourceUtils.createSubResource(root, "namedGraphs"); // An update can only go to a single graph model.add(root, RDF.type, V.RdfDataset); model.add(root, V.endpoint, model.createResource(serviceRef.getServiceURL())); model.add(root, V.target, model.createResource(targetGraph)); UsernamePasswordCredentials credentials = serviceRef.getCredentials(); //if(auth instanceof SimpleAuthenticator) { if(credentials != null) { //SimpleAuthenticator a = (SimpleAuthenticator)auth; //String username = (String)FieldUtils.readField(a, "username" , true); //char[] password = (char[])FieldUtils.readField(a, "password" , true); model.add(root, V.username, model.createLiteral(credentials.getUserName())); model.add(root, V.password, model.createLiteral(credentials.getPassword())); } }
Element password = newEpicureElement("password"); login.setText(credentials.getUserName()); password.setText(credentials.getPassword()); epicurLite.addContent(login); epicurLite.addContent(password);