当前位置: 首页>>代码示例>>Java>>正文


Java Base64Utils.encode方法代码示例

本文整理汇总了Java中org.springframework.util.Base64Utils.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64Utils.encode方法的具体用法?Java Base64Utils.encode怎么用?Java Base64Utils.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.util.Base64Utils的用法示例。


在下文中一共展示了Base64Utils.encode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAccessToken

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
public static String getAccessToken(MockMvc mockMvc, String username, String password) throws Exception {
    String authorizationHeaderValue = "Basic "
            + new String(Base64Utils.encode("trusted-sw360-client:sw360-secret".getBytes()));

    MockHttpServletResponse response = mockMvc
            .perform(post("/oauth/token")
                    .header("Authorization", authorizationHeaderValue)
                    .contentType(MediaType.APPLICATION_FORM_URLENCODED)
                    .param("client_id", "trusted-sw360-client")
                    .param("client_secret", "sw360-secret")
                    .param("username", username)
                    .param("password", password)
                    .param("grant_type", "password")
                    .param("scope", "sw360.read"))
            .andReturn().getResponse();

    return new ObjectMapper()
            .readValue(response.getContentAsByteArray(), OAuthToken.class)
            .accessToken;
}
 
开发者ID:sw360,项目名称:sw360rest,代码行数:21,代码来源:TestHelper.java

