本文整理汇总了Java中org.restlet.security.ChallengeAuthenticator类的典型用法代码示例。如果您正苦于以下问题:Java ChallengeAuthenticator类的具体用法?Java ChallengeAuthenticator怎么用?Java ChallengeAuthenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChallengeAuthenticator类属于org.restlet.security包,在下文中一共展示了ChallengeAuthenticator类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
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
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
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: createInboundRoot
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
@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 );
}
}
示例4: getAdminGuard
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
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;
}
示例5: getUserGuard
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
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;
}
示例6: setUpAuth
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
private void setUpAuth(Router router,String path,String resourceKey,Class<? extends ServerResource> targetClass){
if(authpara == null ){
router.attach(path,targetClass);
return;
}
if((!authpara.isProtected(resourceKey))|| (!authpara.isEnabled())){
router.attach(path,targetClass);
return;
}
ChallengeAuthenticator auth = createAuthenticator();
auth.setNext(targetClass);
router.attach(path,auth);
logger.info("Resource "+router+" need to auth.");
}
示例7: createAuthenticator
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
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: secure
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
private Restlet secure(Application app, Verifier verifier, String realm) {
ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext().createChildContext(),
ChallengeScheme.HTTP_OAUTH_BEARER, realm);
guard.setVerifier(verifier);
guard.setNext(app);
return guard;
}
示例9: createAuthenticator
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
private ChallengeAuthenticator createAuthenticator() {
// ChallengeAuthenticator extends Authenticator extends Filter extens Restlet
ChallengeAuthenticator bearerAuthenticator = new ChallengeAuthenticator(application.getContext(),ChallengeScheme.HTTP_OAUTH_BEARER, ObixServiceImpl.REALM);
// do not propose new challenge if authorisation fails.
bearerAuthenticator.setRechallenging(false);
//bearerAuthenticator.setVerifier( new TokenVerifier(new Reference( "http://localhost:8080" + oautLocalServerPath + Oauth2ApplicationFactory.TOKENAUTHENTICATORURI)));
bearerAuthenticator.setVerifier( new TokenVerifier(new Reference( "riap://component" + oautLocalServerPath + Oauth2ApplicationFactory.TOKENAUTHENTICATORURI)));
return bearerAuthenticator;
}
示例10: createInboundRoot
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
/**
* 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;
}
示例11: make
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
private void make() {
XMLConverter obixConverter = new XMLConverter();
Engine.getInstance().getRegisteredConverters().add( obixConverter);
JSonConverter jsonConverter = new JSonConverter();
Engine.getInstance().getRegisteredConverters().add(jsonConverter);
// remove standart JacksonConverter
List<ConverterHelper> converters = Engine.getInstance().getRegisteredConverters();
for (ConverterHelper converter : converters) {
if (converter instanceof JacksonConverter) {
converters.remove(converter);
break;
}
}
// and add our that add special mixins
converters.add(new JacksonCustomConverter());
application = new Application();
Context context = new Context();
application.setContext(context);
guiceFinderFactory = new GuiceFinderFactory();
root = new GuiceRouter(context);
root.setFinderFactory(guiceFinderFactory);
// Cors filter for cross domain requests
CorsFilter corsFilter = new CorsFilter(root.getContext());
corsFilter.setNext(root);
// attach resources to root
addRoutes();
// if the rest resources have to be secured, add verification up front.
if( doSecure.booleanValue()){
// Create authentifier, will attempt to authentify every request
ChallengeAuthenticator authenticator = createAuthenticator();
// authorizer will block request on resources based on role for current authentified user
//RoleAuthorizer roleAuth = createRoleAuthorizer();
authenticator.setNext(corsFilter);
//roleAuth.setNext(corsFilter);
application.setInboundRoot(authenticator);
} else {
// otherwie just the cors filter
application.setInboundRoot(corsFilter);
}
Activator.log(LogService.LOG_INFO, "Restlet application initialised.");
//Engine.setRestletLogLevel(Level.OFF);
}
示例12: createInboundRoot
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
@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;
}
示例13: onStart
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
@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);
}
}
示例14: make
import org.restlet.security.ChallengeAuthenticator; //导入依赖的package包/类
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);
}