Example usage for org.springframework.security.oauth2.common.util RandomValueStringGenerator RandomValueStringGenerator

List of usage examples for org.springframework.security.oauth2.common.util RandomValueStringGenerator RandomValueStringGenerator

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common.util RandomValueStringGenerator RandomValueStringGenerator.

Prototype

public RandomValueStringGenerator() 

Source Link

Document

Create a generator with the default length (6).

Usage

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

@Test
public void nonImplicitGrantClientWithoutSecretIsRejected() throws Exception {
    OAuth2AccessToken token = getClientCredentialsAccessToken("clients.read clients.write");
    HttpHeaders headers = getAuthenticatedHeaders(token);
    BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar",
            "client_credentials", "uaa.none");
    ResponseEntity<UaaException> result = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), UaaException.class);
    assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
    assertEquals("invalid_client", result.getBody().getErrorCode());
}

From source file:org.smartplatforms.oauth2.LaunchOrchestrationEndpoint.java

private LaunchContext createLaunchContext(String launchId, Map<String, Object> launchContextParams) {
    LaunchContext launchContext = null;//from  w  w w.ja v a  2s.co  m
    if (StringUtils.isNotBlank(launchId)) {
        launchContext = LaunchContextHolder.getLaunchContext(launchId);
    }
    if (launchContext == null) {
        launchContext = new LaunchContext();
        RandomValueStringGenerator randomValueStringGenerator = new RandomValueStringGenerator();
        launchId = randomValueStringGenerator.generate();
        launchContext.setLaunchId(launchId);
        launchContext.setLaunchContextParams(launchContextParams);
    }
    return launchContext;
}

From source file:org.hspconsortium.platform.authorization.launchcontext.LaunchOrchestrationEndpoint.java

private LaunchContext createLaunchContext(String launchId, String patientId) {
    LaunchContext launchContext = null;/*from   w  w  w  . j  a  v  a 2s. c o m*/
    if (StringUtils.isNotBlank(launchId)) {
        launchContext = LaunchContextHolder.getLaunchContext(launchId);
    }
    if (launchContext == null) {
        launchContext = new LaunchContext();
        RandomValueStringGenerator randomValueStringGenerator = new RandomValueStringGenerator();
        launchId = randomValueStringGenerator.generate();
        launchContext.setLaunchId(launchId);
        launchContext.setPatientId(patientId);
    }
    return launchContext;
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

@Test
public void implicitAndAuthCodeGrantClient() throws Exception {
    BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar",
            "implicit,authorization_code", "uaa.none");
    ResponseEntity<UaaException> result = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), UaaException.class);
    assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
    assertEquals("invalid_client", result.getBody().getErrorCode());
}

From source file:org.cloudfoundry.identity.uaa.integration.feature.OpenIdTokenGrantsIT.java

@Before
public void setUp() throws Exception {
    ((RestTemplate) restOperations).setRequestFactory(new IntegrationTestUtils.StatelessRequestFactory());
    ClientCredentialsResourceDetails clientCredentials = getClientCredentialsResource(
            new String[] { "scim.write" }, testAccounts.getAdminClientId(),
            testAccounts.getAdminClientSecret());
    client = IntegrationTestUtils.getClientCredentialsTemplate(clientCredentials);
    user = createUser(new RandomValueStringGenerator().generate(), "openiduser", "openidlast",
            "test@openid,com", true);
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

@Test
public void implicitGrantClientWithoutSecretIsOk() throws Exception {
    BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar",
            "implicit", "uaa.none");
    ResponseEntity<Void> result = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), Void.class);

    assertEquals(HttpStatus.CREATED, result.getStatusCode());
}

From source file:org.cloudfoundry.identity.uaa.integration.OpenIdTokenAuthorizationWithApprovalIntegrationTests.java

@Before
public void createRestTemplate() throws Exception {

    ClientCredentialsResourceDetails clientCredentials = getClientCredentialsResource(
            new String[] { "oauth.login" }, "login", "loginsecret");
    loginClient = new OAuth2RestTemplate(clientCredentials);
    loginClient.setRequestFactory(new StatelessRequestFactory());
    loginClient.setErrorHandler(new OAuth2ErrorHandler(clientCredentials) {
        // Pass errors through in response entity for status code analysis
        @Override//from w w w.ja  v  a  2 s .c o  m
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });

    Assume.assumeTrue(!testAccounts.isProfileActive("vcap"));

    client = (RestTemplate) serverRunning.getRestTemplate();
    client.setErrorHandler(new OAuth2ErrorHandler(context.getResource()) {
        // Pass errors through in response entity for status code analysis
        @Override
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });
    user = createUser(new RandomValueStringGenerator().generate(), "openiduser", "openidlast",
            "test@openid,com", true).getBody();
}

From source file:org.cloudfoundry.identity.uaa.login.feature.OpenIdTokenGrantsIT.java

@Before
public void setUp() throws Exception {
    ((RestTemplate) restOperations).setRequestFactory(new StatelessRequestFactory());
    ClientCredentialsResourceDetails clientCredentials = getClientCredentialsResource(
            new String[] { "scim.write" }, testAccounts.getAdminClientId(),
            testAccounts.getAdminClientSecret());
    client = new OAuth2RestTemplate(clientCredentials);
    client.setRequestFactory(new StatelessRequestFactory());
    client.setErrorHandler(new OAuth2ErrorHandler(clientCredentials) {
        // Pass errors through in response entity for status code analysis
        @Override//  ww  w  .  j  a v a 2  s  .  co m
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });
    user = createUser(new RandomValueStringGenerator().generate(), "openiduser", "openidlast",
            "test@openid,com", true).getBody();
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

@Test
public void passwordGrantClientWithoutSecretIsOk() throws Exception {
    BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar",
            "password", "uaa.none");
    ResponseEntity<Void> result = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), Void.class);

    assertEquals(HttpStatus.CREATED, result.getStatusCode());
}

From source file:org.cloudfoundry.identity.uaa.integration.ScimGroupEndpointsIntegrationTests.java

@Before
public void createRestTemplate() throws Exception {
    client = (RestTemplate) serverRunning.getRestTemplate();
    client.setErrorHandler(new OAuth2ErrorHandler(context.getResource()) {
        // Pass errors through in response entity for status code analysis
        @Override/*from   ww w.ja  v  a  2s .  c om*/
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });

    JOEL = new ScimGroupMember(
            createUser("joel_" + new RandomValueStringGenerator().generate().toLowerCase(), "Passwo3d")
                    .getId());
    DALE = new ScimGroupMember(
            createUser("dale_" + new RandomValueStringGenerator().generate().toLowerCase(), "Passwo3d")
                    .getId());
    VIDYA = new ScimGroupMember(
            createUser("vidya_" + new RandomValueStringGenerator().generate().toLowerCase(), "Passwo3d")
                    .getId());
}