示例2: getAccessToken

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private String getAccessToken(String username, String password) throws Exception {
    String authorization = "Basic "
            + new String(Base64Utils.encode("clientapp:123456".getBytes()));
    String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8";

    String content = mvc
            .perform(post("/oauth/token")
                            .header("Authorization", authorization)
                            .contentType(MediaType.APPLICATION_FORM_URLENCODED)
                            .param("username", username)
                            .param("password", password)
                            .param("grant_type", "password")
                            .param("scope", "read write")
                            .param("client_id", "clientapp")
                            .param("client_secret", "123456"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(contentType))
            .andExpect(jsonPath("$.access_token", is(notNullValue())))
            .andExpect(jsonPath("$.token_type", is(equalTo("bearer"))))
            .andExpect(jsonPath("$.refresh_token", is(notNullValue())))
            .andExpect(jsonPath("$.expires_in", is(greaterThan(4000))))
            .andExpect(jsonPath("$.scope", is(equalTo("read write"))))
            .andReturn().getResponse().getContentAsString();

    return content.substring(17, 53);
}
 
开发者ID:leandrocgsi,项目名称:erudio-api-oauth2,代码行数:27,代码来源:GreetingControllerTest.java

示例3: getAccessToken

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private String getAccessToken(String username, String password) throws Exception {
    String authorization = "Basic "
            + new String(Base64Utils.encode("clientapp:123456".getBytes()));
    String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8";

    // @formatter:off
    String content = mvc
            .perform(
                    post("/oauth/token")
                            .header("Authorization", authorization)
                            .contentType(
                                    MediaType.APPLICATION_FORM_URLENCODED)
                            .param("username", username)
                            .param("password", password)
                            .param("grant_type", "password")
                            .param("scope", "read write")
                            .param("client_id", "clientapp")
                            .param("client_secret", "123456"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(contentType))
            .andExpect(jsonPath("$.access_token", is(notNullValue())))
            .andExpect(jsonPath("$.token_type", is(equalTo("bearer"))))
            .andExpect(jsonPath("$.refresh_token", is(notNullValue())))
            .andExpect(jsonPath("$.expires_in", is(greaterThan(4000))))
            .andExpect(jsonPath("$.scope", is(equalTo("read write"))))
            .andReturn().getResponse().getContentAsString();

    // @formatter:on

    return content.substring(17, 53);
}
 
开发者ID:Pivopil,项目名称:spring-boot-rest-rxjava,代码行数:32,代码来源:UserControllerTest.java

示例4: getAccessToken

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
protected String getAccessToken(String username, String password) throws Exception {


        String authorization = "Basic " + new String(Base64Utils.encode((PROP_CLIENTID + ":" + PROP_SECRET).getBytes()));
        String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8";
        String content = mvc
                .perform(
                        post("/oauth/token")
                                .header("Authorization", authorization)
//                        .contentType(
//                                MediaType.APPLICATION_FORM_URLENCODED)
                                .param("username", username)
                                .param("password", password)
                                .param("grant_type", "password")
                                .param("scope", "read write")
                                .param("client_id", PROP_CLIENTID)
                                .param("client_secret", PROP_SECRET))
                .andDo(MockMvcResultHandlers.print())
                .andExpect(status().isOk())
                .andExpect(content().contentType(contentType))
                .andExpect(jsonPath("$.access_token", is(notNullValue())))
                .andExpect(jsonPath("$.token_type", is(equalTo("bearer"))))
                .andExpect(jsonPath("$.refresh_token", is(notNullValue())))
                        // .andExpect(jsonPath("$.expires_in", is(greaterThan(new Double(PROP_TOKEN_VALIDITY_SECONDS*0.9).intValue()))))
                .andExpect(jsonPath("$.scope", is(equalTo("read write"))))
                .andReturn().getResponse().getContentAsString();

        return content.substring(17, 53);
    }
 
开发者ID:lsneucamp,项目名称:SpringBoot-Oauth2-stater-kit,代码行数:30,代码来源:AbstractTest.java

示例5: getAccessToken

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
String getAccessToken(String username, String password, MockMvc mvc) throws Exception {
    String authorization = "Basic "
            + new String(Base64Utils.encode((DEFAULT_CLIENT_NAME + ":" + DEFAULT_CLIENT_SECRET).getBytes()));
    String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8";

    String content = mvc
            .perform(
                    post("/oauth/token")
                            .header("Authorization", authorization)
                            .contentType(
                                    MediaType.APPLICATION_FORM_URLENCODED)
                            .param("username", username)
                            .param("password", password)
                            .param("grant_type", "password")
                            .param("scope", "read write")
                            .param("client_id", DEFAULT_CLIENT_NAME)
                            .param("client_secret", DEFAULT_CLIENT_SECRET))
            .andExpect(status().isOk())
            .andExpect(content().contentType(contentType))
            .andExpect(jsonPath("$.access_token", is(notNullValue())))
            .andExpect(jsonPath("$.token_type", is(equalTo("bearer"))))
            .andExpect(jsonPath("$.refresh_token", is(notNullValue())))
            .andExpect(jsonPath("$.expires_in", is(greaterThan(4000))))
            .andExpect(jsonPath("$.scope", is(equalTo("read write"))))
            .andReturn().getResponse().getContentAsString();

    return content.substring(17, 53);
}
 
开发者ID:Pivopil,项目名称:spring-boot-oauth2-rest-service-password-encoding,代码行数:29,代码来源:AbstractRestTest.java

示例6: buildOriginatingIdentityHeader

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
protected String buildOriginatingIdentityHeader() throws JsonProcessingException {
	Map<String, Object> propMap = new HashMap<>();
	propMap.put(ORIGINATING_USER_KEY, ORIGINATING_USER_VALUE);
	propMap.put(ORIGINATING_EMAIL_KEY, ORIGINATING_EMAIL_VALUE);
	ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().build();
	String properties = mapper.writeValueAsString(propMap);
	String encodedProperties = new String(Base64Utils.encode(properties.getBytes()));
	return ORIGINATING_IDENTITY_PLATFORM + " " + encodedProperties;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-cloudfoundry-service-broker,代码行数:10,代码来源:ControllerIntegrationTest.java

示例7: getAccessToken

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private String getAccessToken(String username, String password) throws Exception {
    String authorization = "Basic "
            + new String(Base64Utils.encode("app:very_secret".getBytes()));
    String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8";

    String body = mockMvc
            .perform(
                    post("/oauth/token")
                            .header("Authorization", authorization)
                            .contentType(
                                    MediaType.APPLICATION_FORM_URLENCODED)
                            .param("username", username)
                            .param("password", password)
                            .param("grant_type", "password")
                            .param("scope", "read write")
                            .param("client_id", "app")
                            .param("client_secret", "very_secret"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(contentType))
            .andExpect(jsonPath("$.access_token", is(notNullValue())))
            .andExpect(jsonPath("$.token_type", is(equalTo("bearer"))))
            .andExpect(jsonPath("$.refresh_token", is(notNullValue())))
            .andExpect(jsonPath("$.expires_in", is(greaterThan(4000))))
            .andExpect(jsonPath("$.scope", is(equalTo("read write"))))
            .andReturn().getResponse().getContentAsString();

    return body.substring(17, 53);
}
 
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:29,代码来源:MockMvcBase.java

示例8: getSecureRestTemplate

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private RestTemplate getSecureRestTemplate(ConfigClientProperties client) {
	SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
	requestFactory.setReadTimeout((60 * 1000 * 3) + 5000); //TODO 3m5s, make configurable?
	RestTemplate template = new RestTemplate(requestFactory);
	String username = client.getUsername();
	String password = client.getPassword();
	String authorization = client.getAuthorization();
	Map<String, String> headers = new HashMap<>(client.getHeaders());

	if (password != null && authorization != null) {
		throw new IllegalStateException(
				"You must set either 'password' or 'authorization'");
	}

	if (password != null) {
		byte[] token = Base64Utils.encode((username + ":" + password).getBytes());
		headers.put("Authorization", "Basic " + new String(token));
	}
	else if (authorization != null) {
		headers.put("Authorization", authorization);
	}

	if (!headers.isEmpty()) {
		template.setInterceptors(Arrays.<ClientHttpRequestInterceptor> asList(
				new GenericRequestHeaderInterceptor(headers)));
	}

	return template;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:30,代码来源:ConfigServicePropertySourceLocator.java

示例9: getAccessToken

import org.springframework.util.Base64Utils; //导入方法依赖的package包/类
private String getAccessToken(String username, String password) throws Exception {
	String authorization = "Basic "
			+ new String(Base64Utils.encode("clientapp:123456".getBytes()));
	String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8";

	// @formatter:off
	String content = mvc
			.perform(
					post("/oauth/token")
							.header("Authorization", authorization)
							.contentType(
									MediaType.APPLICATION_FORM_URLENCODED)
							.param("username", username)
							.param("password", password)
							.param("grant_type", "password")
							.param("scope", "read write")
							.param("client_id", "clientapp")
							.param("client_secret", "123456"))
			.andExpect(status().isOk())
			.andExpect(content().contentType(contentType))
			.andExpect(jsonPath("$.access_token", is(notNullValue())))
			.andExpect(jsonPath("$.token_type", is(equalTo("bearer"))))
			.andExpect(jsonPath("$.refresh_token", is(notNullValue())))
			.andExpect(jsonPath("$.expires_in", is(greaterThan(4000))))
			.andExpect(jsonPath("$.scope", is(equalTo("read write"))))
			.andReturn().getResponse().getContentAsString();

	// @formatter:on

	return content.substring(17, 53);
}
 
开发者ID:royclarkson,项目名称:spring-rest-service-oauth,代码行数:32,代码来源:GreetingControllerTest.java


注:本文中的org.springframework.util.Base64Utils.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。