本文整理汇总了Java中org.restlet.data.ChallengeResponse类的典型用法代码示例。如果您正苦于以下问题:Java ChallengeResponse类的具体用法?Java ChallengeResponse怎么用?Java ChallengeResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChallengeResponse类属于org.restlet.data包,在下文中一共展示了ChallengeResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: administration
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
@SubResource
public void administration()
{
ChallengeResponse challenge = Request.getCurrent().getChallengeResponse();
if( challenge == null )
{
Response.getCurrent()
.setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) );
throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
}
User user = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() );
if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) )
{
throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
}
current().select( user );
subResource( AdministrationResource.class );
}
示例2: list
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
@Override
public List<Car> list() {
Client client = new Client(new Context(), Protocol.HTTPS);
Series<Parameter> parameters = client.getContext().getParameters();
parameters.add("truststorePath", System.getProperty("javax.net.ssl.trustStore"));
ClientResource clientResource = new ClientResource("https://localhost:8043/api/cars/cars");
clientResource.setNext(client);
ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER);
challenge.setRawValue(Request.getCurrent().getAttributes().getOrDefault("token", "").toString());
clientResource.setChallengeResponse(challenge);
CarServiceInterface carServiceInterface = clientResource.wrap(CarServiceInterface.class);
Car[] allCars = carServiceInterface.getAllCars();
try {
client.stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
return asList(allCars);
}
示例3: handle
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
public void handle(Request request, Response response) {
if (!request.getMethod().equals(Method.GET)) {
response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
return;
}
ChallengeResponse authResponse = request.getChallengeResponse();
if (passwords==null || passwordsTimestamp<getPasswordsLastModified()) {
loadPasswords();
}
String password = passwords.get(authResponse.getIdentifier());
if ((new String(authResponse.getSecret())).equals(password)) {
response.setStatus(Status.SUCCESS_NO_CONTENT);
} else {
response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
}
}
示例4: postMethodRWS
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
static Response postMethodRWS(ConnectionProperties cp, String uriReference, Representation form) throws RancidApiException {
client.setConnectTimeout(cp.getTimeout());
client.setProtocols(cp.getProtocols());;
Request request = new Request(Method.POST, uriReference, form);
if(cp.getAuthOn()){
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse authentication = new ChallengeResponse(scheme,cp.getUserName(), cp.getPassword());
request.setChallengeResponse(authentication);
}
else {
}
Response response = client.handle(request);
if (response.getStatus().isSuccess()) {
return response;
} else {
throw(handleException(response, "POST" ,uriReference));
}
}
示例5: invokeQuery
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
private HandlerCommand invokeQuery( Reference ref, Object queryRequest, ResponseHandler resourceHandler, ResponseHandler processingErrorHandler )
{
Request request = new Request( Method.GET, ref );
if( queryRequest != null )
{
contextResourceFactory.writeRequest( request, queryRequest );
}
contextResourceFactory.updateQueryRequest( request );
User user = request.getClientInfo().getUser();
if ( user != null)
request.setChallengeResponse( new ChallengeResponse( ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret() ) );
Response response = new Response( request );
contextResourceFactory.getClient().handle( request, response );
if( response.getStatus().isSuccess() )
{
contextResourceFactory.updateCache( response );
return resourceHandler.handleResponse( response, this );
} else if (response.getStatus().isRedirection())
{
Reference redirectedTo = response.getLocationRef();
return invokeQuery( redirectedTo, queryRequest, resourceHandler, processingErrorHandler );
} else
{
if (response.getStatus().equals(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY) && processingErrorHandler != null)
{
return processingErrorHandler.handleResponse( response, this );
} else
{
// TODO This needs to be expanded to allow custom handling of all the various cases
return errorHandler.handleResponse( response, this );
}
}
}
示例6: getRequestResultWithAuth
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
private Response getRequestResultWithAuth(String path,String user,String password){
Request request = new Request(Method.GET, serverUrl+path);
Client client = new Client(Protocol.HTTP);
ChallengeResponse authentication = new ChallengeResponse(
ChallengeScheme.HTTP_BASIC, user, password);
request.setChallengeResponse(authentication);
Response response = client.handle(request);
return response;
}
示例7: verify
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
@Override
public int verify(Request request, Response response) {
final String token;
try {
ChallengeResponse cr = request.getChallengeResponse();
if (cr == null) {
return RESULT_MISSING;
} else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) {
final String bearer = cr.getRawValue();
if (bearer == null || bearer.isEmpty()) {
return RESULT_MISSING;
}
token = bearer;
} else {
return RESULT_UNSUPPORTED;
}
} catch (Exception ex) {
return RESULT_INVALID;
}
Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand();
return user.map(u -> {
org.restlet.security.User restletUser = createRestletUser(u);
request.getClientInfo().setUser(restletUser);
request.getAttributes().put("token", token);
return RESULT_VALID;
}).orElse(RESULT_INVALID);
}
示例8: verify
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
public int verify(Request request, Response response) {
final String clientId;
final char[] clientSecret;
ChallengeResponse cr = request.getChallengeResponse();
if (cr == null) {
if (!isAcceptBodyMethod()) {
return RESULT_MISSING;
}
// Alternative method...
Form params = new Form(request.getEntity());
clientId = params.getFirstValue(OAuthServerResource.CLIENT_ID);
if (clientId == null || clientId.isEmpty()) {
return RESULT_MISSING;
}
String s = params.getFirstValue(OAuthServerResource.CLIENT_SECRET);
if (s == null || s.isEmpty()) {
clientSecret = new char[0];
} else {
clientSecret = s.toCharArray();
}
// Restore the body
request.setEntity(params.getWebRepresentation());
} else {
if (!cr.getScheme().equals(ChallengeScheme.HTTP_BASIC)) {
// XXX: May be unsupported
return RESULT_UNSUPPORTED;
}
clientId = cr.getIdentifier();
clientSecret = cr.getSecret();
}
int result = verify(clientId, clientSecret);
if (result == RESULT_VALID) {
request.getClientInfo().setUser(new User(clientId));
} else {
response.setEntity(OAuthServerResource.responseErrorRepresentation(new OAuthException(OAuthError.invalid_client, "Invalid client", null)));
}
return result;
}
示例9: WattDepotClient
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
/**
* Creates a new WattDepotClient.
*
* @param serverUri The URI of the WattDepot server (e.g.
* "http://server.wattdepot.org/")
* @param username The name of the user. The user must be defined in the
* WattDepot server.
* @param orgId the organization the user is in.
* @param password The password for the user.
* @throws BadCredentialException If the user or password don't match the
* credentials on the WattDepot server.
*/
public WattDepotClient(String serverUri, String username, String orgId, String password)
throws BadCredentialException {
// ensure that the UnitsHelper class is loaded.
new UnitsHelper();
this.properties = new ClientProperties();
this.logger = Logger.getLogger("org.wattdepot.client");
LoggerUtil.setLoggingLevel(this.logger, properties.get(ClientProperties.LOGGING_LEVEL_KEY));
LoggerUtil.useConsoleHandler();
LoggerUtil.removeRestletLoggers();
logger.finest("Client " + serverUri + ", " + username + ", " + password);
this.authentication = new ChallengeResponse(this.scheme, username, password);
if (serverUri == null) {
throw new IllegalArgumentException("serverUri cannot be null");
}
if (!serverUri.endsWith("/")) {
throw new IllegalArgumentException("serverUri must end with '/'");
}
this.wattDepotUri = serverUri + Labels.WATTDEPOT + "/";
ClientResource client = null;
client = makeClient(orgId + "/");
try {
client.head();
if (client.getLocationRef() != null) {
String path = client.getLocationRef().getPath();
path = path.substring(0, path.length() - 1);
int lastSlash = path.lastIndexOf('/') + 1;
organizationId = path.substring(lastSlash);
}
else {
organizationId = orgId;
}
client.release();
}
catch (ResourceException e) {
throw new BadCredentialException(e.getMessage() + " username and or password are not corect.");
}
}
示例10: getUserIdFromHeader
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
private String getUserIdFromHeader(Request request) {
ChallengeResponse cr = request.getChallengeResponse();
return (cr != null) ? cr.getIdentifier() : null;
}
示例11: getPassword
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
private String getPassword(Request request) {
ChallengeResponse cr = request.getChallengeResponse();
return (cr != null) ? new String(cr.getSecret()) : null;
}
示例12: authenticate
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public int authenticate(Request request) {
String url = getRelativePath(request);
// no filter belongs to url
if (filterChainProxy != null && filterChainProxy.getFilters(url) != null && filterChainProxy.getFilters(url).isEmpty()) {
return Guard.AUTHENTICATION_VALID;
}
int result = Guard.AUTHENTICATION_MISSING;
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (this.getScheme() != null) {
// An authentication scheme has been defined,
// the request must be authenticated
final ChallengeResponse cr = request.getChallengeResponse();
if (cr != null) {
if (this.getScheme().equals(cr.getScheme())) {
if (auth != null) {
if (auth.isAuthenticated()) {
return Guard.AUTHENTICATION_VALID;
}
} else {
throw new IllegalArgumentException("Challenge scheme " + this.getScheme() + " not supported by the Restlet engine.");
}
} else {
// The challenge schemes are incompatible, we need to
// challenge the client
}
} else {
if (auth != null) {
ChallengeResponse challengeResponse = new ChallengeResponse(this.getScheme(), auth.getName(), "");
if (auth.getDetails() instanceof User) {
User user = (User) auth.getDetails();
challengeResponse.setRawValue(user.getPassword());
challengeResponse.setRealm(this.getRealm());
org.restlet.security.User u = new org.restlet.security.User(user.getUsername());
if (user.getPassword() != null)
u.setSecret(user.getPassword().toCharArray());
request.getClientInfo().setUser(u);
}
challengeResponse.setAuthenticated(auth.isAuthenticated());
result = Guard.AUTHENTICATION_VALID;
request.setChallengeResponse(challengeResponse);
}
// No challenge response found, we need to challenge the client
}
}
if (request.getChallengeResponse() != null) {
// Update the challenge response accordingly
request.getChallengeResponse().setAuthenticated(result == Guard.AUTHENTICATION_VALID);
}
// Update the client info accordingly
request.getClientInfo().setAuthenticated(result == Guard.AUTHENTICATION_VALID);
return result;
}
示例13: getMethodRWS
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
static Response getMethodRWS(ConnectionProperties cp, String uriReference) throws RancidApiException {
client.setConnectTimeout(cp.getTimeout());
client.setProtocols(cp.getProtocols());;
Request request = new Request(Method.GET, uriReference);
if(cp.getUserName() != null){
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse authentication = new ChallengeResponse(scheme,cp.getUserName(), cp.getPassword());
request.setChallengeResponse(authentication);
}
else {
}
Response response = client.handle(request);
if (response.getStatus().isSuccess()) {
return response;
} else {
throw(handleException(response, "GET" ,uriReference));
}
}
示例14: putMethodRWS
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
static Response putMethodRWS(ConnectionProperties cp, String uriReference, Representation form) throws RancidApiException {
client.setConnectTimeout(cp.getTimeout());
client.setProtocols(cp.getProtocols());;
Request request = new Request(Method.PUT, uriReference, form);
if(cp.getAuthOn()){
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse authentication = new ChallengeResponse(scheme,cp.getUserName(), cp.getPassword());
request.setChallengeResponse(authentication);
}
else {
}
Response response = client.handle(request);
if (response.getStatus().isSuccess()) {
return response;
} else {
throw(handleException(response, "PUT" ,uriReference));
}
}
示例15: deleteMethodRWS
import org.restlet.data.ChallengeResponse; //导入依赖的package包/类
static Response deleteMethodRWS(ConnectionProperties cp, String uriReference) throws RancidApiException {
client.setConnectTimeout(cp.getTimeout());
client.setProtocols(cp.getProtocols());;
Request request = new Request(Method.DELETE, uriReference);
if(cp.getAuthOn()){
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse authentication = new ChallengeResponse(scheme,cp.getUserName(), cp.getPassword());
request.setChallengeResponse(authentication);
}
else {
}
Response response = client.handle(request);
if (response.getStatus().isSuccess()) {
return response;
} else {
throw(handleException(response, "DELETE" ,uriReference));
}
}