org.openstack4j.model.identity.v3.Token Java Examples

The following examples show how to use org.openstack4j.model.identity.v3.Token. 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: OpenStackClient.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private Token createToken(KeystoneCredentialView osCredential) {
    if (osCredential == null) {
        throw new CredentialVerificationException("Empty credential");
    }
    if (osCredential.getScope() == null) {
        throw new CredentialVerificationException("Null scope not supported");
    }
    switch (osCredential.getScope()) {
        case CB_KEYSTONE_V3_DOMAIN_SCOPE:
            return OSFactory.builderV3().withConfig(config).endpoint(osCredential.getEndpoint())
                    .credentials(osCredential.getUserName(), osCredential.getPassword(), Identifier.byName(osCredential.getUserDomain()))
                    .scopeToDomain(Identifier.byName(osCredential.getDomainName()))
                    .authenticate()
                    .getToken();
        case CB_KEYSTONE_V3_PROJECT_SCOPE:
            return OSFactory.builderV3().withConfig(config).endpoint(osCredential.getEndpoint())
                    .credentials(osCredential.getUserName(), osCredential.getPassword(), Identifier.byName(osCredential.getUserDomain()))
                    .scopeToProject(Identifier.byName(osCredential.getProjectName()), Identifier.byName(osCredential.getProjectDomain()))
                    .authenticate()
                    .getToken();
        default:
            throw new CredentialVerificationException("Scope not supported: " + osCredential.getScope());
    }
}
 
Example #2
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private void createAccessOrToken(AuthenticatedContext authenticatedContext) {
    KeystoneCredentialView osCredential = createKeystoneCredential(authenticatedContext.getCloudCredential());
    if (isV2Keystone(osCredential)) {
        Access access = createAccess(osCredential);
        if (access != null) {
            authenticatedContext.putParameter(Access.class, access);
        } else {
            throw new CredentialVerificationException("Openstack authentication failed, can not create access");
        }
    } else {
        Token token = createToken(osCredential);
        if (token != null) {
            authenticatedContext.putParameter(Token.class, token);
        } else {
            throw new CredentialVerificationException("Openstack authentication failed, can not create token");
        }
    }
}
 
Example #3
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public OSClient<?> createOSClient(AuthenticatedContext authenticatedContext) {
    String facing = authenticatedContext.getCloudCredential().getStringParameter(FACING);

    if (isV2Keystone(authenticatedContext)) {
        Access access = authenticatedContext.getParameter(Access.class);
        return OSFactory.clientFromAccess(access, Facing.value(facing));
    } else {
        Token token = authenticatedContext.getParameter(Token.class);
        return OSFactory.clientFromToken(token, Facing.value(facing));
    }
}
 
Example #4
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public OSClient<?> createOSClient(CloudCredential cloudCredential) {
    String facing = cloudCredential.getStringParameter(FACING);
    KeystoneCredentialView osCredential = createKeystoneCredential(cloudCredential);

    if (isV2Keystone(cloudCredential)) {
        Access access = createAccess(osCredential);
        return OSFactory.clientFromAccess(access, Facing.value(facing));
    } else {
        Token token = createToken(osCredential);
        return OSFactory.clientFromToken(token, Facing.value(facing));
    }
}