本文整理汇总了Java中org.restlet.data.ChallengeScheme.HTTP_BASIC属性的典型用法代码示例。如果您正苦于以下问题:Java ChallengeScheme.HTTP_BASIC属性的具体用法?Java ChallengeScheme.HTTP_BASIC怎么用?Java ChallengeScheme.HTTP_BASIC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.restlet.data.ChallengeScheme
的用法示例。
在下文中一共展示了ChallengeScheme.HTTP_BASIC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
public static void main( String[] args )
throws Exception
{
Energy4Java polygene = new Energy4Java( );
Server server = new Server( Protocol.HTTP, 8888 );
Application app = polygene.newApplication( new ForumAssembler(), new MetadataService() );
app.activate();
ContextRestlet restlet = app.findModule( "REST", "Restlet" ).newObject( ContextRestlet.class, new org.restlet.Context() );
ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm");
MapVerifier mapVerifier = new MapVerifier();
mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray());
guard.setVerifier(mapVerifier);
guard.setNext(restlet);
server.setNext( restlet );
server.start();
}
示例2: initializeAuthentication
public void initializeAuthentication() {
if(verifier == null){
verifier = new DefaultSecretVerifier();
}
authenticator = new ChallengeAuthenticator(null, false, ChallengeScheme.HTTP_BASIC, "Foxbpm Realm") {
protected boolean authenticate(Request request, Response response) {
if (restAuthenticator != null && !restAuthenticator.requestRequiresAuthentication(request)) {
return true;
}
if (request.getChallengeResponse() == null) {
response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
return false;
} else {
boolean authenticated = super.authenticate(request, response);
if (authenticated && restAuthenticator != null) {
authenticated = restAuthenticator.isRequestAuthorized(request);
}
return authenticated;
}
}
};
authenticator.setVerifier(verifier);
}
示例3: postMethodRWS
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));
}
}
示例4: createInboundRoot
@Override
public Restlet createInboundRoot()
{
Context context = getContext();
Engine.getInstance().getRegisteredConverters().add( new PolygeneConverter( objectFactory ) );
if( polygeneApplication.mode() == Application.Mode.development )
{
setDebugging( true );
}
router = new Router( context );
addRoutes( router );
router.attach( basePath, newPolygeneRestlet( EntryPointResource.class, EntryPoint.class ) );
Verifier verifier = createVerifier();
Enroler enroler = createEnroler();
if( verifier == null && enroler == null )
{
return createInterceptors(new Filter()
{
} );
}
else
{
ChallengeAuthenticator guard = new ChallengeAuthenticator( context, ChallengeScheme.HTTP_BASIC, getName() + " Realm" );
if( verifier != null )
{
guard.setVerifier( verifier );
}
if( enroler != null )
{
guard.setEnroler( enroler );
}
return createInterceptors( guard );
}
}
示例5: getAdminGuard
private ChallengeAuthenticator getAdminGuard() {
// Create a simple password verifier
// MapVerifier verifier = new MapVerifier();
// verifier.getLocalSecrets().put("mitko", "qwepoi".toCharArray());
// Create a guard
ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(),
ChallengeScheme.HTTP_BASIC, "FP Admin");
guard.setVerifier(new AdminVerifier());
return guard;
}
示例6: getUserGuard
private ChallengeAuthenticator getUserGuard() {
// Create a guard
ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(),
ChallengeScheme.HTTP_BASIC, "FP User");
guard.setVerifier(new UserVerifier());
guard.setOptional(getAppProperties().getProperty("DisableAnonymous", "1").equals("1")?false:true);
return guard;
}
示例7: createAuthenticator
private ChallengeAuthenticator createAuthenticator() {
ChallengeAuthenticator auth= new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "mcrest");
MapVerifier mapVerifier = new MapVerifier();
mapVerifier.getLocalSecrets().put(authpara.getUserId(), authpara.getPassword().toCharArray());
auth.setVerifier(mapVerifier);
return auth;
}
示例8: getRequestResultWithAuth
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;
}
示例9: createInboundRoot
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@Override
public synchronized Restlet createInboundRoot() {
Verifier verifier = new SecretVerifier() {
@Override
public boolean verify(String username, char[] password) throws IllegalArgumentException {
boolean verified = ActivitiUtil.getIdentityService().checkPassword(username, new String(password));
return verified;
}
};
authenticator = new ChallengeAuthenticator(null, true, ChallengeScheme.HTTP_BASIC,
"Activiti Realm") {
@Override
protected boolean authenticate(Request request, Response response) {
if (request.getChallengeResponse() == null) {
return false;
} else {
return super.authenticate(request, response);
}
}
};
authenticator.setVerifier(verifier);
Router router = new Router(getContext());
router.attachDefault(DefaultResource.class);
router.attach("/process-engine", ProcessEngineResource.class);
router.attach("/login", LoginResource.class);
router.attach("/user/{userId}", UserResource.class);
router.attach("/user/{userId}/groups", UserGroupsResource.class);
router.attach("/group/{groupId}", GroupResource.class);
router.attach("/groups/{groupId}/users", GroupUsersResource.class);
router.attach("/process-definitions", ProcessDefinitionsResource.class);
router.attach("/process-instances", ProcessInstancesResource.class);
router.attach("/process-instance", ProcessInstanceResource.class);
router.attach("/processInstance/{processInstanceId}/diagram", ProcessInstanceDiagramResource.class);
router.attach("/process-definition/{processDefinitionId}/form", ProcessDefinitionFormResource.class);
router.attach("/tasks", TasksResource.class);
router.attach("/tasks-summary", TasksSummaryResource.class);
router.attach("/task/{taskId}", TaskResource.class);
router.attach("/task/{taskId}/form", TaskFormResource.class);
router.attach("/task/{taskId}/{operation}", TaskOperationResource.class);
router.attach("/form/{taskId}/properties", TaskPropertiesResource.class);
router.attach("/deployments", DeploymentsResource.class);
router.attach("/deployment", DeploymentUploadResource.class);
router.attach("/deployments/delete", DeploymentsDeleteResource.class);
router.attach("/deployment/{deploymentId}", DeploymentDeleteResource.class);
router.attach("/management/jobs", JobsResource.class);
router.attach("/management/job/{jobId}", JobResource.class);
router.attach("/management/job/{jobId}/execute", JobExecuteResource.class);
router.attach("/management/jobs/execute", JobsExecuteResource.class);
router.attach("/management/tables", TablesResource.class);
router.attach("/management/table/{tableName}", TableResource.class);
router.attach("/management/table/{tableName}/data", TableDataResource.class);
authenticator.setNext(router);
return authenticator;
}
示例10: SpringSecurityGuard
public SpringSecurityGuard(Context context) {
super(context, ChallengeScheme.HTTP_BASIC, "Spring Security");
}
示例11: createInboundRoot
@Override
public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
System.setProperty("http.keepAlive", "true");
getMetadataService().setDefaultMediaType(MediaType.TEXT_HTML);
router.attach("/rootcommunities", RootCommunitiesResource.class);
router.attach("/collections", AllCollectionsResource.class);
router.attach("/items", AllItemsResource.class);
router.attach("/community/{communityId}", CommunityResource.class);
router.attach("/community/{communityId}/logo",
CommunityLogoResource.class);
router.attach("/community/{communityId}/communities",
CommunitiesResource.class);
router.attach("/community/{communityId}/collections",
CollectionsResource.class);
router.attach("/collection/{collectionId}", CollectionResource.class);
router.attach("/collection/{collectionId}/logo",
CollectionLogoResource.class);
router.attach("/collection/{collectionId}/items", ItemsResource.class);
router.attach("/item/{itemId}", ItemResource.class);
router.attach("/bundle/{bundleId}", BundleResource.class);
router.attach("/bitstream/{bitstreamIdDotFormat}",
BitstreamResource.class);
router.attach("/metadataschemas", MetadataSchemasResource.class);
router.attach("/metadataschema/{metadataSchemaId}",
MetadataSchemaResource.class);
router.attach("/metadatafields", MetadataFieldsResource.class);
router.attach("/metadatafield/{metadataFieldId}",
MetadataFieldResource.class);
router.attach("/users", UsersResource.class);
router.attach("/user/{userId}", UserResource.class);
router.attach("/groups", GroupsResource.class);
router.attach("/group/{groupId}", GroupResource.class);
Series<Parameter> params = getContext().getParameters();
String username = params.getFirstValue("username");
String password = params.getFirstValue("password");
if (password == null || password.equals("")) {
log.fatal("No password defined - you have to set it!!!");
return null;
}
// Needs HTTPS!
ChallengeAuthenticator authenticator = new ChallengeAuthenticator(
getContext(), ChallengeScheme.HTTP_BASIC,
"Authentication for SimpleRest");
Verifier verifier = new MyVerifier();
authenticator.setVerifier(verifier);
authenticator.setNext(router);
router.attach("", RootResource.class);
router.attach("/handle/{handle}", HandleResource.class);
return authenticator;
}
示例12: onStart
@Override
public void onStart() {
try {
super.onStart();
component = new Component();
component.getClients().add(Protocol.FILE);
//TODO: To test with the restlet 2.1 Maybe the maxTotalConnections could be avoided
// see: http://restlet-discuss.1400322.n2.nabble.com/rejectedExecution-td4513620.html
//component.getServers().add(Protocol.HTTP, SERVER_PORT);
Server server = new Server(Protocol.HTTP, SERVER_PORT);
component.getServers().add(server);
server.getContext().getParameters().add("maxTotalConnections", "50");
//end TODO
// enable SSL
Server SSLserver = new Server(Protocol.HTTPS, configuration.getIntProperty("SSL_PORT", SERVER_PORT + 2 ));
component.getServers().add(SSLserver);
Series<Parameter> parameters = SSLserver.getContext().getParameters();
parameters.add("sslContextFactory", "org.restlet.ext.ssl.PkixSslContextFactory");
// Certificate's data is taken from config file
parameters.add("keystorePath", new File(this.getFile().getParent() + "/data/" + configuration.getStringProperty("KEYSTORE_FILE", "keystore")).getAbsolutePath());
parameters.add("keystorePassword", configuration.getStringProperty("KEYSTORE_PASSWORD", "password"));
parameters.add("keyPassword", configuration.getStringProperty("KEYSTORE_PASSWORD", "password"));
parameters.add("keystoreType", configuration.getStringProperty("KEYSTORE_TYPE", "JKS"));
// end enable SSL
// Engine.getInstance().getRegisteredServers().clear();
// Engine.getInstance().getRegisteredServers().add(new HttpServerHelper(server));
// Engine.getInstance().getRegisteredServers().add(new HttpServerHelper(SSLserver));
component.getClients().add(Protocol.FILE);
OriginFilter originFilter = new OriginFilter(component.getContext().createChildContext(),this);
Application FDapp = new FreedomRestServer(Info.PATHS.PATH_RESOURCES_FOLDER.getAbsolutePath(), component.getContext().createChildContext());
if (getApi().getAuth().isInited()) {
// Instantiates a Verifier of identifier/secret couples based on Freedomotic Auth
Verifier v = new SecretVerifier() {
@Override
public int verify(String identifier, char[] secret) {
if (getApi().getAuth().login(identifier, secret)) {
return RESULT_VALID;
}
return RESULT_INVALID;
}
};
// Guard the restlet with BASIC authentication.
ChallengeAuthenticator guard = new ChallengeAuthenticator(component.getContext().createChildContext(), false, ChallengeScheme.HTTP_BASIC, "testRealm", v);
// WIP: Guard the restlet with DIGEST authentication.
DigestAuthenticator dguard = new DigestAuthenticator(component.getContext().createChildContext(), "DigestRealm", configuration.getStringProperty("DIGEST_SECRET", "s3cr3t"));
dguard.setOptional(true);
// TODO: set proper verifier before enabling DIGEST AUTH.
originFilter.setNext(guard);
guard.setNext(FDapp);
} else {
originFilter.setNext(FDapp);
}
component.getDefaultHost().attachDefault(originFilter);
component.start();
freedomoticApi = getApi();
} catch (Exception ex) {
Logger.getLogger(RestApi.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例13: make
private void make(){
application = new Application(new Context());
Router router = new Router(application.getContext());
application.getContext().getAttributes().put(TokenManager.class.getName(), tokenManager);
application.getContext().getAttributes().put(ClientManager.class.getName(), clientManager);
application.getContext().getAttributes().put(ResourceOwnerManager.class.getName(), ownerManager);
application.getContext().getAttributes().put(OAuthServerResource.PARAMETER_DEFAULT_SCOPE, OAUTHDEFAULTSCOPE);
// Setup Authorize Endpoint - used by the client to obtain authorization from the resource owner via user-agent redirection
router.attach(AUTHORIZEENDPOINTURI, AuthorizationServerResource.class);
// Setup Token Endpoint - used by the client to exchange an authorization grant for an access token, typically with client authentication
ChallengeAuthenticator clientAuthenticator = new ChallengeAuthenticator(application.getContext(), ChallengeScheme.HTTP_BASIC, ObixServiceImpl.REALM);
BugFixClientVerifier clientVerifier = new BugFixClientVerifier(application.getContext());
clientVerifier.setAcceptBodyMethod(true);
clientAuthenticator.setVerifier(clientVerifier);
clientAuthenticator.setNext(AccessTokenServerResource.class);
router.attach(CLIENTTOKENENDPOINTURI, clientAuthenticator);
// Setup Token Auth for Resources Server
router.attach(TOKENAUTHENTICATORURI, TokenAuthServerResource.class);
application.setInboundRoot(router);
}
示例14: getMethodRWS
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));
}
}
示例15: putMethodRWS
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));
}
}